[BUG] Forking a session re-creates context cache
Status Fixed / completed
Maintainer reply None cached
Activity 3 comments · opened Mar 31, 2026 · closed May 15, 2026
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
When using /branch, claude code seems to re-create the cache instead of reading from it, is it expected that context cache might not be easily shared between sessions?
What Should Happen?
Sessions with shared prefixes should share the context cache.
Error Messages/Logs
Steps to Reproduce
1) Create a warmed session in claude code (choose any large-ish file)
❯ head /var/log/syslog -1000 | claude
2) Fork/ branch the session in claude code
/branch
3) Ask something in the new session,
What are we doing here
4) check usage stats of the warmed and the branched sessions
❯ npx ccusage session -O -b -i 97aae588-7518-45ff-b710-5a69e6bdf358
...
┌───────────┬─────────────────┬───────────┬───────────┬───────────────┬─────────────┬─────────────┐
│ Timestamp │ Model │ Input │ Output │ Cache Create │ Cache Read │ Cost (USD) │
├───────────┼─────────────────┼───────────┼───────────┼───────────────┼─────────────┼─────────────┤
│ 2026 │ claude-opus-4-6 │ 2 │ 28 │ 71,867 │ 12,463 │ $0.00 │
│ 03-30 │ │ │ │ │ │ │
├───────────┼─────────────────┼───────────┼───────────┼───────────────┼─────────────┼─────────────┤
│ 2026 │ claude-opus-4-6 │ 2 │ 127 │ 71,867 │ 12,463 │ $0.00 │
│ 03-30 │ │ │ │ │ │ │
└───────────┴─────────────────┴───────────┴───────────┴───────────────┴─────────────┴─────────────┘
❯ npx ccusage session -O -b -i 76781672-ed1a-4483-bf60-ceaa10b605ad
....
┌───────────┬─────────────────┬───────────┬───────────┬───────────────┬─────────────┬─────────────┐
│ Timestamp │ Model │ Input │ Output │ Cache Create │ Cache Read │ Cost (USD) │
├───────────┼─────────────────┼───────────┼───────────┼───────────────┼─────────────┼─────────────┤
│ 2026 │ claude-opus-4-6 │ 2 │ 28 │ 71,867 │ 12,463 │ $0.00 │
│ 03-30 │ │ │ │ │ │ │
├───────────┼─────────────────┼───────────┼───────────┼───────────────┼─────────────┼─────────────┤
│ 2026 │ claude-opus-4-6 │ 2 │ 127 │ 71,867 │ 12,463 │ $0.00 │
│ 03-30 │ │ │ │ │ │ │
├───────────┼─────────────────┼───────────┼───────────┼───────────────┼─────────────┼─────────────┤
│ 2026 │ claude-opus-4-6 │ 3 │ 29 │ 69,946 │ 12,463 │ $0.00 │
│ 03-30 │ │ │ │ │ │ │
├───────────┼─────────────────┼───────────┼───────────┼───────────────┼─────────────┼─────────────┤
│ 2026 │ claude-opus-4-6 │ 3 │ 592 │ 69,946 │ 12,463 │ $0.00 │
│ 03-30 │ │ │ │ │ │ │
├───────────┼─────────────────┼───────────┼───────────┼───────────────┼─────────────┼─────────────┤
│ 2026 │ claude-opus-4-6 │ 3 │ 52 │ 72,229 │ 12,463 │ $0.00 │
│ 03-30 │ │ │ │ │ │ │
├───────────┼─────────────────┼───────────┼───────────┼───────────────┼─────────────┼─────────────┤
│ 2026 │ claude-opus-4-6 │ 3 │ 243 │ 59 │ 84,692 │ $0.00 │
│ 03-30 │ │ │ │ │ │ │
└───────────┴─────────────────┴───────────┴───────────┴───────────────┴─────────────┴─────────────┘
The Cache gets re-created in the branch and we do not hit a cache read immediately in the branched session.
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
v2.1.88
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
WSL (Windows Subsystem for Linux)
Additional Information
_No response_
3 Comments
Likely root cause --
src/services/api/claude.ts:519–527every API request includes:--fork-sessioncreate a new session ID, and thus changes user_id and invalidates cache.Proposed fix --
Either don't include
session_idinuser_id, or replace with a conversation_id that's stable across forksBeen a while, but just retested it and it worked in
2.1.119This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.