claude-code - 💡(How to fix) Fix Aggregate token usage / cost across sub-agent sessions in status line [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#48040Fetched 2026-04-15 06:35:01
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Author
Timeline (top)
labeled ×4closed ×1commented ×1

Code Example

{
  "cost": {
    "total_cost_usd": 0.12,
    "aggregate_cost_usd": 0.87,
    "sub_agent_cost_usd": 0.75
  }
}
RAW_BUFFERClick to expand / collapse

Feature Request

Problem

When using multi-agent workflows (e.g., an orchestrator that spawns several sub-agents via the Agent tool), the cost and context_window data provided to the status line script only reflects the primary session's token usage. Sub-agents run in isolated sessions, so their costs are invisible to the user in the status line.

This makes it difficult to understand the true cost of a pipeline run that delegates work across multiple agents.

Proposed Solution

Provide an aggregated cost field in the status line JSON input that includes token usage from all sub-agent sessions spawned by the current conversation. For example:

{
  "cost": {
    "total_cost_usd": 0.12,
    "aggregate_cost_usd": 0.87,
    "sub_agent_cost_usd": 0.75
  }
}

Or alternatively, expose a parent_session_id linkage so external tooling can correlate and sum costs across related sessions.

Use Case

I maintain a Claude Code plugin with a multi-agent SDL pipeline that orchestrates 6+ sub-agents (ticket fetcher, architect, implementer, reviewer, e2e tester, auditor). After a full pipeline run, the status line only shows the orchestrator's cost — a small fraction of the actual spend. Being able to see the total cost at a glance would help with cost awareness and budgeting.

Alternatives Considered

  • Manual state file tracking: Have each sub-agent write its token usage to a shared file, then read it in the status line script. Works but fragile and requires modifying every agent.
  • Parsing transcript files: Extract token counts from transcript JSONs. Slow and brittle.

Neither approach is ideal compared to native support.

extent analysis

TL;DR

To address the issue of invisible sub-agent costs in multi-agent workflows, consider implementing an aggregated cost field in the status line JSON input or exposing a parent_session_id linkage to correlate costs across related sessions.

Guidance

  • Investigate the feasibility of modifying the Agent tool to track and report token usage from sub-agents, potentially by introducing a new API or data structure to store and aggregate costs.
  • Explore the possibility of adding a parent_session_id field to the status line JSON input, allowing external tooling to correlate and sum costs across related sessions.
  • Evaluate the proposed JSON structure for the aggregated cost field, ensuring it meets the requirements for accurate cost representation and is compatible with existing tooling.
  • Consider the trade-offs between native support and alternative approaches, such as manual state file tracking or parsing transcript files, and assess their potential impact on the overall system.

Example

No code snippet is provided as the issue focuses on proposing a solution rather than implementing a specific code change.

Notes

The solution requires modifications to the underlying system or tooling, which may involve significant development and testing efforts. The proposed approaches may have varying degrees of complexity, performance impact, and compatibility with existing workflows.

Recommendation

Apply a workaround, such as manual state file tracking or parsing transcript files, until native support for aggregated cost tracking is implemented, as these alternatives can provide a temporary solution to address the immediate need for cost awareness and budgeting.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING