claude-code - 💡(How to fix) Fix [BUG] Token counter appears to omit sub-agent consumption, causing up to 10× undercount [4 comments, 3 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#55121Fetched 2026-05-01 05:45:43
View on GitHub
Comments
4
Participants
3
Timeline
14
Reactions
0
Author
Timeline (top)
cross-referenced ×5labeled ×5commented ×4
RAW_BUFFERClick to expand / collapse

Describe the bug

The running token counter shown in the Claude Code Desktop app appears to only count API calls on the main conversation thread. When Claude spawns sub-agents via the Agent tool, those sub-agents make their own API calls — which appear to be invisible to the counter. The displayed number can therefore be off by an order of magnitude, with no indication that any omission is occurring.

To reproduce

Give Claude a task that causes it to spawn sub-agents (e.g. "build test infrastructure for these two repos"). Watch the running counter during execution. Compare the displayed token count to the actual API usage in the session's JSONL file under ~/.claude/projects/.

Expected behavior

The counter reflects total token consumption for the session, including all sub-agent API calls attributed to that session.

Actual behavior

In a concrete example: the Desktop counter showed ~60K tokens for a 51-minute autonomous task. The underlying session JSONL recorded 239 deduplicated API calls with 605K output tokens — roughly 10× the displayed figure. The counter gave no indication it was incomplete.

Impact

This affects every user trying to manage their consumption — Pro, Max, and Enterprise alike. Pro users have the least headroom and arguably the most to lose from an understated counter. Enterprise users have the most at stake financially. Nobody can manage what they can't accurately see.

This is not a niche concern. Anthropic has clearly recognized the importance of usage transparency — the Plan usage display (showing 5-hour limit, weekly limits, per-model breakdowns) is evidence of that investment. The sub-agent blind spot undermines the value of that entire feature: a user watching their plan consumption bars approach limits is working with a number that may be substantially lower than actual usage.

Prior art / not a duplicate

A search of existing issues turned up several that are related in theme but distinct in complaint:

  • #54623 — Reports unexpectedly high token consumption when sub-agents were used against the user's instructions. The complaint is about agent behavior (unauthorized sub-agent spawning) and task failure, not about the accuracy of the token counter display.

  • #36727 — Reports a sub-agent running in an unbounded loop with no tool call or time limits. The complaint is about the absence of guardrails on sub-agent execution, not about the counter failing to reflect sub-agent consumption.

  • #54673 — Requests that token counts be exposed to hooks and session context for programmatic use. This is a feature request for developer access to token metadata, not a bug report about the counter being incorrect for end users.

This issue is specifically about the counter being silently incomplete — not about agent behavior, not about programmatic access, but about the number shown to users being wrong in a way that makes cost management impossible.

extent analysis

TL;DR

The token counter in the Claude Code Desktop app needs to account for API calls made by sub-agents to provide an accurate total token consumption.

Guidance

  • Review the current implementation of the token counter to identify why it only counts API calls on the main conversation thread and not those made by sub-agents.
  • Modify the counter to include API calls from sub-agents, potentially by tracking all API calls associated with a session, regardless of the thread or agent making the call.
  • Verify the fix by comparing the displayed token count with the actual API usage in the session's JSONL file, as described in the reproduction steps.
  • Consider adding a notification or indicator when the counter is incomplete or has been updated to reflect sub-agent API calls.

Example

No specific code snippet can be provided without more details on the current implementation, but the solution likely involves modifying the counter's logic to aggregate API call data from all threads and agents within a session.

Notes

The exact implementation details of the fix will depend on the underlying architecture of the Claude Code Desktop app and how it tracks API calls and token consumption. Ensuring that the counter accurately reflects all API calls, including those from sub-agents, is crucial for users to manage their token consumption effectively.

Recommendation

Apply a workaround or fix to the token counter implementation to include sub-agent API calls, as this directly addresses the issue of silently incomplete token counting, which is critical for cost management.

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…

FAQ

Expected behavior

The counter reflects total token consumption for the session, including all sub-agent API calls attributed to that session.

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 [BUG] Token counter appears to omit sub-agent consumption, causing up to 10× undercount [4 comments, 3 participants]