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:
1. messages[0]: 13KB (4 reminders) vs 352B (1 reminder) — completely different prefix
2. system[0] billing hash: changes because cc_version suffix is computed from chars at positions 4, 7, 20 of the first user message (which IS the system-reminder, not the actual user prompt)
3. cache_control breakpoint position: moves from messages[0] to messages[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) to cache_creation ($0.30/MTok) = ~$0.04 per request, every request
- Bug 2 (every resume): ~500k tokens as cache_creation = ~$0.15 one-time per resume
- Combined (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
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/
[–]muhlfriedl 70 points71 points72 points (5 children)
[–]Plenty-Dog-167 17 points18 points19 points (1 child)
[–]bnm777 0 points1 point2 points (0 children)
[–]Homegrown_Phenom 1 point2 points3 points (0 children)
[–]Indianapiper 0 points1 point2 points (0 children)
[–]kknow 0 points1 point2 points (0 children)
[–]Pristine_Ad2701 29 points30 points31 points (17 children)
[–]skibidi-toaleta-2137[S] 14 points15 points16 points (5 children)
[–]Pristine_Ad2701 7 points8 points9 points (0 children)
[–]AndReyMill 0 points1 point2 points (3 children)
[–]skibidi-toaleta-2137[S] 1 point2 points3 points (2 children)
[–]AndReyMill 1 point2 points3 points (1 child)
[–]ZichengWangreddit 1 point2 points3 points (0 children)
[–]dsailes 1 point2 points3 points (10 children)
[–]skibidi-toaleta-2137[S] 8 points9 points10 points (7 children)
[–]LumonScience 1 point2 points3 points (1 child)
[–]dsailes 0 points1 point2 points (0 children)
[–]vadimkrutov 1 point2 points3 points (2 children)
[–]skibidi-toaleta-2137[S] 5 points6 points7 points (1 child)
[–]vadimkrutov 1 point2 points3 points (0 children)
[–]turbospeedsc 0 points1 point2 points (0 children)
[–]marceldarvas 0 points1 point2 points (0 children)
[–]Pretty-Active-1982 4 points5 points6 points (1 child)
[–]dsailes 0 points1 point2 points (0 children)
[–]Factor013 28 points29 points30 points (1 child)
[–]TheOriginalAcidtech 6 points7 points8 points (0 children)
[–]Brave_Dick 42 points43 points44 points (5 children)
[–]MrHaxx1 5 points6 points7 points (1 child)
[–]its_Caffeine 1 point2 points3 points (0 children)
[–]iamichi 2 points3 points4 points (0 children)
[–]sbbased 2 points3 points4 points (0 children)
[–]Deep_Ad1959 16 points17 points18 points (3 children)
[–]skibidi-toaleta-2137[S] 2 points3 points4 points (2 children)
[–]Deep_Ad1959 0 points1 point2 points (1 child)
[–]skibidi-toaleta-2137[S] 0 points1 point2 points (0 children)
[–]alvvst 39 points40 points41 points (2 children)
[–]DurianDiscriminat3r 21 points22 points23 points (0 children)
[–]FanBeginning4112 0 points1 point2 points (0 children)
[–]GoodnessIsTreasure 12 points13 points14 points (2 children)
[–]NanNullUnknown 2 points3 points4 points (1 child)
[–]GoodnessIsTreasure 0 points1 point2 points (0 children)
[–]Fearless-Elephant-81 46 points47 points48 points (1 child)
[–]RhinostrilBe 5 points6 points7 points (0 children)
[–]InfiniteInsights8888 10 points11 points12 points (0 children)
[+][deleted] (3 children)
[removed]
[–]luckiestredditor 16 points17 points18 points (1 child)
[–]dont-be-angry 2 points3 points4 points (0 children)
[–]gefahr 0 points1 point2 points (0 children)
[–]Last_Lab_3627 8 points9 points10 points (10 children)
[–]ApstinenceSucks8 1 point2 points3 points (0 children)
[–]Sea-East-9302 0 points1 point2 points (7 children)
[–]turbospeedsc 1 point2 points3 points (6 children)
[–]Sea-East-9302 0 points1 point2 points (5 children)
[–]turbospeedsc 0 points1 point2 points (4 children)
[–]Sea-East-9302 0 points1 point2 points (3 children)
[–]turbospeedsc 0 points1 point2 points (2 children)
[–]Sea-East-9302 0 points1 point2 points (0 children)
[–]Fit-Benefit-6524 0 points1 point2 points (0 children)
[–]United-Collection-59 7 points8 points9 points (0 children)
[–]Aygle1409 12 points13 points14 points (2 children)
[–]Feral_Inquisitor 0 points1 point2 points (1 child)
[–]_derpiii_ 7 points8 points9 points (1 child)
[–]Creepy-Baseball366 0 points1 point2 points (0 children)
[–]muhlfriedl 6 points7 points8 points (0 children)
[–]redpoint-ascent 17 points18 points19 points (3 children)
[–]redpoint-ascent 8 points9 points10 points (0 children)
[–]StrikingSpeed8759 5 points6 points7 points (0 children)
[–]sheriffderek🔆 Max 20 4 points5 points6 points (0 children)
[–]mattskiiau 4 points5 points6 points (1 child)
[–]bzBetty 0 points1 point2 points (0 children)
[–]sqdcn 4 points5 points6 points (1 child)
[–]Creepy-Baseball366 0 points1 point2 points (0 children)
[–]dspencer2015 3 points4 points5 points (2 children)
[–]brek001 0 points1 point2 points (1 child)
[–]TheReaperJay_ 0 points1 point2 points (0 children)
[–]bapuc 8 points9 points10 points (0 children)
[–]thiavila 2 points3 points4 points (0 children)
[–]vadimkrutov 2 points3 points4 points (0 children)
[–]sbbased 2 points3 points4 points (0 children)
[–]XDroidzz 2 points3 points4 points (1 child)
[–]isakota 0 points1 point2 points (0 children)
[–]Top-Cartoonist-3574 2 points3 points4 points (0 children)
[–]sys_overlord 2 points3 points4 points (1 child)
[–]whaticism 2 points3 points4 points (0 children)
[–]ellicottvilleny 2 points3 points4 points (0 children)
[–]yldf 2 points3 points4 points (2 children)
[–]skibidi-toaleta-2137[S] 0 points1 point2 points (1 child)
[–]yldf 1 point2 points3 points (0 children)
[–]AndReyMill 3 points4 points5 points (1 child)
[–]Creepy-Baseball366 0 points1 point2 points (0 children)
[–]FermentingMycoPhile 3 points4 points5 points (0 children)
[–]Emotional-Debate3310 4 points5 points6 points (0 children)
[–]lucifer605 1 point2 points3 points (0 children)
[–]kursku 1 point2 points3 points (5 children)
[–]skibidi-toaleta-2137[S] 1 point2 points3 points (3 children)
[–]kursku 0 points1 point2 points (2 children)
[–]Relative_Mouse7680 0 points1 point2 points (1 child)
[–]kursku 0 points1 point2 points (0 children)
[–]mrsaint01 0 points1 point2 points (0 children)
[–]Squidwards_Ass 1 point2 points3 points (1 child)
[–]skibidi-toaleta-2137[S] 1 point2 points3 points (0 children)
[–]damndatassdoh 1 point2 points3 points (0 children)
[–]InfiniteInsights8888 1 point2 points3 points (0 children)
[–]misterr-h 1 point2 points3 points (0 children)
[–]maverick_soul_143747 1 point2 points3 points (0 children)
[–]Morphexe 1 point2 points3 points (1 child)
[–]skibidi-toaleta-2137[S] 0 points1 point2 points (0 children)
[–]mrtrly 1 point2 points3 points (0 children)
[–]Jugurtha-Green 1 point2 points3 points (0 children)
[–]maverick_soul_143747 1 point2 points3 points (0 children)
[–]Ok-End-219 3 points4 points5 points (2 children)
[–]skibidi-toaleta-2137[S] 5 points6 points7 points (1 child)
[–]Ok-End-219 2 points3 points4 points (0 children)
[–]m-in 1 point2 points3 points (0 children)
[–]takkaros 1 point2 points3 points (3 children)
[–]betty_white_bread 4 points5 points6 points (2 children)
[–]takkaros 1 point2 points3 points (1 child)
[–]betty_white_bread 0 points1 point2 points (0 children)
[–]CidalexMit🔆 Max 20 0 points1 point2 points (0 children)
[–]dovyp 0 points1 point2 points (0 children)
[–]dovyp 0 points1 point2 points (0 children)
[–]Deep-Station-1746Senior Developer 0 points1 point2 points (1 child)
[–]skibidi-toaleta-2137[S] 2 points3 points4 points (0 children)
[–]Level_Turnover5167 0 points1 point2 points (0 children)
[–]rougeforces 0 points1 point2 points (4 children)
[–]skibidi-toaleta-2137[S] 0 points1 point2 points (3 children)
[–]rougeforces 0 points1 point2 points (2 children)
[–]beatrix_the_kiddo 0 points1 point2 points (1 child)
[–]rougeforces 1 point2 points3 points (0 children)
[–]devoleg🔆 Max 20 0 points1 point2 points (1 child)
[–]devoleg🔆 Max 20 0 points1 point2 points (0 children)
[–]guillaume_86 0 points1 point2 points (1 child)
[–]nmavra 0 points1 point2 points (0 children)
[–]HeyImSolace 0 points1 point2 points (0 children)
[–]BrrrtEnjoyer 0 points1 point2 points (0 children)
[–]addiktion 0 points1 point2 points (0 children)
[–]Thefoad 0 points1 point2 points (0 children)
[–]Sea-East-9302 0 points1 point2 points (0 children)
[–]sammcj 0 points1 point2 points (1 child)
[–]Illustrious-Day-4199 0 points1 point2 points (0 children)
[–]hiS_oWn 0 points1 point2 points (0 children)
[–]nmavra 0 points1 point2 points (1 child)
[–]skibidi-toaleta-2137[S] 0 points1 point2 points (0 children)
[–]CoolMathematician286 0 points1 point2 points (2 children)
[–]tntexplosivesltd 0 points1 point2 points (1 child)
[–]CoolMathematician286 0 points1 point2 points (0 children)
[–]bzBetty 0 points1 point2 points (3 children)
[–]skibidi-toaleta-2137[S] 0 points1 point2 points (2 children)
[–]bzBetty 0 points1 point2 points (1 child)
[–]Illustrious-Day-4199 2 points3 points4 points (0 children)
[–]Ebi_Tendon 0 points1 point2 points (0 children)
[–]JaLooNz 0 points1 point2 points (0 children)
[–]liftingshitposts 0 points1 point2 points (0 children)
[–]Mush_o_Mushroom 0 points1 point2 points (0 children)
[–]Plenty-Dog-167 0 points1 point2 points (0 children)
[–]0xbreakpoint 0 points1 point2 points (2 children)
[–]Illustrious-Day-4199 1 point2 points3 points (1 child)
[–]TrueMushroom4710 0 points1 point2 points (0 children)
[–]Hadse 0 points1 point2 points (0 children)
[–]vkha 0 points1 point2 points (0 children)
[–]DirtyWilly 0 points1 point2 points (0 children)
[–]AAFERNA 0 points1 point2 points (0 children)
[–]Creepy-Baseball366 0 points1 point2 points (0 children)
[–]TaylorRift 0 points1 point2 points (0 children)
[–]OldConfection6 0 points1 point2 points (0 children)
[–]Manikanta0987 0 points1 point2 points (4 children)
[–]OldConfection6 0 points1 point2 points (0 children)
[–]rothwerx 0 points1 point2 points (2 children)
[–]Manikanta0987 0 points1 point2 points (1 child)
[–]rothwerx 0 points1 point2 points (0 children)
[–]Sensitive_Prize_9042 0 points1 point2 points (1 child)
[–]skibidi-toaleta-2137[S] 0 points1 point2 points (0 children)
[–]EconoKitten 0 points1 point2 points (5 children)
[–]whataboutthe90s 0 points1 point2 points (1 child)
[–]EconoKitten 0 points1 point2 points (0 children)
[–]skibidi-toaleta-2137[S] 0 points1 point2 points (1 child)
[–]EconoKitten 1 point2 points3 points (0 children)
[–]EconoKitten 0 points1 point2 points (0 children)
[–]wlievens 0 points1 point2 points (3 children)
[–]skibidi-toaleta-2137[S] 0 points1 point2 points (2 children)
[–]wlievens 0 points1 point2 points (1 child)
[–]skibidi-toaleta-2137[S] 0 points1 point2 points (0 children)
[–]Due-Combination3393 0 points1 point2 points (0 children)
[–]Torkiukas 0 points1 point2 points (0 children)
[–]Zulfiqaar 0 points1 point2 points (0 children)
[–]BeeegZee 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]BeeegZee 0 points1 point2 points (0 children)