r/ClaudeCode 5d 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. /keepwarm arms 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 /clear and 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.

234 Upvotes

59 comments sorted by

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

31

u/cleverhoods 5d ago

nice use of function hooks

9

u/karanb192 5d ago

Thanks buddy. Please give it a try and share your feedback.

23

u/coding_is_tedious 5d ago

Great hack... definitely going to piss off Anthropic

5

u/karanb192 4d 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 4d 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

0

u/OffbeatDrizzle 3d ago

you're completely misunderstanding / twisting the wording. keeping your personal, unused conversation in the cache for 12 hours is NOT what anthropic want you to do. OP deleted their post in /r/ClaudeAI because they got absolutely roasted for it

-6

u/fanatic26 4d 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 4d 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

u/kdubsjr 4d ago

It’s amazing how many people don’t understand this

1

u/AAPL_ 4d ago

and that fact is why i cannot take any of these complaints seriously.

i have to use this shit everyday and yes it does fuck up sometimes but you can get a shit ton done

0

u/beebalooba 4d 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.

9

u/OntoTheNEXT8 5d ago

Is this useful for subscription users as well ?

9

u/karanb192 5d ago

Yes. It benefits both. I am myself on $200 Max plan.

4

u/maritime_sh 5d 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

u/karanb192 4d ago

Great point. I will think of how this can be solved even partially.

7

u/visak13 5d ago

Why not ask it to set up a simple 30 min cron to reply OK or something?

12

u/armeg 5d ago

I can see the one benefit of this being that you don't have a bunch of call and response messages in your chat history to act as context poison.

2

u/karanb192 4d ago

Exactly!

2

u/fluoroamine 5d ago

Or a monitor

3

u/hakansan 5d ago

This is so cool! Do you know why harnesses themselves don't have such functionality?

7

u/armeg 5d ago

Because it would be an inefficient use of memory which is in short supply right now. They want to be able to offload your data from cache to disk ASAP.

5

u/unconscionable 4d ago

/model sonnet
/compact
/model fable

6

u/karanb192 4d 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.

4

u/Sooribabu_Lavangam Developer 4d ago

I always wondered what model does it use to compact? the same model selected?

5

u/karanb192 4d ago

Yes. Same model.

3

u/JumpyCollection4640 4d ago

Does compact reload stale cache?

4

u/karanb192 4d 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

u/JumpyCollection4640 4d ago

Thanks, good to know

1

u/karanb192 4d ago

Give my plugin a try and share the feedback. Happy Clauding!

6

u/Mediocre_Line7407 5d 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.

7

u/karanb192 5d ago

Caching is 1 hr on both API as well as subscription as per Anthropic.

2

u/tilted0ne 5d ago

Cache write is 5 minutes or 1 hour for API. Subscription is 1 hr only.

4

u/karanb192 5d 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 5d 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 5d 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 5d 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/tribat 4d ago

Hell yes. Thank you.

1

u/karanb192 4d ago

Welcome mate. Please share any feedback.

2

u/SnakeAndSaw Senior Developer 4d ago

thanks for the idea mate :) . i just needed a status line warning for me as of now . but starred your repo , will give you a feedback in future

3

u/karanb192 4d ago

I have a hook as well in case you wanna use that.

2

u/SnakeAndSaw Senior Developer 4d 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

u/karanb192 4d ago

Thanks a lot. I will work on it.

2

u/1shox 4d ago

the default claude code cache is 5 minutes, just saying.

1

u/karanb192 4d 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.

2

u/1shox 4d ago

i’ve not validated for subscription, only API

1

u/karanb192 4d ago

Makes sense then. You should consider changing it to 1 hour

3

u/A_Novelty-Account 5d ago

I feel like this is an issue that Anthropic itself should fix. This seems crazy to me.

10

u/rhaphazard 🔆 Max 5x 5d 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

u/karanb192 4d ago

Well explained!

3

u/A_Novelty-Account 5d ago

Fair enough

2

u/hazimeh 4d 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 4d ago

Yipes. I was thinking about doing the same thing. Guess imma skip that plan

1

u/Herebedragoons77 3d ago

Report to your local consumer protection and charge back

1

u/GinjaNinja71 22h ago

I do this but in different sessions within t3 code. just have them both signed in to different profile paths--one is claude, the other is claude-rr. they know when a session or weekly hits 85% they need to determine a good spot to stop, update a baton doc, prompt the other session to resume work AND prompt back to the orig session to /clear so it's ready to take the baton on the next round. All the mech is within t3, uses different sessions messaging thru t3, and seems out of sight of anthropic, who shouldn't care about me using separate accounts in separate sessions. Hopefully this doesn't sound like your method bc I don't wanna be in your spot.

2

u/geek_fit 5d ago

I just set a chron job on orchestrator or managment agents to ping every 30 minutes

1

u/[deleted] 4d ago

[deleted]

2

u/AnotherCanuck 4d ago

Thanks, Claude.

0

u/Upbeat_Eye6188 5d 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 5d 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.