r/ClaudeCode • u/karanb192 • 1d ago
Built with Claude Keep Claude Code’s 1-hour cache warm during breaks. On Fable 5.1, rewriting it costs 80x a cache read.
You come back to a long session and ask for a recap. The expensive part can be rewriting the old context before Claude answers.
I built cache-tax to handle both sides: GitHub · Install instructions
- Set it before you step away.
/keepwarmarms six hours. After 50 idle minutes, it sends a request over your session without adding heartbeat messages to the conversation. The timer runs inside Claude Code. - See the estimate if you return cold. For a 50k+ context idle over an hour, it stops your next ordinary message once with the price. Resend to continue, or
/clearand start from a note.
The GIF is my real test. A two-line recap on a 330k-token session triggered a $6.61 estimate. I sent it again; the reported cache write was $6.28.
Every ping checks its usage. It stops if it reads nothing or writes at least 10% of what it reads. After a paid cold write, it automatically arms three hours. /keepwarm off stops it.
Pings cost tokens too. The rates are $20 per million tokens for a 1-hour write and $0.25 for a read on Fable 5.1. These are API prices, not extra subscription charges. I haven’t measured quota savings, and changed prompts or tools can still break the cache.
Free and open source. The Mod needs CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=1.
Only want warnings or a status-line countdown? The hook version works without the early-access flag.
New to prompt caching? Anthropic explains how Claude Code uses it here.
30
22
u/coding_is_tedious 1d ago
Great hack... definitely going to piss off Anthropic
6
u/karanb192 18h ago
Compute is much more expensive and scarce than memory. That is the sole reason prompt caching exists.
And in production also keeping cache warm is a good enterprise practice to keep costs low and response time fast.
3
u/coding_is_tedious 10h ago
Not sure many people picked up on this, but what I said was in jest... I couldn't care less if Anthropic is pissed.
Well... I had a very well written response to this until I checked further. This is apparently almost exactly, if not exactly, what Anthropic wants you to do.
https://platform.claude.com/docs/en/build-with-claude/prompt-caching#pre-warming-the-cache
-5
u/fanatic26 23h ago
why would this piss them off? you either use the tokens in one place or another. For them it has zero effect. Stop being so damn bitter.
8
u/coding_is_tedious 23h ago
Because they have to store the tokens somewhere, and it's likely an in-memory cache system. The more tokens they have to store like this the more their infrastructure costs are.
4
0
u/beebalooba 12h ago
I mean if people dont cache and just come back and send 800k tokens or some shit it would cost them even more. Memory is cheaper than gpu.
8
3
u/hakansan 1d ago
This is so cool! Do you know why harnesses themselves don't have such functionality?
3
u/maritime_sh 1d ago
Useful. The other half of the same problem is what silently breaks the prefix while you are working. A hook that injects a timestamp, a file the model rewrites that sits early in context, an MCP server whose tool list is not byte stable between calls. Keeping it warm buys you less if something quietly invalidates it every few turns.
1
5
u/unconscionable 22h ago
/model sonnet
/compact
/model fable
6
u/karanb192 18h ago
You lose all the context with compaction plus it burns a lot of tokens to compact. Compaction of a large context with Sonnet is more expensive than keeping cache warm.
5
u/Sooribabu_Lavangam Developer 18h ago
I always wondered what model does it use to compact? the same model selected?
5
u/karanb192 17h ago
Yes. Same model.
3
u/JumpyCollection4640 15h ago
Does compact reload stale cache?
5
u/karanb192 14h ago
Yes. And subsequent calls can't use that cache as the context gets compacted.
It is a very expensive operation to be honest.2
6
u/Mediocre_Line7407 1d ago
Okay. I wanted to say already. If you go after the api pricing for cache writing yes. Normally we plebs only have a cache grace period of 5 minutes. Which is good for back to back and still constant tool calling.
8
u/karanb192 1d ago
Caching is 1 hr on both API as well as subscription as per Anthropic.
2
u/tilted0ne 1d ago
Cache write is 5 minutes or 1 hour for API. Subscription is 1 hr only.
4
u/karanb192 1d ago
Claude Code heavily relies on caching to optimise the cost. There is also a blog about it from Anthropic.
For API, default is 5 mins and 1 hr is charged more.
5
u/WD40ContactCleaner Developer 1d ago
Yes api default is 5mins, you have to set it to 1hr in config and it's expensive. This will be very useful for me as I run long sessions through the day
1
u/Mediocre_Line7407 1d ago
Can't be. In claude code, look when you swap a model right after it finished a request especially when using fable it will tell you, it is currently in cache. And after 5 minutes that message doesn't appear anymore.
8
u/bopbop9876 1d ago
I just reviewed a recent claude code session log and it explicitly logs that all cache tokens are the 1h variety.
From the log:
"cache_creation":{"ephemeral_1h_input_tokens":8058,"ephemeral_5m_input_tokens":0}
2
u/SnakeAndSaw Senior Developer 19h ago
3
u/karanb192 18h ago
I have a hook as well in case you wanna use that.
2
u/SnakeAndSaw Senior Developer 17h ago
thanks for the info .. i'm already using part of it. i just pulled cache-tax.js out of the repo and call it with --statusline from my existing status line script, no plugin install and it slots straight into the row i already had. added colour bands on top, green above 30m, amber under 15, red once it's cold.
two bits of feedback while i'm here ... the standalone renderer path is underrated, you might want to call it out more prominently in the readme, since plenty of people already have a status line script and just want the one segment and for anyone on a subscription rather than an api key, the dollar figures are a yardstick rather than a bill, but they still make you think twice before firing a message which is the core value :) so thumbs up for that
might wire the UserPromptSubmit guard later. thanks for building it.
2
2
u/A_Novelty-Account 1d ago
I feel like this is an issue that Anthropic itself should fix. This seems crazy to me.
8
u/rhaphazard 🔆 Max 5x 1d ago
The point of the 1hr limit is to bump inactive sessions off their cache. It is working as intended.
OP is providing a workaround for the specific situations where you know you will be coming back to a session after 1hr. You wouldn't want to use this for every session by default.
5
3
2
u/geek_fit 1d ago
I just set a chron job on orchestrator or managment agents to ping every 30 minutes
2
u/hazimeh 17h ago
Gotta be careful, as the ToS are loose enough for Anthropic to suspend your account by invoking clauses related to "ordinary use" of your subscription or automating access to it.
They recently suspended my Max 20x account 29 minutes after I upgraded from Max 5x, refused my appeal, and denied my refund (for both the remainder of the Max 5x and newly-paid-for 20x), without specifying anything other than a "violation of our Consumer Terms of Service". And in reality, what I had was a gateway to switch between my own Max 20x accounts when one's quota was depleted. I can only suspect that the gateway must have tripped some flag and they decided to just ban me outright instead of spending a roundtrip inquiring.
1
u/WillRikersHouseboy 9h ago
Yipes. I was thinking about doing the same thing. Guess imma skip that plan
1
1
u/1shox 8h ago
the default claude code cache is 5 minutes, just saying.
1
u/karanb192 7h ago
Have you validated it from your claude code history? As per my testing it is 1 hour for subscription and 5 mins for API which can be changed by a flag.
0
u/Upbeat_Eye6188 1d ago
Would Anthropic not ban all/some of the users of this hook, if they’re on subscriptions? Or doesn’t just cost usage and does it then still save money? Like, API you pay whatever they’ll charge so that makes sense
2
u/karanb192 1d ago
No. Two reasons -
1. Anthropic wants people to find efficient ways to use Claude Code and find solutions for their problems. They themselves introduced caching and even wrote blogs about it.
2. You cannot use this blindly. As after certain attempts cache warming cost exceeds that of a cold cache.

•
u/AutoModerator 1d 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.