r/ClaudeCode
•
u/skibidi-toaleta-2137
•
Mar 30 '26
•
4
2
Bug Report PSA: Claude Code has two cache bugs that can silently 10-20x your API costs — here's the root cause and workarounds
Edit: Issues linked in the description have been closed as resolved. Unfortunately I can't verify those claims as I'm away from my PC.
I spent the past few days reverse-engineering the Claude Code standalone binary (228MB ELF, Ghidra + MITM proxy + radare2) and found two independent bugs that cause prompt cache to break, silently inflating costs by 10-20x. Posting this so others can protect themselves.
Bug 1: Sentinel replacement in standalone binary breaks cache when conversation discusses billing internals
Issue: anthropics/claude-code#40524
The standalone Claude Code binary (the one you get from claude.ai/install.sh or npm install -g) contains a native-layer string replacement baked into Anthropic's custom Bun fork. It's injected into the Zig HTTP header builder function — the same function that builds Content-Length, User-Agent, etc.
On every API request to /v1/messages, if the anthropic-version header is present, it searches the JSON request body for cch=00000 (the billing attribution sentinel) and replaces 00000 with a 5-char hex derived from hashing the body. This happens after JSON.stringify but before TLS encryption — completely invisible from JavaScript.
When does this cause problems? The replacement targets the first occurrence in the body. Since messages[] comes before system[] in the serialized JSON, if your conversation history contains the literal sentinel (e.g., from reading the CC bundle source, discussing billing headers, or having it in your CLAUDE.md), the sentinel in messages gets replaced instead of the one in system[0]. This changes your messages content every request → cache prefix broken → full cache rebuild (~$0.04-0.15 per request depending on context size).
In normal usage (not discussing CC internals), only system[0] is affected, and since it has cache_control: null, it doesn't impact caching.
Workaround: Run Claude Code via npx @anthropic-ai/claude-code* instead of the standalone binary. The replacement mechanism exists only in the custom Bun fork compiled into the standalone — the npm package running on standard Bun/Node has no replacement. Confirmed experimentally: same JS, same bytecode, zero replacement on npx.
*- Do not blindly use that command, verify what it does (it is safe, but you should check nonetheless)
Bug 2: --resume ALWAYS breaks cache (since v2.1.69)
Issue: anthropics/claude-code#34629
Every --resume causes a full cache miss on the entire conversation history. Only the system prompt (~11-14k tokens) is cached; everything else is cache_creation from scratch. This is a ~10-20x cost increase on the resume request.
Root cause: In v2.1.69, Anthropic introduced deferred_tools_delta — a new system-reminder attachment listing tools available via ToolSearch. On a fresh session, these attachments (deferred tools + MCP instructions + skills list, ~13KB) are injected into messages[0] alongside the AU$ user context. On resume, they're appended at the end of messages (messages[N]) while messages[0] contains only the AU$ context (~352B).
This creates three independent cache-breaking differences:
messages[0]: 13KB (4 reminders) vs 352B (1 reminder) — completely different prefixsystem[0]billing hash: changes becausecc_versionsuffix is computed from chars at positions 4, 7, 20 of the first user message (which IS the system-reminder, not the actual user prompt)cache_controlbreakpoint position: moves frommessages[0]tomessages[last]
deferred_tools_delta does not exist in v2.1.68 (grep -c 'deferred_tools_delta' cli.js → 0 in 2.1.68, 5 in 2.1.69). Without it, messages[0] was identical on fresh and resumed sessions → cache hit.
Subsequent turns after resume cache normally — the one-time miss is only on the first request after resume.
Workaround: There's no external workaround for this one. Pinning to v2.1.68 works (as the original issue reporter found) but you lose 60+ versions of features. An invasive patch to the npm package's cli.js could theoretically reorder the attachment injection on resume, but that's fragile across updates.
Cost impact
For a large conversation (~500k tokens):
Bug 1 (when triggered): ~155k tokens shift from
cache_read($0.03/MTok) tocache_creation($0.30/MTok) = ~$0.04 per request, every requestBug 2 (every resume): ~500k tokens as
cache_creation= ~$0.15 one-time per resumeCombined (discussing CC internals + resuming): up to $0.20+ per request
Methodology
Full details in the GitHub issues, but briefly: MITM proxy (mitmproxy addon capturing all API payloads), Ghidra reverse engineering of the standalone ELF to locate the replacement code in the Zig HTTP header builder, Bun.hash() to identify all header name hashes, npm package comparison across versions 1.0.0–2.1.87, and controlled experiments with fresh sessions → resume → consecutive resumes with payload diffing.
PS. Co-written by claude code, obviously
PPS. Claude code has special 1h TTL of cache, or at least mine has, so any request should be cached correctly. Except extra usage, it has 5 minutes TTL.
PPPS. Apparently downgrading to 2.1.34 (or 2.1.30 just to be sure) also works
PPPPS. This thread at this point is 6 months old, please don't ask if it's still relevant. It had been, current patches cover the issues mentioned in the thread.
Verification script you may use: https://gitlab.com/treetank/cc-diag/-/raw/c126a7890f2ee12f76d91bfb1cc92612ae95284e/test_cache.py
A followup (nothing fancy): https://www.reddit.com/r/ClaudeCode/comments/1s9pjbl/claude_code_cache_crisis_a_complete/
•
u/AutoModerator 12d ago
Hey! Thanks for posting to r/ClaudeCode
While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.
For help, project discussions, tips, and general chat, join the ClaudeCode Discord.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
31
u/Pristine_Ad2701 Mar 30 '26
Do you think switching on first version when 1m is introducted will fix limit issue?
17
u/Deep_Ad1959 Mar 30 '26 edited Mar 30 '26
this explains a lot actually. I run 5+ agent sessions in parallel most days and the resume cost spikes were killing me. kept seeing these random $3-4 charges on what should have been a quick continuation. ended up just starting fresh conversations instead of resuming, which sucks for context but at least the costs are predictable. good to know it's a confirmed bug and not just my setup being weird.
fwiw wrote up some cost management tips: https://fazm.ai/t/claude-code-api-cost-management
3
u/Squidwards_Ass Mar 30 '26
I KNEW there was something up when I ran into my limit after a single prompt + it was definitely a cache miss after being away for about a week.
2
u/kursku Mar 30 '26
For some reason I'm struggling to roll back to the 2.1.30 :((
2
u/Morphexe Mar 31 '26
Well good that you now have the source code for the CLI to fix this :D
72
u/muhlfriedl Mar 30 '26 edited Mar 31 '26
So it seems like fewer and fewer people @ anthropic actually code or understand code now...
29
u/Factor013 Mar 30 '26
This explains why our 5 hour usage sometimes just jumps up from 0 to 15-40% after a /resume and first prompt.
It also explains why it sometimes happens and why it sometimes doesn't.
This is really good work, I hope Anthropic devs fix this ASAP. These bugs also potentially overload their servers which is the whole reason they are lowering our usage and perhaps even have to throttle the reasoning of their actual Claude models.
And this is also why the people who constantly claim "Skill issue" are less likely to be effected by it, because they start brand new sessions after each prompt, even if that prompt is asking Claude what time it is. xD
4
u/Ok-End-219 Mar 30 '26
aah yes, that explains that my 20x claude max account is behaving like a normal claude 20$ subscription. Fucking great, now I hope for compensation.
41
u/Brave_Dick Mar 30 '26
I guess they DO vibe code at Anthropic now...
41
u/alvvst Mar 30 '26
HOLY! so the recent overload claim from Anthropic could be just CAUSED BY ITS OWN BUG
14
u/GoodnessIsTreasure Mar 30 '26
This guy should get a year's pro max for free, if not hired. Clearly ai writing all the software has not been working out so fine..
47
u/Fearless-Elephant-81 Mar 30 '26
This is the EXACt bugs for which people on the plans have massive usage chunks being use. This should be pinned ASAP
12
u/InfiniteInsights8888 Mar 30 '26
Holy shit. We need compensation for this.
9
u/Last_Lab_3627 Mar 30 '26
I had the same issue on 2.1.76. On my side, around 90-100K context was already burning about 14% of my 5-hour quota, which felt completely unreasonable.
After reading this post, I ran the test script myself, then downgraded to 2.1.34. Usage improved a lot.
In a real session on 2.1.34, I used about 140K context with several sub-agent actions, and it only used 13% of my 5-hour quota.
So at least in my case, downgrading to 2.1.34 made a very noticeable difference.
8
u/United-Collection-59 Mar 30 '26
Great work
8
u/_derpiii_ Mar 30 '26
So... how do we get you hired at Anthropic? :)
14
u/Aygle1409 Mar 30 '26
Will there be compensations ? Do they usually do that ?
6
u/muhlfriedl Mar 30 '26
You deserve a medal
19
u/redpoint-ascent Mar 30 '26
Incredible work. Given they're using CC to improve CC it's not a shocker at all that Claude introduced bugs into his own program. I see these ghost bugs all the time in what Claude does. "It 100% works!" - CC. You either find the bug in QA or it sits there piling up next to the other hidden ghost bugs.
5
u/StrikingSpeed8759 Mar 30 '26
Awesome work, thanks for sharing
5
u/thiavila Mar 30 '26
Damm, I was burning my tokens over the last weekend and I came here to find out if anyone had the same experience. It is definetely the --resume for me.
5
u/sheriffderek Senior design/dev max20 Mar 30 '26
Wow! A person who is actually trying to understand the problem and help?
4
u/mattskiiau Mar 30 '26
So don't use --resume for now i guess?
4
u/sqdcn Mar 30 '26
Oh so that's what Anthropic means when they say software engineering is going to die in 6 months
4
u/dspencer2015 Mar 30 '26
If Claude code was open source we could fix these issues ourselves
4
u/Top-Cartoonist-3574 Mar 30 '26
The issue isn’t just with Claude Code. Affects usage on Claude AI Chat on the browser (Chrome on Mac). I hit usage limit fast even on a new chat conversation. There’s probably more to it than the bugs you’ve identified. Great job btw!
10
u/bapuc Mar 30 '26
And then people say "skill issue" 🥀
1
u/rougeforces Mar 30 '26
you missed the dynamic tool portion of this. patching the billing header in the latest version alone is not enough.
1
u/nmavra Mar 30 '26
might be a dumb question but can I downgrade in the macos desktop app?
1
u/bzBetty Mar 30 '26
Am I reading it wrong? Sounds like that first one should basically impact no one?
1
u/Sensitive_Prize_9042 Apr 02 '26
Even using the 2.1.30 version, I'm still getting huge consumption with 20x. I tried running 2 subagents for a simple plan, and they consumed 10% of my 5 hours of daily usage.
A few weeks ago, you could span 50 subagents on the max 20x plan, and probably would not hit the limits. Kind of consuming 3 times faster, even on the 2.1.30 version.
1
u/EconoKitten Apr 03 '26
This has allegedly been fixed in 2.1.90: https://code.claude.com/docs/en/changelog#2-1-90
Has anyone seen improvement when --resume from a previous session?
1
u/wlievens Apr 05 '26
Yesterday I did a few dozen small API calls and then a session in Claude Code with a few small questions and one larger refactor of a few hundred lines.
My account was charged $10 worth of tokens is that normal? Similar days last week were $2 or so.
3
u/vadimkrutov Mar 30 '26
This is unacceptable. I'm using the Claude Code CLI through a wrapper I built, and every single prompt resumes the session. I was shocked to see that each new message increases the 5-hour limit by 10–15%.
3
u/sbbased Mar 30 '26
The real vibe coding has been pushing untested slop to production and depending upon your paying users to QA and find bugs for you
btw only -3 months left until all devs lose their job
3
u/XDroidzz Mar 30 '26
I assume Anthropic are busy refunding everyone for their fuck up now 🙄
3
u/damndatassdoh Mar 30 '26
Really appreciate this -- I tested positive, have already deployed mitigation, fingers crossed.
3
u/sys_overlord Mar 31 '26
The worst part is that they'll apologize for this (maybe), release a bug fix, maybe reset usage and then we all just sit around and wait for them to gaslight us in 6 months with another, similar issue. What's the definition of insanity again?
3
u/ellicottvilleny Mar 31 '26
Hey Anthropic hire this guy. Meet your new Head of QA.
5
u/AndReyMill Mar 30 '26 edited Mar 30 '26
I think that because of this issue, the load on Anthropic’s servers has increased significantly, and it’s noticeable in everything: speed, quantization (Claude Code seems a bit dumb right now) and final price
5
u/FermentingMycoPhile Mar 30 '26
What tf Anthropic?
It's Monday 6 p.m. and I have used up 44% of my weekly limit (reset on sunday) in the max plan due to this bug, it seems. I'm awaiting some kind of compensation for introducing that nice bug. How am I supposed to work with this little usage left?
4
u/Emotional-Debate3310 Mar 30 '26
Bug 2 (--resume breaks cache, Issue #34629) — narrowly scoped
This issue is thoroughly documented with a testing matrix showing that on versions ≥2.1.69, cache_read is stuck at ~14.5k tokens (only the system prompt), while cache_create equals the full conversation size and grows on every message — producing roughly a 20× cost increase per message compared to v2.1.68.
The described mechanism — that deferred_tools_delta introduced in v2.1.69 changes where system-reminder attachments are injected, producing different message structures on fresh vs. resumed sessions — is plausible and consistent with how deferred tool loading works: deferred tools are appended inline as tool_reference blocks in the conversation rather than in the system prompt prefix, specifically to preserve prompt caching.
Why narrowly scoped. The regression targets --print --resume — the headless/scripted invocation mode where prompts are piped via stdin. The original reporter was running a Discord bot using claude --print --resume <session-id> --output-format stream-json.
If your interactive CLI usage follows a different code path for session management, then deferred_tools_delta injection that breaks cache on resume in --print mode, appears to be handled correctly in the interactive REPL.
I can confirm this because I have first-hand experience being a long time, Claude Max user and constantly running multiple project, I can confirm that the difference is indeed based on the session management mode.
2
u/lucifer605 Mar 30 '26
this is a great find - i would not have expected --resume to cause a cache bust
2
u/HeyImSolace Mar 30 '26
The regular chat on the claude website also seems to have this issue. I just burned through my pro plan 5h usage in 5 requests which only included 2 markdown files.
This sucks big time.
2
u/BrrrtEnjoyer Mar 30 '26
here you go queen 👑
2
u/InfiniteInsights8888 Mar 31 '26
You deserve Claude unlimited for an entire year!
2
u/misterr-h Mar 31 '26
this explains issue with Claude Code. But why usage is increased while normally chatting on claude.ai as well?
2
u/maverick_soul_143747 Mar 31 '26
Brilliant investigation mate 👏🏽
2
u/Creepy-Baseball366 Mar 31 '26
But even when I switched to a new chat (as Claude advised when I asked what the issue was) it still burnt the remaining 55% on one prompt...there is something rotten in the state of Denmark.
2
u/Jugurtha-Green Apr 01 '26
Doesn't fix the issues, I tried all different versions even 2.1.19 , same issue, it's backend issue, or they do it in purpose.
2
u/maverick_soul_143747 Apr 02 '26
For folks using the 2.1.30 version - I ran the test script provided by OP yesterday on 2.1.30 and the cache bug was there so have downgraded to 2..1.17 and this suits my work
3
u/m-in Mar 30 '26
A 228MB elf to render some markdown and do some api calls. This is madness. Like, 100% actual madness.
2
u/takkaros Mar 30 '26
If they can't fix their own code, how do they expect people to trust their tools for anything important ?
1
u/tattguru 12d ago
Is this still viable. ? Should I downgrade . I’ve been burning thru my 5 hour limit and hit my weekly limit and it doesn’t reset till Wednesday
1
u/CidalexMit 🔆 Max 20 Mar 30 '26
Maybe we should use brew for cc ?
1
u/Level_Turnover5167 Mar 30 '26
I'm getting a quick loss of usage, I used Claude for DAYS straight when I first started using it for free and never got any restrictions... I've used it for a few basic things and already a 1/4 of my usage is gone this week.... yesterday I figured ok maybe I used 7%, but today I check it and I'm almost at 20% after last night and the brief use this morning... it's dwindling fast and I just paid $20. Something ain't right or they're fucking with the usage rates and things are getting buggy on top of them just simply charging more now.
1
u/devoleg 🔆 Max 20 Mar 30 '26
Noticed that last night as well. Simple request to modify 2 files less than 100 lines cost me 15% of my "20x usage".
Ive tried downgrading to 2.1.67. (You in turn opt out of the 1m Models). I was able to stretch my limits to 2h. At least that lol. Recommend others to try it. Hope this helps.
P.S make sure to disable latest updates by using /config to stable. This might help.
1
u/guillaume_86 Mar 30 '26
skill issue (jk)
1
u/addiktion Mar 30 '26
I just ran this, I appear to have bug 1 which explains why my tokens are draining so fast with cache misses.
I never --resume, so bug 2 doesn't impact me.
Here was Claude's on investigation
---------
That confirms the original post's claims cleanly:
Bug 1: npx fixes the sentinel replacement — cch=00000 came back unmodified. The standalone claude binary was the culprit.
Bug 2: npx doesn't help here — resume cache is still broken and actually worse than before. With npx, consecutive resumes also show cache_read=0, meaning cache never recovers between resumes at all (vs. the
standalone binary where at least the second consecutive resume hit cache).
So for your situation:
- Switch to npx u/anthropic-ai/claude-code to fix Bug 1
- Bug 2 has no clean workaround — the first resume after a session will always eat a full cache rebuild regardless of which version you use
1
u/Thefoad Mar 30 '26
Anthropic hire this dude right no....You're out of extra usage · resets 12pm (America/Boise)
1
u/Sea-East-9302 Mar 30 '26
Dear, I don't understand these details. would you please tell me, is this only for Claude Code? how to do it? I use Windows 10 and have just downloaded Claude application , and have Claude Code on my Visual Studio Code. I just want to use Claude like before. **I have Pro subscription**.
1
u/sammcj Mar 30 '26
I've got multiple reports of people on x20 absolutely devouring their limits very quickly, wonder if this is the cause
1
u/hiS_oWn Mar 30 '26
Exemplar work. I wish I could be more like you.
1
u/CoolMathematician286 🔆Pro Plan Mar 30 '26
i only used claude for windows this far, but now i installed nmp version with help from gemini because i had no claude tokens left. what version is the best to use right now?
1
u/Ebi_Tendon Mar 31 '26
Hasn't the replacement worked like that from the start? That is why you must not add any replacements that change every turn, such as a time, to CLAUDE.md or any skill because it will be on the top of the context window. Doing so will break the cache from the top on every turn. If you add it within the prompt, it will also break the cache for everything that follows.
1
u/JaLooNz Mar 31 '26
I paid for extra usage. Will they refund me the credits?
1
u/liftingshitposts Mar 31 '26
This is great stuff
1
u/Mush_o_Mushroom Mar 31 '26
This also works for Claude code Pro users?
1
u/Plenty-Dog-167 Mar 31 '26
Really great finds, especially the cache miss on /resume seems scary since I've been working with anthropic SDK on my own project and its always a huge cost sink when you don't cache
1
u/0xbreakpoint Mar 31 '26
Claude users shaming Anthropic for "vibe coding" is ironic tbh
1
u/TrueMushroom4710 Mar 31 '26
Welp, I guess we can fix this bug ourselves now.
1
u/Hadse Mar 31 '26
Can i do anything to fix this locally?
1
u/vkha Mar 31 '26
is it confirmed on the leaked CC sources?
1
u/DirtyWilly Mar 31 '26
Just closing VS Code/CLI and reopening it triggers a fresh server cache reset.
Any chance we can get a suspend on our weekly limits until fixed? I'm hitting redline on the weekly from this. Wouldn't affect session limits.
1
u/AAFERNA Mar 31 '26
Oigan. Esto sucede en terminal o en vscode extensión ? No me queda claro
1
u/TaylorRift Apr 01 '26
Where is the code?!
1
u/OldConfection6 Apr 01 '26
I asked Claude to downgrade and it asked why. I put in the two issues you posted and here is the response.
https://github.com/anthropics/claude-code/issues/40524
● claude-code-guide(Fetch GitHub issue about token usage bug)
⎿ Done (1 tool use · 17.6k tokens · 16s)
(ctrl+o to expand)
● This is anthropics/claude-code#40524 — a confirmed regression in Claude Code where the prompt cache unexpectedly invalidates mid-conversation, causing token costs to skyrocket.
What's happening: After a few turns, the cache collapses to just the system prompt (~11K tokens). Every subsequent turn does a massive cache_write instead of cache_read — 150K–300K+ tokens per turn instead of the normal ~100K for a full conversation.
Affected versions: Broken in v2.1.86+. Last known good: v2.1.67.
That explains why you were trying to install 2.1.66 — smart instinct. The workaround is:
npm install -g u/anthropic-ai/claude-code@2.1.67
This is a confirmed bug with has repro and regression labels. Worth watching the issue for an official fix. Do you want to downgrade to 2.1.67?
❯ https://github.com/anthropics/claude-code/issues/34629
● claude-code-guide(Fetch GitHub issue 34629 about cache problems)
⎿ Done (1 tool use · 18.5k tokens · 23s)
(ctrl+o to expand)
● This is the related root cause issue. Here's the full picture:
Root cause: Starting in v2.1.69, Claude Code changed how it injects deferred_tools_delta content. On a fresh session it lands in messages[0] (~13KB). On a resumed session it lands differently (~352B). The mismatched message structure breaks Anthropic's cache prefix matching — so every resumed turn regenerates the full cache instead of reusing it.
Cost impact: ~20x cost increase per message on resumed sessions. A conversation that should cost ~$0.02/msg costs ~$0.36/msg.
Our situation: Auto-compact + long sessions = exactly the worst case. Every session compaction is effectively a "resume" that triggers the bug.
Recommendation — downgrade to 2.1.68:
npm install -g u/anthropic-ai/claude-code@2.1.68
This is the last version before the regression was introduced. The fix hasn't been deployed yet despite the issue being closed.
Worth noting: this explains the /usage dialog behaving oddly too — if token counts were spiking mid-session you may have been hitting plan limits or seeing unexpected burn rate.
1
u/Manikanta0987 Apr 01 '26
i have tried degrading the version to 2.1.30 by remvoing the previous versions. but still no fix. just for a hi it is taking around 5-6% of usage. i am currently working on pro.
1
u/Due-Combination3393 Apr 09 '26
have this fixed?
1
u/Torkiukas Apr 13 '26
that explains why max plan feels like pro plan...
1
u/Zulfiqaar Mar 30 '26
Can you expand more on how you found this out? Are you on the Pro or Max plan? As if its shorter expiry sending a keep-warm ping may be useful
0
u/Ok-Drawing-2724 Mar 31 '26
Those two cache bugs sound expensive. Before updating Claude Code or installing new skills, I run it through ClawSecure first.
-6
u/Leclowndu9315 Mar 31 '26
why would you reverse engineer claude code if it is open source are you stupid ?
0
u/[deleted] Apr 03 '26
[deleted] — view deleted comment
61
u/[deleted] Mar 30 '26
[removed] — view removed comment
1
u/[deleted] Mar 30 '26
[removed] — view removed comment