●CC 2.1.331 — 2.1.331 adds an API connectivity check to claude doctor and fixes MCP tool calls hanging for up to 30 minutes●SONNET 4.5 — Sonnet 4.5 retires from the Claude API on 11/30, 6 days left. Move to claude-sonnet-5-5●OFFICE — Users report the Microsoft 365 add-in disappearing seconds after install on macOS●NEW — New: Count how many input tokens one more tool costs with count_tokens●GEMINI 2.5 — Using Gemini 2.5 alongside Claude? From 12/1 requests reroute to newer models, billed at their rates. 7 days left●WORKBENCH — Trying the API in Workbench for the first time? Check the billing pages before you start●CC 2.1.331 — 2.1.331 adds an API connectivity check to claude doctor and fixes MCP tool calls hanging for up to 30 minutes●SONNET 4.5 — Sonnet 4.5 retires from the Claude API on 11/30, 6 days left. Move to claude-sonnet-5-5●OFFICE — Users report the Microsoft 365 add-in disappearing seconds after install on macOS●NEW — New: Count how many input tokens one more tool costs with count_tokens●GEMINI 2.5 — Using Gemini 2.5 alongside Claude? From 12/1 requests reroute to newer models, billed at their rates. 7 days left●WORKBENCH — Trying the API in Workbench for the first time? Check the billing pages before you start
I decide the prompt cache TTL by where I come back to, not how long I was away
Claude Code v2.1.242 added promptCacheTtl and subagentPromptCacheTtl. Whether the one-hour cache pays off depends on returning to the same directory and the same git state, not on how long the break was. Here is the order I check things in.
Mornings in the iOS wallpaper app repo, afternoons on the web side, back into Xcode by evening. Running several products as an indie developer means moving between working directories many times a day. Every switch, Claude Code seemed to be re-reading the conversation from the top, and the waiting added up.
Claude Code v2.1.242 introduced two settings: promptCacheTtl and subagentPromptCacheTtl. They let you stretch the prompt cache lifetime from five minutes to one hour. My first reaction was that this would suit someone who steps away as often as I do.
Then I read the specification before writing the setting, and the deciding factor turned out not to be the length of the break. Whether the cache is still there when you return depends less on how long you waited and more on where you return to. If the destination has changed, stretching the TTL buys you a cache that never gets read once.
Two knobs, two buckets
Claude Code does not let you place cache_control yourself. It decides both the position and the boundaries. What you get to set is the lifetime, for requests split into two fixed buckets.
Bucket
Requests it covers
Setting key
Main conversation
Interactive turns, non-interactive -p runs, Agent SDK turns, and the helpers that run inline with them
Both accept exactly two values, 5m and 1h. Anything else is ignored. Write 30m and it is not rejected with an error; it quietly falls back to the default. That quiet fallback matters later, so keep it in mind.
The defaults, meanwhile, depend on how you are billed. This table, and every version number and setting name in this piece, is what I checked against the official documentation as of November 2026.
Bucket
Claude subscription, within plan usage
Usage credits, API key, or cloud provider
Main conversation
One hour
Five minutes
Everything else
Five minutes, except a small set of server-controlled helper requests that get one hour
Five minutes
While you are on a subscription and inside your plan's included usage, the main conversation already runs on the one-hour cache. The moment you go over the limit and start drawing on usage credits, that usage is billed to you, so Claude Code drops back to the cheaper five-minute TTL. Sign in with an API key or go through a cloud provider and everything starts at five minutes.
So writing promptCacheTtl explicitly is worth doing in two situations: you are on an API key or a cloud provider, or you are on a subscription and want to keep the hour after passing your plan's limit. If you are comfortably inside your plan, setting "1h" changes nothing that was not already true.
Subagents start at five minutes no matter what you pay
This is where I tripped first. On a subscription, the main conversation is running on a one-hour cache. Call a subagent and that child lands in the five-minute bucket. Exactly when you fan work out in parallel, the side that would benefit most from a warm cache is the side that starts cold.
The reasoning makes sense once you read it. A subagent opens its own conversation with its own system prompt and tool set, separate from the parent's. The prefixes differ, so it cannot read the parent's cache at all. It warms one of its own across its turns instead.
A fork inverts this. A fork inherits the parent's system prompt, tools, and conversation history exactly, so its first request reads the parent's cache. Two ways of splitting work, and from the cache's point of view they are not the same thing. I wrote about their broader differences in branching cuts loose, delegation stays in the session, but the caching behaviour alone is enough to change the choice sometimes.
Does that mean you should set subagentPromptCacheTtl to "1h"? I do not. One-hour writes are billed at a higher rate than five-minute writes, and subagents are short-lived — most finish their job in a handful of turns. There is no reason to pay the expensive write for something that disappears before it can earn it back.
The one case that flips this is calling the same subagent definition repeatedly within an hour. Even then, you don't have to move the whole bucket. Since v2.1.248, a subagent's own definition file can set the lifetime for that one agent:
---name: repo-auditordescription: Audits a large repository and reports what it findsexperimental: cacheTtl: 1h---
cacheTtl has to live inside the experimental map; at the top level of the frontmatter it is simply not read. It accepts 5m or 1h, and while a subscription is drawing on usage credits, a 1h here is ignored too.
So my line is this: the one agent I call over and over gets the hour, everything else stays at five minutes. Setting subagentPromptCacheTtl to 1h would drag compaction and the short-lived helpers onto the expensive write as well. Which agent earns the exception is something I decide with the break-even formula further down.
✦
Thank you for reading this far.
Continue Reading
What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.
WHAT YOU'LL LEARN
✦You'll be able to tell, before flipping the switch, whether your own working rhythm can actually benefit from a one-hour cache
✦You'll understand why subagents and forks are treated differently by the cache, and pick the right one when you split work
✦You'll avoid the quiet days where a setting is in place but doing nothing, by checking precedence and unsupported environments up front
Secure payment via Stripe · Cancel anytime
✦
Unlock This Article
Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.
This is the finding that made me want to write the article.
Claude Code's cache is effectively scoped to one machine and one directory. The system prompt embeds the working directory, the platform, the shell, the OS version, and the auto memory paths. Different directory, different prefix. Different prefix, different cache.
Several consequences follow directly, and they hit daily work.
Two worktrees of the same repository do not read each other's cache. Each worktree is its own working directory
Sessions running in parallel in the same directory build matching prefixes and do read each other's cache
Sessions opened one after another in the same directory share a prefix only when the git status snapshot at startup matches, because the system prompt also captures the branch and recent commits
That third one caught me. On the web side, I add an article, commit, step away, and come back inside the hour. On the TTL clock, I made it. But the recent commits have changed, so the prefix the next session assembles is not the one I left. I bought a one-hour cache and then walked to an address that no longer exists.
Deciding "1h" from the length of my breaks had the order backwards. The first thing to look at is whether you return to the same directory in the same git state. If you do not, the extended TTL leaves nothing behind but the higher write rate.
How to structure the multi-repository work itself is a separate topic, and keeping the cache warm while moving between repositories goes into that. This article stays one step earlier, on the decision of whether to stretch at all.
Make the read-to-write balance visible
Before deciding anything, it helps to see where you currently stand. The API reports two token counts on every response, and a status line script can read them.
Field
Meaning
cache_creation_input_tokens
Tokens written to the cache this turn, billed at the cache write rate
cache_read_input_tokens
Tokens served from the cache this turn, billed at roughly 10% of the standard input rate
Save the script below as ~/.claude/cache-ratio.sh and make it executable. It prints the share of this turn's input that came from cache, plus how many tokens were read per token written.
#!/bin/bash# Claude Code status line: show the cache balance of the most recent API call.# The session JSON arrives on stdin.input=$(cat)MODEL=$(echo "$input" | jq -r '.model.display_name // "?"')# current_usage is null before the first API call of a session and right after# /compact. Without fallbacks, the arithmetic below dies on an empty string.READ=$(echo "$input" | jq -r '.context_window.current_usage.cache_read_input_tokens // 0')WRITE=$(echo "$input" | jq -r '.context_window.current_usage.cache_creation_input_tokens // 0')FRESH=$(echo "$input" | jq -r '.context_window.current_usage.input_tokens // 0')TOTAL=$((READ + WRITE + FRESH))if [ "$TOTAL" -eq 0 ]; then echo "[$MODEL] cache: --" exit 0fi# Share of this turn's input that came from cache, integer math only.HIT=$((READ * 100 / TOTAL))# Reads per token written, scaled by 10 to keep one decimal place.if [ "$WRITE" -gt 0 ]; then RATIO=$((READ * 10 / WRITE)) RATIO_STR="$((RATIO / 10)).$((RATIO % 10))x"else RATIO_STR="inf"fiecho "[$MODEL] cache ${HIT}% hit | read/write ${RATIO_STR} | fresh ${FRESH}"
Note that current_usage sits under context_window, not at the top level. Get that wrong and jq returns null silently, the fallbacks kick in, and you get cache: -- forever. A script that looks alive while reporting nothing is the worst failure mode of the three.
Test it with mock input before wiring it up. Here are four cases run locally.
$ echo '{"model":{"display_name":"Opus"},"context_window":{"current_usage":{"input_tokens":800,"output_tokens":1200,"cache_creation_input_tokens":5000,"cache_read_input_tokens":48000}}}' | ./cache-ratio.sh[Opus] cache 89% hit | read/write 9.6x | fresh 800# Right after the prefix broke$ echo '{"model":{"display_name":"Opus"},"context_window":{"current_usage":{"input_tokens":800,"output_tokens":1200,"cache_creation_input_tokens":52000,"cache_read_input_tokens":0}}}' | ./cache-ratio.sh[Opus] cache 0% hit | read/write 0.0x | fresh 800# current_usage is null (before the first API call, or just after /compact)$ echo '{"model":{"display_name":"Opus"},"context_window":{"current_usage":null}}' | ./cache-ratio.sh[Opus] cache: --# context_window missing entirely$ echo '{"model":{"display_name":"Sonnet"}}' | ./cache-ratio.sh[Sonnet] cache: --
The second case is the one to watch for. If turn after turn shows zero reads and large writes, the problem is not the lifetime — your prefix is changing every time, and no TTL will fix that.
Once the gap outlives the TTL, the cache becomes a surcharge
Here is where my prediction was exactly backwards.
Relative to the base input token price, five-minute writes cost 1.25x, one-hour writes cost 2x, and reads cost 0.1x. A write costing more than the base price means that a cache entry nobody reads is pure overhead.
I wanted to see how much overhead, so I put the published multipliers into a normalised model: an eight-turn session, a 40,000-token prefix at the start, and 1,500 tokens of growth per turn. These are computed figures from public rates, not a real invoice.
# Normalised so that one base input token = 1.0W5, W1H, READ = 1.25, 2.0, 0.1def session_cost(turns, gap_min, prefix0, delta, ttl_min, write_mult): """Total input cost for one session, assuming the conversation grows by delta per turn.""" prefix, total = prefix0, 0.0 for i in range(turns): warm = (i > 0) and (gap_min <= ttl_min) # within the TTL of the previous turn? if warm: total += READ * prefix + write_mult * delta # read the old part, write the increment else: total += write_mult * (prefix + delta) # rewrite the whole prefix prefix += delta return total
Varying only the gap between turns:
Gap between turns
No cache
5m TTL
1h TTL
Cheapest
2 minutes
374,000
97,200
136,200
5m
10 minutes
374,000
467,500
136,200
1h
45 minutes
374,000
467,500
136,200
1h
90 minutes
374,000
467,500
748,000
No cache
Look at the ten-minute row. The five-minute TTL costs 467,500 against 374,000 for no caching at all. The cache expires every five minutes, so every turn becomes a full rewrite, and every rewrite bills at 1.25x. A cache that is never read is exactly a 25% surcharge.
And five minutes is the default for the main conversation when you sign in with an API key. Anyone working in ten-minute bursts with breaks in between may be paying that 25% without noticing. My instinct that this setting would help me was right, but the reason was not that an hour is cheap. It was that five minutes was expensive.
The ninety-minute row twists once more. Stretching to an hour lands at twice the no-cache cost. When even an hour cannot bridge the gap, every turn is a 2x rewrite, so the longer lifetime sinks you further. A longer TTL is not a safer TTL.
The break-even is easy to state. With a write multiplier of W and reads at 0.1, a cache pays for itself after the smallest whole number of requests above (W − 0.1) ÷ 0.9. For five minutes that is 1.28, so the second request already wins. For one hour it is 2.11, so you wait until the third. A one-hour cache only earns its keep when the same prefix is read at least twice.
I would not jump from this table to turning caching off, though. The documentation recommends leaving it enabled for normal use, and caching buys latency as well as money. What I took from the exercise was not that caching is optional, but that a mismatch between your rhythm and your lifetime is expensive in a way that never announces itself. If you call the API directly and can place your own breakpoints, splitting the TTL into two tiers gives you far more room than these two keys do.
The order I check things in
Turning all of that into the sequence I actually use. Work down the list and stop at the first row that decides it.
#
What to check
What it settles
1
Are you on a subscription and inside your plan's usage?
If so, the main conversation is already on an hour. Nothing to write
2
When you resume, do you return to the same directory in the same git state?
If not, stay on 5m. A longer lifetime will never be read
3
Do gaps between turns exceed five minutes but stay under an hour?
If yes, 1h on the main conversation is worth it
4
Will the same prefix be read at least twice within that lifetime?
If not, only the higher write rate remains
5
Do you re-invoke the same subagent definition several times an hour?
If so, consider experimental.cacheTtl: 1h on that one definition. The bucket-wide subagentPromptCacheTtl is the last resort
Moving the second row near the top is the change I made. I used to start from the gap length in row three, and that produced a steady stream of decisions to stretch.
One more thing happens when you leave a long conversation idle on the one-hour TTL: Claude Code may compact it while you're away. If you come back to find the history replaced by a summary, that's why. To turn it off, set idleCompaction to false (v2.1.290 or later). Continuing from the summary means later requests stop carrying the whole history, so for very large conversations it can help more directly than any lifetime setting.
Clear the "set but not working" cases first
TTL values can arrive from several places, and most of the time a setting that appears to do nothing is simply losing to something above it. Claude Code takes the first match in this order:
FORCE_PROMPT_CACHING_5M=1, which forces five minutes for both buckets
The bucket's environment variable (CLAUDE_CODE_PROMPT_CACHE_TTL / CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL)
The bucket's setting key (promptCacheTtl / subagentPromptCacheTtl)
For subagent requests only, experimental.cacheTtl in the subagent's definition file (v2.1.248 or later)
ENABLE_PROMPT_CACHING_1H=1, which requests one hour for both buckets
The bucket's default
The setting key is third. If a stale value sits in managed settings or an environment variable, nothing you put in settings.json will reach the request. Read the other way round, FORCE_PROMPT_CACHING_5M=1 outranks everything, which makes it the right tool for comparing the two lifetimes or temporarily overriding a longer TTL pushed by managed settings.
Some environments cannot give you the hour at all.
Through a Claude apps gateway, your local settings alone won't get you the hour. An administrator has to request the one-hour TTL in the gateway policy
On Amazon Bedrock, caching support, the minimum cacheable prefix length, and one-hour TTL availability all vary by model. If your cache token counts stay at zero, check the supported models and regions first
Behind a custom ANTHROPIC_BASE_URL or an LLM gateway, whether caching works at all depends on the gateway. Part of the one-hour request travels in the anthropic-beta header, so check that the gateway forwards it unchanged
And the property from the opening comes back here. Only 5m and 1h are accepted; everything else is ignored. Write "60m" and you get no warning — it falls back to the default and keeps running. After changing the setting, judge it by whether the read-to-write ratio in your status line moved, not by what the file says. The file will happily tell you nothing is wrong.
Three windows for checking whether it worked
For a while I looked only at the read-to-write ratio and assumed I was on the hour. A good ratio can't tell you whether the writes behind it were five-minute or one-hour writes. These days I use three views, each for a different question.
The first answers "which lifetime did the write use?" directly. Non-interactive runs fall in the main-conversation bucket, so one run inside the repository you care about is enough.
# Did the main conversation's cache write use the 1h or the 5m lifetime?# (This costs one request.)claude -p "hello" --output-format json \ | jq -r '.usage.cache_creation | "1h=\(.ephemeral_1h_input_tokens // 0) 5m=\(.ephemeral_5m_input_tokens // 0)"'
One-hour writes show up under ephemeral_1h_input_tokens, five-minute writes under ephemeral_5m_input_tokens. Run it once after changing the setting and once more after removing a suspected environment variable, and you can tell which layer is actually winning.
The second is /usage. From v2.1.251, after the main conversation's first response, the Session block gains a Prompt cache (main) line with the session's hit ratio, miss count, and whether the cache is warm right now. From v2.1.260 it also names the likely cause of the last miss when it can, in the form likely cause: tool definitions changed. Knowing whether the miss right after a break was a tool change or something else is often enough to decide whether the TTL is even the suspect.
The third is the prompt_cache object passed to status line scripts, also from v2.1.251: ttl, warm, hit_ratio, misses, expires_at, and more. Where cache-ratio.sh reports this turn, this one reports the session so far and how long until the cache goes cold.
#!/bin/bash# Show TTL and time-to-cold from the prompt_cache object (v2.1.251+).# prompt_cache is absent until the first API response, so print -- then.input=$(cat)TTL=$(echo "$input" | jq -r '.prompt_cache.ttl // empty')if [ -z "$TTL" ]; then echo "cache: --" exit 0fiWARM=$(echo "$input" | jq -r '.prompt_cache.warm')HIT=$(echo "$input" | jq -r '(.prompt_cache.hit_ratio // 0) * 100 | floor')MISS=$(echo "$input" | jq -r '.prompt_cache.misses // 0')EXP=$(echo "$input" | jq -r '.prompt_cache.expires_at // empty')LEFT="cold"if [ -n "$EXP" ]; then SEC=$((EXP - $(date +%s))) [ "$SEC" -gt 0 ] && LEFT="$((SEC / 60))m"fiecho "ttl ${TTL} warm=${WARM} hit ${HIT}% miss ${MISS} left ${LEFT}"
I read warm without a // fallback on purpose. jq's // treats false as missing, so a fallback would quietly replace "cold" with whatever default you gave it. expires_at is null when the last response reported no cache tokens. Four mock inputs:
$ echo '{"prompt_cache":{"warm":true,"ttl":"1h","expires_at":'$(( $(date +%s) + 2520 ))',"misses":2,"hit_ratio":0.91}}' | ./pc-ttl.shttl 1h warm=true hit 91% miss 2 left 42m$ echo '{"prompt_cache":{"warm":false,"ttl":"5m","expires_at":null,"misses":5,"hit_ratio":0.42}}' | ./pc-ttl.shttl 5m warm=false hit 42% miss 5 left cold# Past expiry, hit_ratio still null$ echo '{"prompt_cache":{"warm":false,"ttl":"5m","expires_at":'$(( $(date +%s) - 60 ))',"misses":1,"hit_ratio":null}}' | ./pc-ttl.shttl 5m warm=false hit 0% miss 1 left cold# Before the first API response (no prompt_cache)$ echo '{"model":{"display_name":"Opus"}}' | ./pc-ttl.shcache: --
These statistics cover the main conversation only; subagent requests are not counted. To check a subagent's lifetime, you look at the usage of whatever invokes it separately, in the same spirit as the first window.
When the setting changes nothing: a lookup table
Here is everything above, arranged so you can start from the symptom. The rows run roughly from easiest to check to hardest.
Symptom
Likely cause
How to check
Fix
You set "1h", but writes land in ephemeral_5m_input_tokens
FORCE_PROMPT_CACHING_5M, an environment variable, or the managed-settings env block outranks you
env | grep -i PROMPT_CACH, the managed env block, then rerun claude -p "hello" --output-format json
Remove the higher-ranked value, or change it in the layer that wins
You wrote "60m" and nothing changed
Anything other than 5m or 1h is ignored without a warning
Read the value in settings.json
Write "1h"
After going over your plan's limit, misses climb every time you step away
On usage credits the main conversation drops to five minutes; a frontmatter 1h is ignored too
The Prompt cache (main) line in /usage, and prompt_cache.ttl
Set promptCacheTtl to "1h" explicitly if you want to keep the hour
Every return starts with a big write and zero reads
A commit or branch switch changed the git state, or you opened a different worktree
The likely cause in /usage; git log -1 and the working directory before and after the break
Leave the TTL alone. Make the checkpoint commit after you come back, not before you leave
Cache token counts stay at zero
Unsupported model or region on Bedrock, or a gateway stripping the cache markers
Is prompt_cache.caching_observedfalse?
Check model and region support; review the gateway's transformation settings
Through an LLM gateway it stays at five minutes
The anthropic-beta header isn't forwarded
The gateway's request-header settings
Forward that header unchanged
The fourth row is my own working pattern from the start of this piece. Commit before stepping away and the git state you return to is different, so the hour you paid for has nothing to read. Moving the checkpoint commit to after the break takes you out of that row without touching a single setting, which is why I'd try it before reaching for the TTL.
Three common misreadings
"Setting an hour can't hurt." It can. Per the official pricing, five-minute writes are 1.25 times base input, one-hour writes are 2 times, and reads are 0.1 times. As the 90-minute row above shows, when even an hour isn't long enough, the longer lifetime only sinks you deeper.
"On a subscription, everything gets the hour." Only the main conversation does, plus a small set of helper requests controlled server-side. Subagents, workflows, forks, and compaction start at five minutes.
"A worktree lets me run in parallel while borrowing the parent's cache." A worktree is a different working directory, so the prefixes don't match. The thing that reads the parent's cache from its first request is a fork.
The one thing to check first
Before adding a TTL setting, drop cache-ratio.sh in place and watch it for half a day. If reads sit at several times writes, your current configuration is already in step with how you work. If writes keep dominating, the thing to fix is not the lifetime but the prefix that keeps changing underneath it.
I had that order reversed myself and wrote the setting before looking at any numbers. Had I checked first, I would have found there was nothing to stretch. If this saves someone the same detour, that would make me glad.
Share
Thank You for Reading
Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.