You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Claude usage totals double-count multi-block assistant messages (no message.id deduplication) #131
Dux Shell: v2.1.2
Quickshell: 0.3.2
Compositor: Hyprland
Distro: CachyOS Linux
Claude Code: 2.1.330
Steps to reproduce
Use Claude Code normally for a few days (any session with thinking or tool calls produces multi-block assistant messages).
Compare the panel's Claude Week tokens/cost against an independent sum over unique message ids in ~/.claude/projects/**/*.jsonl.
Expected behavior
Each assistant message's usage is counted once.
Actual behavior
Usage is counted once per JSONL line. Claude Code writes one line per content block, and every line of a message carries the full message usage object, so a 3-block message is counted 3 times. All Claude totals (today/week/month tokens and costs, per-model and per-project splits, and the daily series) are inflated accordingly.
Local checks
Measured on my transcripts (2026-11-19 to 2026-11-21):
- 7,611 assistant lines vs 3,608 unique .message.id values; 2,593 ids span multiple lines, and forevery one of them the repeated usage objects are byte-identical. No id appearsin two different files, and no assistant line lacks an id.
- Raw per-line sum: 1,544,771,153 tokens, which matches the panel's "1.5B". Deduplicated by message.id (first occurrence wins): 729,653,816 tokens and $214.56, vs the panel's $477 - about 2.12x inflation.
- The jq extraction in providers/get-claude-usage (get_claude_transcript_rows) builds one row per line with no id deduplication. Suggested fix: deduplicate by .message.id in that extraction (first occurrence wins, pass through any id-less lines), and bump the transcript cache header version so existing caches rebuild.
Thanks for the report, @SlobCoder, and especially for the diagnosis: the unique-id measurement, the confirmation that repeated lines carried identical usage objects, and the suggested message.id first-occurrence dedup made the root cause very clear.
What was happening
Claude Code writes one JSONL line per content block of the same assistant message and repeats the full message.usage object on each line. The extractor in providers/get-claude-usage counted every assistant line as a separate usage row, inflating week/month/day tokens, costs, model splits, and project splits. That matches the ~2.12x inflation you measured.
Deduplicates assistant rows by message.id (first occurrence wins).
Id-less assistant rows pass through defensively, so a format change does not drop usage.
message.id is appended as the last field in the cached transcript TSV.
The transcript cache header is bumped to v2, so existing inflated caches are rebuilt on the next refresh.
I also added regression coverage for same-id multi-block messages and for the same id appearing in different files (which should not be deduplicated across files).
Validation
I ran locally:
bash tests/test-claude-dedup.sh
bash tests/test-claude-cache.sh
bash tests/test-claude-pricing.sh
bash tests/test-claude-profiles.sh
bash tests/test-claude-statusline.sh
bash tests/test-claude-auth-renew.sh
When PR #135 is merged and you update, could you check whether the totals match your message.id-deduplicated sum in your environment? If any difference remains, please reopen with an anonymized snippet (field/types only, no prompt/response content) and I’ll take another look. Thanks again!
Activity
bernardopg commentedon Nov 22, 2026
Thanks for the report, @SlobCoder, and especially for the diagnosis: the unique-id measurement, the confirmation that repeated lines carried identical
usageobjects, and the suggestedmessage.idfirst-occurrence dedup made the root cause very clear.What was happening
Claude Code writes one JSONL line per content block of the same assistant message and repeats the full
message.usageobject on each line. The extractor inproviders/get-claude-usagecounted every assistant line as a separate usage row, inflating week/month/day tokens, costs, model splits, and project splits. That matches the ~2.12x inflation you measured.Fix
I opened PR #135 with the fix:
message.id(first occurrence wins).message.idis appended as the last field in the cached transcript TSV.v2, so existing inflated caches are rebuilt on the next refresh.I also added regression coverage for same-id multi-block messages and for the same id appearing in different files (which should not be deduplicated across files).
Validation
I ran locally:
bash tests/test-claude-dedup.shbash tests/test-claude-cache.shbash tests/test-claude-pricing.shbash tests/test-claude-profiles.shbash tests/test-claude-statusline.shbash tests/test-claude-auth-renew.shWhen PR #135 is merged and you update, could you check whether the totals match your
message.id-deduplicated sum in your environment? If any difference remains, please reopen with an anonymized snippet (field/types only, no prompt/response content) and I’ll take another look. Thanks again!