claude-code - 💡(How to fix) Fix [FEATURE] Expose aggregated cost, tokens, and lines from subagent and agent-team runs (for statusline) [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

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#60591Fetched 2026-05-20 03:54:34
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Timeline (top)
labeled ×4commented ×1

Fix Action

Fix / Workaround

Suggested scope: the minimum viable fix is the cost field, since it's the most visible to users and the hardest to recover manually (per-edit jsonl entries don't carry model-priced cost data, so a script would have to maintain its own pricing table to convert tokens to dollars). Lines next. Tokens last, since tokens are at least scrapable today - though even that workaround has to descend into the subagents/ nested directory and is fragile.

Manual workaround (and why it's brittle):

Code Example

~/.claude/projects/<project-slug>/
  ├── <parent-session-uuid>.jsonl            # parent session
  └── <parent-session-uuid>/
        └── subagents/
              ├── agent-<id-1>.jsonl         # subagent or agent-team member
              ├── agent-<id-2>.jsonl
              └── ...
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing requests and this feature hasn't been requested yet
  • This is a single feature request (not multiple features)

Problem Statement

The JSON payload passed to statusLine commands reflects only the parent session's cost, lines changed, and token usage. Subagent and agent-team runs - both of which create their own child sessions - are not aggregated into the parent, so any custom status line in a workflow that uses delegation materially understates the true spend.

Concretely, for a parent session that spawns subagents or agent teams:

  • cost.total_cost_usd shows only what the parent burned. Each subagent and each agent in an agent team is billed in its own session jsonl file, and none of those costs roll up.
  • cost.total_lines_added / cost.total_lines_removed count only Edit/Write tool calls made from the parent session. Edits performed by subagents or agent-team members are counted in their own sessions.
  • Token usage in context_window.* and similar fields is parent-only too.

The user never sees the gap unless they go digging in ~/.claude/projects/. As Claude Code leans further into delegated execution, this divergence will only grow.

Proposed Solution

Expose totals in the statusLine JSON that include subagent and agent-team activity from the parent's perspective. Two possible shapes:

  1. Aggregate the existing fields by default (potentially backward-incompatible, so probably not the right path).
  2. Add new sibling fields that sum across the parent and any child sessions. Some possible shapes:
    • Flat additions: cost.total_cost_usd_aggregated, cost.total_lines_added_aggregated, cost.total_lines_removed_aggregated, tokens.aggregated.{input,output,cache_creation,cache_read}.
    • Or a nested children / delegated object: cost.children.cost_usd, cost.children.lines_added, cost.children.lines_removed, tokens.children.{...}. Lets a script display parent-only, children-only, or sum-of-both.

Whichever shape is chosen, the key property is that the naming should cover any kind of delegated execution - subagents today, agent teams today, and any future delegated-session primitive. A name like _with_subagents would be too narrow; _aggregated or _children or _delegated is preferable.

Suggested scope: the minimum viable fix is the cost field, since it's the most visible to users and the hardest to recover manually (per-edit jsonl entries don't carry model-priced cost data, so a script would have to maintain its own pricing table to convert tokens to dollars). Lines next. Tokens last, since tokens are at least scrapable today - though even that workaround has to descend into the subagents/ nested directory and is fragile.

Alternative Solutions

No response

Priority

Low - Nice to have

Feature Category

API and model interactions

Use Case Example

The status line is the first place a user looks to answer "how much has this session cost me?" and "how much has Claude actually changed?". Today, in any workflow that uses subagents or agent teams (which Claude Code increasingly encourages), the answer is silently wrong:

  • A multi-agent refactor that costs $50 shows up as $5 in the bar.
  • An orchestrated task that produces +2000 / -800 lines reads as +200 / -80.
  • Cumulative tokens are recoverable only by scraping transcripts manually across a nested directory structure.

Concrete workflow: a user runs a custom slash-command that delegates to a six-specialist agent team (correctness, security, tests, coverage, conventions, performance) in parallel. The status line afterwards shows $2.30 of spend and +0 / -0 lines. The actual cost across the six agent transcripts is $18.50, and a couple of those agents collectively wrote +800 / -120 lines into review notes. None of that is visible from the parent's status line - the user has no way to know what they actually spent without parsing jsonl files manually.

Additional Context

Where subagent and agent-team transcripts live on disk:

~/.claude/projects/<project-slug>/
  ├── <parent-session-uuid>.jsonl            # parent session
  └── <parent-session-uuid>/
        └── subagents/
              ├── agent-<id-1>.jsonl         # subagent or agent-team member
              ├── agent-<id-2>.jsonl
              └── ...

Each child transcript has isSidechain: true, a distinct sessionId, an agentId, and the standard message.usage token fields. Both subagent runs (single Agent tool calls) and agent-team runs end up in the same subagents/ subdirectory - the directory structure doesn't distinguish them, and from the parent session's reporting perspective they behave identically.

Manual workaround (and why it's brittle):

To recover even just token totals today, a status-line script has to:

  1. From the transcript_path provided in the statusLine JSON, derive the project directory.
  2. Walk both the project directory and every nested <session-uuid>/subagents/ subdirectory under it.
  3. Parse every modified jsonl file and sum message.usage.input_tokens, message.usage.output_tokens, message.usage.cache_creation_input_tokens, and message.usage.cache_read_input_tokens itself.

This works but it's brittle (couples the script to internal jsonl layout and the subagents/ directory convention), slow on large sessions (100-500ms per status-line refresh on multi-MB transcripts), and as noted in the Proposed Solution, cost can't really be recovered this way at all.

References:

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

claude-code - 💡(How to fix) Fix [FEATURE] Expose aggregated cost, tokens, and lines from subagent and agent-team runs (for statusline) [1 comments, 2 participants]