What's Wrong?
Claude code sessions sometimes reprocess the entire conversation instead of just a new message that a user sends. This is not due to any reason visible in the chat itself.
I found two causes by diffing /v1/messages requests around a cost spike.
- Claude Code rewrites an old hook reminder's shape later in the session. It does this by either moving it into its own message, or merging it into a neighboring one. Becausr this edits a message from earlier in the session's history, the entire session cache gets invalidated. I hit this multiple times in the same day.
- Long sessions only get one cache checkpoint, at the very end. This means that if this checkpoint is missed, you're SOL and the entire convo hits a cache write.
What Should Happen?
Old messages should not be modified, since this invalidates the entire cache, which can cost up to $20 (or even more...)
Steps to Reproduce
- Run a long VS Code session with PreToolUse hooks that add extra context to tool calls
- Diff consecutive raw request bodies around a big
cache_creation_input_tokens spike which should hit eventually
- You'll see an old
<system-reminder> block change shape, either split into its own message or merged into a neighboring one, breaking the cache for everything after it
Claude Code Version
2.1.197 (Claude Code)
Is this a regression?
Not sure, probably not
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
VS Code extension (CLI wrapper)
What's Wrong?
Claude code sessions sometimes reprocess the entire conversation instead of just a new message that a user sends. This is not due to any reason visible in the chat itself.
I found two causes by diffing
/v1/messagesrequests around a cost spike.What Should Happen?
Old messages should not be modified, since this invalidates the entire cache, which can cost up to $20 (or even more...)
Steps to Reproduce
cache_creation_input_tokensspike which should hit eventually<system-reminder>block change shape, either split into its own message or merged into a neighboring one, breaking the cache for everything after itClaude Code Version
2.1.197 (Claude Code)
Is this a regression?
Not sure, probably not
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
VS Code extension (CLI wrapper)