Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsDeduplicating repeated message IDs fixes one common overcount, but it does not guarantee that a total parsed from Claude Code logs is correct. Other causes include placeholder output counts, cumulative results from resumed sessions, mismatched subagent scope, or genuinely heavy context processing. Without the Claude Code version, source format, and representative records, the remaining discrepancy cannot be assigned to one cause.
First, identify which total you are calculating
“Usage” can mean several different things: output from one response, a query’s completed token usage, a resumed session’s accumulated spend, all models in an agent tree, or a local estimate of cost. Those figures are not interchangeable.
As an Amazon Associate I earn from qualifying purchases.
| Question | Relevant source | Important qualification |
|---|---|---|
| How much output was reported as a response finished? | Agent SDK result message usage | Use the completed result rather than treating each assistant message’s output count as final. |
| How much did each model use, including subagents? | SDK modelUsage or model_usage in the same cost guide |
The result’s top-level usage covers the main loop, not subagents. |
| What was the output progress during streaming? | Documented message_delta usage events in the cost guide |
Use the stream’s documented events, not repeated snapshots as if each were new usage. |
| What does a local session transcript show? | The specific Claude Code transcript and parser | The SDK guide does not establish that every local JSONL version exposes identical fields or snapshot semantics. |
| What was billed? | An authoritative billing record | An SDK cost estimate uses a client-side price table and may differ from billed cost when prices or billing rules differ. |
Why deduplicating message IDs may not be enough
Repeated records can represent one response
Anthropic’s Agent SDK guide says that when Claude uses multiple tools in one turn, the messages in that turn can share an ID; count that shared response ID once when accumulating per-step usage. The guide states: “When Claude uses multiple tools in one turn, all messages in that turn share the same ID, so deduplicate by ID to avoid double-counting.” This is SDK guidance, not proof that repeated rows in every local transcript have the same meaning. Group candidate rows by the documented identifier and inspect their usage fields. Do not merge distinct IDs merely because their text looks alike.
Free tools Windows power users keep installed
One-click scans. No signup required.
Assistant output counts can be placeholders
In the SDK, an assistant message’s output_tokens can be a placeholder based on what the API reported when the message started. For a completed SDK query, use the result message’s usage; use modelUsage or model_usage when you need per-model usage or whole-tree accounting. For streaming progress, use the documented message_delta usage events. These distinctions are described in Anthropic’s Agent SDK cost guide.
#1 Best Overall
Resumed-session results may include earlier usage
A result from a call that resumes a session can include spend from earlier in that session. Adding every result together can therefore count earlier usage more than once. For a resumed session total, use the latest applicable result rather than summing cumulative results. Streaming-input mode has its own running-total and reset rules; aggregate it according to those documented boundaries.
Main-loop usage and whole-tree usage have different scope
The SDK result’s top-level usage covers the main loop and excludes subagents. modelUsage or model_usage is the documented route to whole-tree token accounting. Before combining a parent total with child traces, check whether the parent already includes that work; otherwise the scopes may overlap.
A corrected count can still be high
Claude Code sends conversation history and project context with later turns. A parser can remove duplicate representations correctly and still show substantial usage because the session processed a large or growing context. That is different from a counting error. Anthropic’s explanation of Claude Code usage is in its cost guide.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchA practical way to investigate the remaining discrepancy
- Record the source and version. Note whether the data came from streamed Agent SDK messages, an SDK result, a local session transcript, or an export rebuilt by another tool. Record the Claude Code and SDK versions; local transcript semantics are not established as identical across formats.
- Inspect repeated IDs and usage objects. For SDK parallel-tool messages, count a shared response ID once. Check whether the rows repeat the same usage snapshot. Do not deduplicate separate response IDs solely on similar content.
- Verify the field used for output. If the sum reads assistant-message
output_tokens, it may be adding start-of-response placeholders. For a completed SDK query, compare with the result message’susage; for streaming, use the documented delta events. - Check the aggregation boundary. Determine whether each result is an independent query total or a cumulative resumed-session result. Avoid adding successive cumulative snapshots; follow streaming-input reset boundaries where applicable.
- Check subagent coverage. Decide whether the desired number is main-agent-only or whole-tree usage. Use the relevant SDK field and avoid adding parent and child figures until their scopes are known.
- Compare billing only to billing records. A local estimate is not an authoritative billed amount; SDK estimates can diverge when prices or billing rules differ.
- Keep a small redacted sample. Retain representative IDs and usage fields alongside the version details. Transcripts may contain prompts, tool outputs, URLs, credentials, and personal information; redact secrets before sharing them for parser debugging.
What is known about duplicate-ID prevalence
A third-party analysis by Frederick Douglas Pearce reported duplicate assistant message IDs in 986 of 1,047 files (94%) in the author’s measured corpus, with naive row summation inflating that corpus’s total by 1.99×. Those are corpus-specific results, not an Anthropic statistic, a platform-wide prevalence estimate, or evidence about any particular reader’s file: the author’s analysis.
Rank #3
Anthropic’s separate compliance-session API documentation instructs clients to deduplicate listed sessions by session ID and messages by message ID. It describes captured transcripts as reconstructed from API calls and notes that content may be unavailable or truncated in specified circumstances. That guidance applies to the compliance API; it should not be generalized to every local Claude Code JSONL format.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




