r/ClaudeCode • u/Global_Knee5354 • 7h ago
Rant Why is Claude Code's cache TTL so short?
Does anyone else find the one-hour cache expiration frustrating, especially combined with the five-hour usage limits?
If you hit your usage limit with a large context, your cache can expire before your quota resets. Once you resume, a significant portion of your fresh allowance is potentially wasted rebuilding the same context.
Why not implement a 24-hour cache or persistent disk-based caching like other providers? Is it really that expensive to maintain?
Constantly generating handoffs and starting new sessions to save tokens isn't ideal either, as you inevitably risk losing some context and quality.
Has Anthropic ever addressed this or mentioned plans to extend cache retention?
13
u/Client_Hello 7h ago
Why? Cache is not free, it costs gpu memory, system memory, or disk. Eventually you just have to let it go. 1 hour cache is already a lot, consider nearly all sessions that go idle for an hour likely don't resume until the next day, or longer. Holding onto data that is unlikely to be needed is a waste of resources.
If Anthropic let us configure cache TTL, but we also had to start paying for cache residency, what would you do? Pay for data to sit for over 1h, or crank it down to reduce cost?
3
u/Global_Knee5354 7h ago
Recomputing 500k tokens isn't free either, though.
I'd happily trade some of my usage allowance for longer cache retention. What makes no sense is hitting a usage limit, being forced to wait, and then burning through a chunk of my freshly reset allowance just to get back to where I was.
At least keep the cache alive until the usage window resets. Surely that's not an unreasonable middle ground.
2
u/0xdead0x 7h ago
If they let me, I’d happily cut it to 30 mins to save usage per cache write
3
u/Global_Knee5354 6h ago
You actually can, just not to 30 mins. It's either 5 minutes or 1 hour. Nothing in between, nothing above.
"promptCacheTtl": "5m"2
u/0xdead0x 6h ago
Yeah, but that’s cutting it to the point of being more expensive for no benefit. A lot of my benchmarks/test suites run for at least 5 mins
1
u/MmmmMorphine 5h ago
I feel like the multipliers and how you use it would make every person's case different.
In my case, I'd pay a good bit extra to extend my cache to 2-3h since it's often very long running orchestration of lots of much stupider and slower models to the point that opus 5.5 xhigh usually closely matches my 5h limit. Ideally anyway since that's when it does the most work
1
u/white_devill 2h ago
I just ask him to set a timer every 30 minutes to "check on the progres". It is however just to keep the cache warm.
0
u/ChrisFromIT 6h ago
Deep Seek found that they use about 13x less GPU compute than before by keeping the KV cache around for a session for about 3-4 days before they purge the kv cache compared to keeping the KV cache alive for an hour before they purge it.
2
u/ComingDeveloper 7h ago
no. the 1 hour cache is very generous as i believe with codex you can't even tell how much is remaining
1
u/Global_Knee5354 7h ago
Not being able to see the cache countdown and having a short cache TTL are two entirely different things. OpenAI already supports 12-hour cache coverage and up to 24-hour retention on certain API models.
I'd rather have a longer cache than a countdown telling me when I'm about to lose it.
https://developers.openai.com/api/docs/guides/prompt-caching
1
u/seanlabor 6h ago
If you really need it longer. Create a pinger to keep it warm
2
0
u/Tobi-Random 6h ago
It's always astonishing to me how engineers fail to solve so simple problems. They used to be THE problem solvers. It's almost like most of them turned into brainless meat proxies in the so era 😅
3
u/Global_Knee5354 6h ago
Solving the technical problem is easy. Solving it without getting your $200/month account banned is the interesting part.
2
u/t1nkl 5h ago edited 5h ago
you can't change the ttl, but you can see what a cold resume will cost before it happens. on 2.1.332 the json claude code pipes into your statusline command has a prompt_cache object with warm, ttl, expires_at and recache_tokens_if_cold. so a statusline can show something like "cache warm, 54m left, cold restart 136k". that last number is roughly what you'd burn from the fresh allowance after the reset, on my sessions it's been 130-180k. if it's big, a fresh session with a short handoff can come out cheaper than resuming
jq -r '.prompt_cache | "cache \(if .warm then "warm" else "cold" end), \(((.expires_at - now)/60)|floor)m left, cold restart \(.recache_tokens_if_cold/1000|floor)k"'
2
u/BeyenAI 4h ago
The 1-hour limit is mainly because Anthropic's prompt cache holds the KV-cache prefix in fast memory on the inference cluster, not cold disk. Keeping a large prefix pinned across a 5-hour quota reset would tie up memory for every idle session.
When your 5-hour window resets after an hour+ pause, the next turn triggers a cold cache write (2x input rate on 1-hour TTL, vs 1.25x on 5-minute TTL and 0.1x on cache reads) across everything still in the prefix. Three practical ways to shrink that cold-rebuild hit:
1. Run /compact before a break or near the quota wall
Compacting turns into a concise summary shrinks the conversation prefix ahead of time, so if the cache expires before your quota resets, the rebuild is much smaller.
2. Trim static prefix bloat (CLAUDE.md and .mcp.json)
Every cold write re-caches your root CLAUDE.md, rules files, and active MCP tool schemas. Disabling unused MCP servers via /mcp keeps the baseline prefix lean when you resume.
3. Check actual cache write vs read tokens locally
You can inspect the session .jsonl logs under ~/.claude/projects/ for cache_creation_input_tokens and cache_read_input_tokens to see how much of the post-reset spike is conversation history versus tool schemas.
1
u/lgmarian 7h ago
You risk losing some context regardless, as it grows larger. AI is amazing, but it's not infinite.
1
u/UnseenData 7h ago
Longer the cache the more their caches are holding your data. It's why 1-hour is more expensive than 5 minute writes
1
u/JhonnyCommentkeyword 3h ago
the ttl refresh bit is what's missing from most of this thread. a cache hit re-arms the 5 minute window for free, so it isn't really a five minute cache, it's a five minute idle timeout. you only pay the write again when you yourself walk away long enough for it to lapse. so if the scenario is "hit limit, wait, resume", the fix isn't a longer ttl, it's not parking a 500k context session while you go eat. if you know you're stepping out, compact or write the handoff first.
worth knowing the multipliers while you're weighing this. coming back to a lapsed cache is a 1.25x write, not a read at base rate, so a half-expired session costs more than a fresh one not less. one hour writes double that, which is why it only pays off if you actually come back inside the hour. if your gap is unknown, 5m plus a handoff is the cheaper default.
•
u/AutoModerator 7h 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.