0.1.82: keep the system prompt static so Claude's cache holds (token burn fix) - #98
Merged
Merged
Conversation
The per-turn state snapshot (items, PRs, ids), the last turn's directive receipts, and the account-usage sentence were all appended to the system prompt, and all three change every turn. A system prompt that changes every turn never caches, so on a long conversation Claude re-billed the whole history at full input price instead of the cache read it should have been. The ledger showed 500k-900k input tokens per turn on an 800-message project, and the app's own "cache miss?" chip had been flagging it. Move all three onto the user turn, where changing content is cheap and where the task manager already carries its own lists. Regenerated fresh from the store each turn, they need no compaction survival. The system prompt is now stable across a conversation (repo rules, per-turn instructions, notes, checkpoint and memory locations), so the history is read from cache rather than re-sent in full. Bump to 0.1.82.
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.
The problem: fast Claude token burn
Three pieces of per-turn dynamic content were appended to the system prompt, and all three change every turn:
A system prompt that changes every turn never caches. On a long conversation Claude then re-bills the entire history at full input price instead of the ~10%-cost cache read it should be. The usage ledger showed 500k–900k input tokens per turn on an ~800-message project, and the app's own "cache miss?" chip had been flagging exactly this.
The fix
Move all three onto the user turn (where the task manager already carries its own lists). They're regenerated fresh from the store each turn, so they need no compaction survival and belong where changing content is cheap.
The system prompt is now stable across a conversation — repo rules, per-turn instructions, compaction notes, checkpoint + memory locations — so the history reads from cache instead of being re-sent in full. The agent still receives everything (snapshot + receipts + usage now lead the user message;
prompt_echo/I/O panel reflects it).Verify
cargo test -p az-gui— 130 pass;cargo fmt --check+clippyclean