Skip to content

[Bug]: Claude usage totals double-count multi-block assistant messages (no message.id deduplication) #131

Closed

Description

@carrotciallo

Plugin version

2.5.0

Area

Provider usage helper

Environment

Dux Shell: v2.1.2
Quickshell: 0.3.2
Compositor: Hyprland
Distro: CachyOS Linux
Claude Code: 2.1.330

Steps to reproduce

  1. Use Claude Code normally for a few days (any session with thinking or tool calls produces multi-block assistant messages).
  2. 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 for every one of them the repeated usage objects are byte-identical. No id appears in 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.

Activity

  1. added
    bug
    on Nov 21, 2026
  2. bernardopg commented on Nov 22, 2026

    @bernardopg
    Owner

    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.

    Fix

    I opened PR #135 with the fix:

    • 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions