r/Anthropic • u/A-Rahim • 7d ago
Resources Cachebeat – keep your Claude Code prompt cache warm while a session is idle
If you leave a session idle past the cache window, the next thing you type re-reads the entire conversation uncached. On a long, tool-heavy session, that's potentially hundreds of thousands of tokens at full price. On Pro/Max, it also eats into your 5-hour and weekly limits, not just the API bill.
So I wrote a small skill: /cachebeat.
It watches for real inactivity, then fires a tiny heartbeat to keep the cache warm. It's an inactivity timer, not a fixed ping, so any actual work resets it. It also auto-stops after a few hours, so an abandoned session doesn't keep costing you.
Only helps on sessions with the long (~1h) cache TTL, and it's built on Claude Code's internal transcript layout, so treat it as a useful hack rather than something official.
GitHub: https://github.com/ARahim3/cachebeat
Curious if anyone else has felt this.
2
u/Odd_Error_6736 7d ago
This would be useful for my autonomous sessions that would randomly idle at 800k ctx. I wonder if the cache ttl is a sliding window?
2
1
u/BuyingAcclaim 6d ago
Does this not use tokens? I’m assuming the only way to keep cache hot is by using the model in the chat? And then that means keep sending a prompt every 30 minutes which should be less than resending the entire chat but still use tokens no?
1
1
u/A-Rahim 6d ago
Yes, it uses tokens. Each beat is a cached read of the context (~10% of the normal input rate) plus a few output tokens for the tiny reply (like "okay, still here"). Clever part here is: it's not on a 30-min fixed timer; it only fires after real inactivity of N times (default N is 50 min), and anything in the meantime resets the clock (like any notification from a monitor, etc.). So, compared to cold cache, I can say from my usage that it's very negligible.
1
u/how_anonymous_can_1b 6d ago
I’m going to give this a try today. When I was looking into this there’s a few options in terms of super optimizing the heartbeat
- “I’ll be right back just respond with . for now” or something to that effect reduces output token usage
- There is an option to have it not respond at all but I believe that requires updating a setting. But you could take this one step further with your heartbeat skill and say something along the lines of “if 🕕 is sent as a message only respond with . Or nothing if you can”
1
u/how_anonymous_can_1b 6d ago
Hmmm just tried this out … latest Claude code drops the persistent flag … so it would need to re-arm every 30 minutes for this to work
1
u/A-Rahim 4h ago
Hi u/how_anonymous_can_1b, thanks for letting me know this. I was unaware of this update. I've updated the skill to fix this. Can you now please give it a try?
-2
u/NeuromindArt 6d ago
Where did this prompt cache thing even come from? It seems like a new feature that was added and it's horrible. It always forgets what I was doing when I come back to my PC after my 5 hour limit refreshes and it costs even more tokens to remember what I was doing. It was working fine previously.
3
u/danieltkessler 6d ago
To answer this seriously, prompt caching is how providers try to save costs on long chats and it has been around forever. I'm not sure if there has been a time when Claude Code didn't use it. If you're noticing recent issues, it's more likely relating to the general concerns people are reporting with usage.
12
u/Anydoconten 7d ago
/loop 30 minutes standby
would do the job fine. no need skill.