Track cost and usage changedagent-sdk/cost-tracking
Nearest release: v2.1.280, published 12 hours after upstream edited the page. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.
Upstream edited this page at 22 Sep 2026 03:07 UTC, give or take a minute or two: the time comes from Anthropic’s own sitemap rather than from a commit. This site recorded the change at 28 Sep 2026 23:37 UTC.
Upstream edited
Recorded here
Lines+5added
Lines−5removed
From line
85
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits11to this page, all time
The whole hunk
from line 85, old and new numbered
/
from line 85
8585
8686The three result-level fields differ in what they count when the agent spawns [subagents](/docs/en/agent-sdk/subagents). Use `modelUsage`, or `model_usage` in Python, for whole-tree token accounting; the `usage` field undercounts as soon as nesting occurs.
8787
88| Field | Subagent activity |
89| ---------------------------- | ------------------------------------------------------------------------------------------------- |
90| `usage` | Excluded. Counts only the top-level agent loop, so tokens consumed inside subagents are not added |
91| `total_cost_usd` | Included. Counts subagent requests alongside the top-level loop |
92| `modelUsage` / `model_usage` | Included. Counts subagent requests alongside the top-level loop, broken down by model |
88| Field | Subagent activity |
89| - | - |
90| `usage` | Excluded. Counts only the top-level agent loop, so tokens consumed inside subagents are not added |
91| `total_cost_usd` | Included. Counts subagent requests alongside the top-level loop |
92| `modelUsage` / `model_usage` | Included. Counts subagent requests alongside the top-level loop, broken down by model |
9393
9494In [single message input mode](/docs/en/agent-sdk/streaming-vs-single-mode#single-message-input), when background subagents are still running at the end of the final turn, Claude Code waits for them, up to the cap described in [background tasks at exit](/docs/en/headless#background-tasks-at-exit), before emitting the result. The result's `total_cost_usd`, `duration_api_ms`, and `modelUsage`, or `model_usage` in Python, include the work done during that wait.
9595
No line in this hunk matches that.