-
Notifications
You must be signed in to change notification settings - Fork 30
Description
Problem
When the parent agent spawns subagents via the Task tool, the total cost displayed for the parent session does not include costs incurred by child sessions. This makes the displayed cost misleadingly low.
For example, a session might show $0.01 but clicking into a subagent reveals that subagent alone cost $0.04. The parent should show the combined total.
Upstream
This is a known upstream issue:
- Issue: Cost of session doesn't include cost of subagents anomalyco/opencode#11027
- Related PR (not merged): fix: add persistent cost to prevent under-reporting spent value anomalyco/opencode#7763 — adds persistent session cost but does not propagate subagent costs to parent
- Related RFC (closed): [RFC] Cost Tracking Architecture: Subagent Aggregation + Multi-Model Correctness anomalyco/opencode#12377 — comprehensive cost tracking architecture proposal
Once upstream merges their fix, we should sync it. If they don't address subagent propagation specifically, we can implement it ourselves.
Root Cause
After a subagent completes in task.ts, its costs are never propagated back to the parent session's assistant message. The parent's assistant message starts with cost: 0 and is never updated with the child's actual cost.
The UI correctly sums costs from all assistant messages in the session — so fixing the backend propagation is sufficient.
Relevant Code
packages/opencode/src/tool/task.ts— Task tool creates child sessions, fetches child messages after completion but doesn't propagate costpackages/opencode/src/session/prompt.ts— Subtask execution path creates assistant message withcost: 0, never updates itpackages/app/src/components/session-context-usage.tsx— UI cost aggregation (tooltip)packages/app/src/components/session/session-context-tab.tsx— UI cost aggregation (stats panel)