Repository navigation
Count the conversation reloaded after a pause apart from a turn's tokens - #85
Merged
Merged
Conversation
A turn after a pause, or right after a restart, sends the whole conversation again because the prompt cache expired. Claude Code reports it as cache_creation_input_tokens, next to what is really new, so a short turn showed tens of thousands of tokens. The daemon now follows each model request and keeps, as `reloaded`, what the conversation already held and did not come from the cache (spec 8.7).
The turn line and the usage dialog count new input and replies, and tell the conversation sent again after a pause on its own, from 1k tokens on.
httpsphl
enabled auto-merge
October 1, 2026 02:19
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.
Why
A short turn after a pause showed a big token count: one real turn took 11 s and read "73.6k tokens", although the bot wrote under 1k. The numbers were right. The prompt cache had expired (the bot had been idle for 7 h and Botloft had just restarted), so the whole conversation was sent again and counted as
cache_creation_input_tokens. Claude Code reports that next to what is really new, because it sends new content (the message, tool results) to the cache too. Soinputalone stays near zero and can't tell the two apart.What
context/reload.rs): for each main-conversation model request (counted once permessage.id), it addsmin(cacheWrite, before - cacheRead), wherebeforeis the previous request's prompt size, or the size Claude Code reported when no request has been seen yet. A new conversation, or one that was just compacted, counts nothing. The turn item getstokens.reloaded, capped to the result'scacheWrite. Nothing new is stored beyond the field, and older items read 0.usage.tokenssumsreloaded, and bots are ordered by the new headline number.input + cacheWrite - reloaded + output. From 1k reloaded tokens, the turn line adds "reloaded the conversation (72k)", the line's tooltip explains it, and the usage dialog shows "· 72k reloaded". New text is in all three languages.Tests
cargo fmt --check,clippy -D warnings,cargo test --workspaceandpnpm checkpass.tests/token_reload.rsruns a cold turn then a warm one end to end.Manual test with real Claude Code