Feature request: Per-Agent-tool-call token usage in modelUsage result event

Resolved 💬 1 comment Opened Apr 11, 2026 by konard Closed May 24, 2026

Feature Request

When using Claude Code with --output-format stream-json, the result event's modelUsage field provides per-model token usage totals aggregated across the entire session. When the Agent tool is used multiple times (e.g., spawning sub-agents), all calls to the same model are combined into a single entry.

Current behavior:

{
  "type": "result",
  "subtype": "success",
  "modelUsage": {
    "claude-sonnet-4-6": {
      "inputTokens": 681400,
      "outputTokens": 338900,
      "cacheReadInputTokens": 3900000,
      "cacheCreationInputTokens": 0,
      "costUSD": 8.806153
    }
  }
}

This doesn't distinguish between, e.g., 12 separate Agent tool calls to Sonnet.

Desired behavior:

Provide per-Agent-tool-call token usage data, e.g.:

{
  "type": "result",
  "subtype": "success",
  "modelUsage": { /* existing aggregated data */ },
  "agentCallUsage": [
    {
      "toolUseId": "toolu_01KxHXxnfTCDEq3ETvH1NYMb",
      "model": "claude-sonnet-4-6",
      "description": "Translate README.md to Chinese",
      "inputTokens": 45000,
      "outputTokens": 28000,
      "cacheReadInputTokens": 320000,
      "costUSD": 0.73
    },
    /* ... more entries for each Agent call */
  ]
}

Use Case

In orchestrator systems that use Claude Code to solve complex tasks, the main agent (e.g., Opus) frequently spawns multiple sub-agents (e.g., Sonnet) via the Agent tool. Without per-call breakdown:

  • Token usage percentages become misleading (e.g., "338.9K / 64K (530%) output tokens" is actually 12 calls averaging ~28K each)
  • Cost allocation per sub-task is impossible
  • Debugging which sub-agent call was expensive requires log parsing

Workaround

We currently:

  1. Count Agent tool_use events in the stream to get the number of calls per model
  2. Calculate averages (total tokens / call count)
  3. Display these averages alongside the aggregate totals

This provides a reasonable approximation but exact per-call data would be much more useful.

Example

Real-world scenario from link-assistant/hive-mind#1590:

Main agent (Opus) spawned 12 Agent tool calls to Sonnet for translating documentation files. The aggregated display showed 530% of the output limit, which was confusing. With per-call data, each call averaged ~44% of the limit — well within bounds.

Reproducible Example

# Start Claude with stream-json output
claude --output-format stream-json -p "Create 3 translations of this text using Agent tool: 'Hello World'" --model opus

# The result event will have modelUsage aggregated across all Agent calls
# No way to see per-Agent-call token breakdown

Suggested Implementation

Add an optional agentCallUsage array to the result event when Agent tool was used during the session. Each entry would contain the tool_use_id, model, description, and token usage for that specific Agent call.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗