r/ClaudeCode • u/Global_Knee5354 • 2d 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?
•
u/AutoModerator 2d 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.
16
u/Client_Hello 2d 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?
2
u/ComingDeveloper 2d 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/245806 2d ago
just never close your laptop
1
u/seanlabor 2d ago
If you really need it longer. Create a pinger to keep it warm
2
u/t1nkl 2d ago edited 2d 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 2d 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 (
2xinput rate on 1-hour TTL, vs1.25xon 5-minute TTL and0.1xon cache reads) across everything still in the prefix. Three practical ways to shrink that cold-rebuild hit:1. Run
/compactbefore a break or near the quota wallCompacting 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.mdand.mcp.json)Every cold write re-caches your root
CLAUDE.md, rules files, and active MCP tool schemas. Disabling unused MCP servers via/mcpkeeps the baseline prefix lean when you resume.3. Check actual cache write vs read tokens locally
You can inspect the session
.jsonllogs under~/.claude/projects/forcache_creation_input_tokensandcache_read_input_tokensto see how much of the post-reset spike is conversation history versus tool schemas.1
u/lgmarian 2d ago
You risk losing some context regardless, as it grows larger. AI is amazing, but it's not infinite.
1
u/UnseenData 2d 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 2d 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.
1
u/GnistAI 2d ago
The API default is 5 min. The fact that Claude has 60 min is comparatively generous.
1
u/holyknight00 2d ago
it is just absurdly expensive to keep big context wasting ram for hours. I think at least they should provide longer ttl for smaller contexts.
1
u/AgentYurt 2d ago
Same frustration here. The thing that changed it for me was giving up on keeping the whole session warm and instead deciding what actually has to survive a cold resume: what we're doing, the one or two don't-touch constraints, and the last thing that was actually verified. I keep those three lines in a short file in the repo and restate them when I start a new session. The cache expiring then costs tokens, not the decisions — and a handoff written that way survives a resume, because it doesn't depend on the chat still being there.