Skip to content

Cost of session doesn't include cost of subagents #196

@marius-kilocode

Description

@marius-kilocode

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:

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 cost
  • packages/opencode/src/session/prompt.ts — Subtask execution path creates assistant message with cost: 0, never updates it
  • packages/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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions