[PR #13588] feat: add sub-agent cost breakdown with recursive session walker #14728

Open
opened 2026-02-16 18:19:29 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/13588

State: open
Merged: No


Summary

Add sub-agent cost breakdown with recursive session walker
Add recursive costs() utility for sub-agent expenditure tracking

The cost of the session/agents now includes the cost of subagents.
This recursively applies when inspecting sub-agents.
Subagents cost is visible in the chat

Comprehensive test coverage (13 new tests)

Visual changes

  1. cost display unchanged, but now accounts for the total session (including sub-agents).
    When inside an agent, display the total cost of that agent and its sub-agents.
    image

  2. Added visible agent task cost inside the chat
    image

Similar changes for the Web app

Verification

Passed packages/util/src/cost.test.ts (7 tests)
Passed packages/app/src/components/session/session-context-metrics.test.ts (6 tests)
Typecheck passes for all affected packages (@opencode-ai/ui, @opencode-ai/util, @opencode-ai/app, opencode)
Note: @opencode-ai/enterprise typecheck failure is pre-existing on dev (unrelated custom-elements.d.ts issue)

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/13588 **State:** open **Merged:** No --- ## Summary Add sub-agent cost breakdown with recursive session walker Add recursive costs() utility for sub-agent expenditure tracking The cost of the session/agents now includes the cost of subagents. This recursively applies when inspecting sub-agents. Subagents cost is visible in the chat Comprehensive test coverage (13 new tests) - Fixes #11027 - Fixes #4925 ## Visual changes 1. cost display unchanged, but now accounts for the total session (including sub-agents). When inside an agent, display the total cost of that agent and its sub-agents. <img width="249" height="82" alt="image" src="https://github.com/user-attachments/assets/1d54826d-3d20-40be-9d23-bff4b8d8fcaf" /> 3. Added visible agent task cost inside the chat <img width="750" height="199" alt="image" src="https://github.com/user-attachments/assets/8365d7fa-5c40-476e-821f-676745229cd1" /> Similar changes for the Web app ## Verification Passed packages/util/src/cost.test.ts (7 tests) Passed packages/app/src/components/session/session-context-metrics.test.ts (6 tests) Typecheck passes for all affected packages (@opencode-ai/ui, @opencode-ai/util, @opencode-ai/app, opencode) Note: @opencode-ai/enterprise typecheck failure is pre-existing on dev (unrelated custom-elements.d.ts issue)
yindo added the pull-request label 2026-02-16 18:19:29 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14728