{"i":19,"study":{"slug":"prompt-cache-across-sessions","title":"Does a new Claude Code session reuse the prompt cache of an earlier one?","seoTitle":"Claude Code prompt caching across sessions, tested","description":"30 calls: later Claude Code sessions showed near-full turn-1 cache reads with a fixed folder, but not with new folders in this sample. Codex CLI tested too.","question":"In the earlier caching study, a new Claude Code session did not read the cache that an earlier session wrote. Does a fixed working folder change that, and does putting the ledger in the system prompt help?","answer":"Later Claude Code sessions showed near-full turn-1 cache reads with a fixed folder. Setup A (new folder): 0 of 2 met the 50% rule, with a 95% interval of 0% to 66%. Setup B (fixed folder): 2 of 2, with a 95% interval of 34% to 100%. Setup C (fixed folder): 2 of 2, with a 95% interval of 34% to 100%. The per-setup intervals overlap. Later A sessions read 1,463 tokens and wrote 6,386 to 6,388 tokens. Later B sessions read 7,833 tokens and wrote 0 tokens. Later C sessions read 7,815 tokens and wrote 0 tokens. We interpret A’s reads as a shared CLI prefix. No token-level trace tests this reading. A post-hoc calculation pools both studies. New folder: 0 of 6, with a 95% interval of 0% to 39%. Fixed folder: 4 of 4, with a 95% interval of 51% to 100%. These intervals do not overlap. The earlier sessions used another login, ledger and turn count, with interleaved models. This pool is a rough check, not a controlled comparison. Mean later-session turn-1 cost at list price was $0.0259 in A and $0.0016 across B and C (calculation). The ratio is 16.2 (calculation). The cost stats show n and ranges. These are subscription calls, not bills. Turn-1 times do not isolate a cache effect. Each setup has n = 3 sessions. A: median 1.56 s, range 1.34 s to 1.62 s. B: median 1.76 s, range 1.71 s to 1.86 s. C: median 1.77 s, range 1.69 s to 1.78 s. Ranges are not confidence intervals. Codex turn-1 cached input ranged from 0 to 8,960 tokens across 6 calls. Its highest read share was 56% (calculation). The 50% rule counts 2 of 4 later sessions, with a 95% interval of 15% to 85%. The post-hoc 90% rule counts 0 of 4, with a 95% interval of 0% to 49%. Neither rule proves which tokens came from the ledger. A and B differ in folder, ledger seed and call order. These observations do not show that a fixed folder is necessary or that the folder caused the difference. The surviving protocol file dates from after the calls. Treat this analysis as exploratory.","date":"2026-10-07","updated":"2026-10-07","tags":["prompt-caching","cache-reuse","claude-code","codex-cli","claude-sonnet","gpt-6-1-sol","working-folder","calculation"],"caveats":["The surviving protocol file was created after all counted calls. Its claimed 00:32 UTC declaration is not supported by its file birth time. Amendment 1 and 2 state 00:36 and 00:37 UTC, but separate pre-edit copies do not verify those times. The current summary was regenerated at 07:41 UTC. Treat the analysis as exploratory.","The synthetic ledger and short lookup questions reuse a designed task shape from the earlier study. All 30 answers passed after text normalization (95% interval 89% to 100%), so correctness hits a ceiling. This is a cache-counter probe, not evidence about coding quality or general task success.","The protocol gives conflicting Codex entry gates: 30% weekly allowance remaining for the optional half, but 20% before the batch. The gate script enforces 20%. No retained gate receipt proves the allowance at run time. Call caps were kept: 18 Claude calls and 12 Codex calls, plus one probe each.","The sample is small: 2 later sessions per setup and route. A count of 2 of 2 has a 95% interval of 34% to 100%, so the per-setup counts alone do not separate the setups. The token counts were stable: every later session in A read the same 1,463 tokens, and later sessions in B read 7,833 tokens each and those in C read 7,815 each. The pooled comparison across both studies is post hoc.","The 4 earlier sessions in the pooled new-folder count differ from this study's sessions. They ran under a different Claude login, with another ledger and 5 turns per session. Sonnet and Opus sessions ran interleaved, so same-model sessions were 13 to 27 seconds apart (calculation from the recorded call times), not under 1 second. The pooled counts are a rough check, not a controlled comparison.","Consecutive sessions of the same setup ran less than one second apart. The cache entries were 1-hour writes. This run says nothing about reuse after a longer gap or after an entry expires.","A and B differ in working folder, ledger seed and call order. We did not test whether the folder path, its name or another property of a new empty folder breaks the match. The CLI documents an option that moves its per-machine system-prompt sections (the working folder is one) into the first user message. We did not test it.","Setup C ran only with a fixed folder. We did not test whether a ledger in the system prompt protects the cache against a changing folder.","Tools were off and the working folder was empty. A real repository adds other session-specific text (for example git state). We did not test that.","Total turn-1 Claude input, including the ledger, is about 7.8k tokens. We interpret the 1,463 reads in later A sessions as the shared CLI prefix; this was not tested. We tested one CLI version and one model per route: Claude Code 2.1.286 with Sonnet 5.5, and Codex CLI 0.160.0 with GPT-6.1 Sol. Larger rewritten inputs cost more at these list prices (calculation); this does not predict another workload’s cache use.","Codex CLI reports no cache-write count and has a large system prompt of its own. Its turn-1 cached counts varied from 0 to 8,960 in each setup. Neither setup reached the post-hoc 90% threshold. The small sample cannot show that folders never matter. We did not test why. Do not rank Codex against Claude on these numbers.","The Codex criterion for a full read (90% or more of its input) was set after we saw the Codex counts (Amendment 1). Under the 50% threshold we recorded in the protocol, 2 of 4 later Codex sessions would count (8,960 tokens cached in each, the count the Codex probe call showed, which we read as the Codex system prefix). The 90% rule, set after we saw the counts, gives 0 of 4. Their Wilson 95% intervals are 15% to 85% and 0% to 49%, respectively.","Costs are list-price calculations. The calls used flat subscriptions. Turn times come from a Mac that also ran other agent work, so contention can add noise."],"sourceIds":["agent-cache-sessions","calc-cache-pricing","price-anthropic","agent-caching-consistency"],"hero":{"statIds":["cache-sessions-later-reuse-a","cache-sessions-later-reuse-b"]},"stats":{"$k":["id","label","value","unit","display","n","ci","note"],"$r":[["cache-sessions-later-reuse-a","Later sessions with at least 50% of turn-1 input cached, A: new folder each time",0,"rate","0 of 2 (95% interval 0% to 66%)",2,[0,0.6576],"Claude Sonnet 5.5 in Claude Code. A later session is session 2 or 3. Reused = turn-1 read share of 0.5 or more. The surviving protocol records this rule but dates from after the calls. No token-level trace identifies the ledger."],["cache-sessions-later-reuse-b","Later sessions with at least 50% of turn-1 input cached, B: fixed folder",1,"rate","2 of 2 (95% interval 34% to 100%)",2,[0.3424,1],"Claude Sonnet 5.5 in Claude Code. A later session is session 2 or 3. Reused = turn-1 read share of 0.5 or more. The surviving protocol records this rule but dates from after the calls. No token-level trace identifies the ledger."],["cache-sessions-later-reuse-c","Later sessions with at least 50% of turn-1 input cached, C: fixed folder, ledger in system prompt",1,"rate","2 of 2 (95% interval 34% to 100%)",2,[0.3424,1],"Claude Sonnet 5.5 in Claude Code. A later session is session 2 or 3. Reused = turn-1 read share of 0.5 or more. The surviving protocol records this rule but dates from after the calls. No token-level trace identifies the ledger."],["cache-sessions-pooled-new-folder","Later sessions with at least 50% of turn-1 input cached, new folders, pooled across studies",0,"rate","0 of 6 (95% interval 0% to 39%)",6,[0,0.3903],"Calculation, post hoc (Amendment 2): this study’s setup A plus the earlier study’s 4 later Claude Code sessions (2 Sonnet, 2 Opus; 5 turns per session; another ledger). The 4 earlier sessions ran under a different Claude login, with Sonnet and Opus sessions interleaved: 13 to 27 seconds between a session’s last call and the next same-model session’s first call (calculation), against under 1 second here."],["cache-sessions-pooled-fixed-folder","Later sessions with at least 50% of turn-1 input cached, fixed folder, B and C pooled",1,"rate","4 of 4 (95% interval 51% to 100%)",4,[0.5101,1],"Calculation, post hoc (Amendment 2): setups B and C differ in where the ledger sits."],["cache-sessions-turn1-usd-new-folder","Turn-1 list-price cost of a later session, new folder each time (calculation)",0.025875,"usd","$0.0259",2,"\u0001","Mean of sessions 2 and 3, setup A; range $0.025871 to $0.025879. Calculation from recorded tokens and list prices; not a bill."],["cache-sessions-turn1-usd-fixed-folder","Turn-1 list-price cost of a later session, fixed folder (calculation)",0.001599,"usd","$0.0016",4,"\u0001","Mean of sessions 2 and 3 in setups B and C; range $0.001597 to $0.001601. Calculation from recorded tokens and list prices; not a bill."],["cache-sessions-turn1-cost-ratio","Turn-1 cost of a later session: new folder as a multiple of fixed folder (calculation)",16.18,"ratio","16.2×",6,"\u0001","Calculation. Turn-1 input here is about 7.8k tokens, including the ledger. A different workload can change both token use and cache matches."],["cache-sessions-codex-declared-threshold","Later Codex CLI sessions with at least 50% of turn-1 input cached (protocol threshold)",0.5,"rate","2 of 4 (95% interval 15% to 85%)",4,[0.15,0.85],"Counter threshold only. A prefix read can meet it; it does not prove that the ledger was read. The surviving protocol was created after the calls."],["cache-sessions-codex-later-reuse","Later Codex CLI sessions with at least 90% of turn-1 input cached (post-hoc rule) (setups A and B)",0,"rate","0 of 4 (95% interval 0% to 49%)",4,[0,0.4899],"GPT-6.1 Sol at medium effort. Reused = cached input of 90% or more of the input (Amendment 1, set after the counts were seen); the highest turn-1 cached share was 56%. Under the 50% threshold we recorded in the protocol, 2 of 4 later Codex sessions would count (8,960 tokens cached in each, the count the Codex probe call showed, which we read as the Codex system prefix). The 90% rule, set after we saw the counts, gives 0 of 4. Their Wilson 95% intervals are 15% to 85% and 0% to 49%, respectively."],["cache-sessions-calls","Counted calls in this study (every one counted)",30,"calls","30 (18 Claude Code, 12 Codex CLI), plus 2 uncounted probe calls","\u0001","\u0001","\u0001"]]},"charts":{"$k":["id","title","subtitle","kind","unit","polarity","xLabel","yLabel","series","note","sourceIds","whisker"],"$r":[["cache-sessions-turn1-read-share","Claude Sonnet 5.5 · Claude Code: share of turn-1 input read from the cache, by setup and session","One bar per call: turn 1 of one session; 3 sessions per setup, run back to back; read-share calculation","grouped-bar","rate","none","Setup","Input tokens read from cache",{"$k":["name","points"],"$r":[["Session 1 (first in its setup)",{"$k":["label","value","n"],"$r":[["A: new folder each time",0.0676,1],["B: fixed folder",0.1867,1],["C: fixed folder, ledger in system prompt",0.0691,1]]}],["Session 2",{"$k":["label","value","n"],"$r":[["A: new folder each time",0.1863,1],["B: fixed folder",0.9997,1],["C: fixed folder, ledger in system prompt",0.9997,1]]}],["Session 3",{"$k":["label","value","n"],"$r":[["A: new folder each time",0.1863,1],["B: fixed folder",0.9997,1],["C: fixed folder, ledger in system prompt",0.9997,1]]}]]},"Session 1 was the first session to use its setup’s ledger. Sessions 2 and 3 used that same ledger. Different seeds prevent full ledger-prefix reuse between setups; shared CLI-prefix reads remain possible. We interpret session-1 reads as a shared CLI prefix; no token-level trace proves this. Read share (calculation) = cache reads ÷ (uncached input + cache reads + cache writes), as the provider reports them. Each bar is one call, not a rate; the counts per setup are in the table. 2 later sessions per setup is a small number.",["agent-cache-sessions"],"\u0001"],["cache-sessions-turn1-cost","Claude Sonnet 5.5 · Claude Code: list-price cost of turn 1, by setup and session (calculation)","The recorded tokens of each call priced at list price; the last bar shows the mean of the 3 calls priced without any cache","grouped-bar","usd","\u0001","Setup","USD (list price)",{"$k":["name","points"],"$r":[["Session 1 (first in its setup)",{"$k":["label","value","n"],"$r":[["A: new folder each time",0.02942,1],["B: fixed folder",0.025807,1],["C: fixed folder, ledger in system prompt",0.029242,1]]}],["Session 2",{"$k":["label","value","n"],"$r":[["A: new folder each time",0.025871,1],["B: fixed folder",0.001601,1],["C: fixed folder, ledger in system prompt",0.001597,1]]}],["Session 3",{"$k":["label","value","n"],"$r":[["A: new folder each time",0.025879,1],["B: fixed folder",0.001601,1],["C: fixed folder, ledger in system prompt",0.001597,1]]}],["Same call without a cache (every input token at the input price)",{"$k":["label","value","n"],"$r":[["A: new folder each time",0.015735,3],["B: fixed folder",0.0157,3],["C: fixed folder, ledger in system prompt",0.015664,3]]}]]},"Calculation, not a bill: the calls ran on a subscription. Uncached input at the input price, cache reads at the cache-read price, 1-hour cache writes at 2× the input price (every write in this run was a 1-hour write); Sonnet 5.5 list prices, effective 2026-09-21. A write costs more than plain input, so a session that writes the ledger again costs more than no cache at all.",["agent-cache-sessions","calc-cache-pricing","price-anthropic"],"\u0001"],["cache-sessions-turn-time","Claude Sonnet 5.5 · Claude Code: time per turn, by setup","Median of 3 sessions; whiskers = fastest and slowest of the 3","dot-range","seconds","\u0001","\u0001","Seconds",[{"name":"Turn 1 (the ledger and question 1)","points":{"$k":["label","value","lo","hi","n"],"$r":[["A: new folder each time",1.56,1.34,1.62,3],["B: fixed folder",1.76,1.71,1.86,3],["C: fixed folder, ledger in system prompt",1.77,1.69,1.78,3]]}},{"name":"Turn 2 (question 2)","points":{"$k":["label","value","lo","hi","n"],"$r":[["A: new folder each time",1.02,0.88,1.14,3],["B: fixed folder",1.33,1.31,1.37,3],["C: fixed folder, ledger in system prompt",1.13,1.09,1.29,3]]}}],"Whiskers are a range (fastest and slowest of 3 sessions), not a confidence interval. Turn 2 read the cache in every setup. This design does not isolate a cache effect on speed. Ledger seed and call order also differ. The Mac also ran other agent work during these calls.",["agent-cache-sessions"],"minmax"],["cache-sessions-codex-turn1-cached","GPT-6.1 Sol (medium) · Codex CLI: cached input tokens on turn 1, by setup and session","Turn-1 input was about 16,042 tokens in every call","grouped-bar","tokens","\u0001","Setup","Cached input tokens",{"$k":["name","points"],"$r":[["Session 1 (first in its setup)",[{"label":"A: new folder each time","value":4864,"n":1},{"label":"B: fixed folder","value":0,"n":1}]],["Session 2",[{"label":"A: new folder each time","value":8960,"n":1},{"label":"B: fixed folder","value":8960,"n":1}]],["Session 3",[{"label":"A: new folder each time","value":0,"n":1},{"label":"B: fixed folder","value":0,"n":1}]]]},"Cached input as the Codex app-server reports it (input includes the cached tokens; it reports no cache writes). Codex sends a large system prompt of its own, so a cached count of about 9,000 can come from that prefix alone. Each bar is one call. Not comparable with the Claude Code bars: different prefix, different cache.",["agent-cache-sessions"],"\u0001"]]},"related":["caching-consistency"]}}