fix(parser): implement request dedup and deltaize for token accuracy#13
Merged
Conversation
- Deduplicate API responses by requestId to eliminate 2-3x overcounting from streaming chunks, sub-agent mirrors, and compact retries - Implement deltaize algorithm to correctly distribute tokens across minutes for long streaming responses with extended thinking - Preserve code metrics on partial-overlap streams using ghost markers - Fix ghost event filtering in model breakdowns Fixes token and cost accuracy issues observed with heavy sub-agent usage.
- Implement schema_version tracking in history.json - Auto-invalidate and rebuild cache on version mismatch - Fixes cache migration without manual user intervention
- Display cache state banner on startup (rebuilt or unreadable) - Add CCMETER_FORCE_BANNER env var for testing - Update dashboard styling for rate tracking components - Include new rate-tracking asset
- Add 'Accurate token counting' section explaining dedup approach - Update version to 2.0.0-beta.3 - Document all fixes and new features in CHANGELOG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements comprehensive token and cost accuracy fixes:
Commits
Changes
Token & cost accuracy — Claude Code logs the same API response in multiple places (streaming chunks, sub-agent mirrors,
/compactretries). CCMeter now dedupes byrequestId(Anthropic's billing unit), eliminating the 2–3× over-counting previously observed on days with heavy sub-agent activity.Multi-minute timeline accuracy — long streaming responses (extended thinking + large outputs) now correctly distribute their tokens across the minutes they actually spanned, instead of collapsing onto the final completion minute.
Cache schema versioning — new versioned cache with automatic invalidation on schema changes, eliminating manual intervention needed when upgrading.
Cache-state banner — UI now displays recovery banners on startup when cache is rebuilt or unreadable.
Documentation — README updated with 'Accurate token counting' section explaining the dedup methodology.