Skip to content

fix(claude): deduplicate multi-block assistant transcript rows - #135

Merged
bernardopg merged 2 commits into
mainfrom
fix/issue-131-claude-dedup
Nov 22, 2026
Merged

bernardopg merged 2 commits into
mainfrom
fix/issue-131-claude-dedup

Conversation

@bernardopg

Copy link
Copy Markdown
Owner

Summary

  • Deduplicate Claude transcript assistant rows by message.id (first occurrence wins) so multi-block assistant messages are counted once.
  • Keep id-less assistant rows defensively.
  • Append message.id as the last cached transcript TSV field and bump the transcript cache header to v2 so existing inflated caches rebuild on the next refresh.
  • Add regression coverage for same-id multi-block messages and same-id-different-file behavior.

Root cause

Claude Code writes one JSONL line per content block and repeats the full message.usage object on each line. providers/get-claude-usage parsed every assistant line as a separate usage row, inflating week/month/day tokens, costs, model splits and project splits.

Test plan

  • 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
  • bash -n providers/get-claude-usage
  • shellcheck -S warning providers/get-claude-usage tests/test-claude-dedup.sh tests/test-claude-cache.sh

Fixes #131

Claude Code writes one JSONL line per content block and repeats the full message.usage on every line. The transcript extractor counted each line, inflating week/month/day tokens, costs, model splits and project splits.

Deduplicate assistant rows by message.id (first occurrence wins), keep id-less lines defensively, append the id as the last cached TSV field, and bump the transcript cache header to v2 so existing inflated caches rebuild.

Fixes #131

Signed-off-by: Bernardo Pinto Gomes <[email protected]>
@github-actions github-actions Bot added documentation Improvements or additions to documentation area:providers Provider adapters (providers/) area:ci CI, workflows, tooling labels Nov 22, 2026
Signed-off-by: Bernardo Pinto Gomes <[email protected]>

# Conflicts:
#	CHANGELOG.md
@bernardopg
bernardopg merged commit 4af4463 into main Nov 22, 2026
20 checks passed
@bernardopg
bernardopg deleted the fix/issue-131-claude-dedup branch November 22, 2026 04:37
@bernardopg bernardopg mentioned this pull request Nov 22, 2026
4 of 7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, workflows, tooling area:providers Provider adapters (providers/) documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant