Repository navigation
fix(claude): keep cost available for resumed sessions' zeroed copies - #141
Merged
Merged
Conversation
…copies Resumed and forked Claude Code transcripts copy earlier messages with all four token totals zeroed but the original cache_creation split left in place. When the parent transcript is gone, those copies reached pricing, failed the split consistency check, and marked the whole session's cost unavailable. Treat a row whose four totals are all reported zero as an unbilled copy and ignore its stale split; any nonzero total with an inconsistent split still fails closed. Co-Authored-By: Claude Code <noreply@anthropic.com>
…d copy A row that omits a cache total must still fail the split consistency check instead of being priced as an unbilled copy. Co-Authored-By: Claude Code <noreply@anthropic.com>
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
Claude Code sessions that were resumed or forked could show their main-session cost as unavailable ("--"). This happened when the original parent transcript no longer existed.
This change treats a usage row as an unbilled copy when all four token totals (
input,output,cache_read,cache_creation_input_tokens) are present and reported as 0. The row's stalecache_creation5m/1h split is ignored. A row with any nonzero total, or with a missing total, and an inconsistent split still fails closed. The change is in_normalized_usageintoken_meter/runtimes/claude.py.Why
When Claude Code resumes or forks a session, it copies earlier messages into the new transcript. The copies have all four token totals set to 0, but they keep the original
cache_creation5m/1h split. Fork lineage normally drops these copies when the parent transcript exists.When the parent transcript has been cleaned up, the copy reaches pricing. Its split no longer sums to its total, so
billing_availablebecomes False. One such row marks the whole session's cost unavailable, even though its subagents still price correctly.In local data, 65 such rows appeared across 11 sessions. Each was a copy of a message billed with matching numbers in another session file.
I considered pricing the stale split instead, and rejected it because it double-counts. One local session went from $288 to $486.
Known behavior: a zeroed copy that still carries
server_tool_use.web_search_requestsis priced for web search. This matches existing behavior for copies with a consistent split. No local copy carries one.Testing
On head 68d1efc:
git diff --checkandpy_compileare clean.Not verified
./scripts/install,/health,/menubar, source/runtime parity).🤖 Generated with Claude Code