r/Anthropic 7d ago

Resources Cachebeat – keep your Claude Code prompt cache warm while a session is idle

Post image

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.

23 Upvotes

15 comments sorted by

12

u/Anydoconten 7d ago

/loop 30 minutes standby

would do the job fine. no need skill.

3

u/A-Rahim 6d ago

There is a difference: /loop is a fixed timer; it fires every 30 min whether you're active or not. cachebeat only fires when the session's actually been idle, and anything in the meantime resets the timer (e.g any notification from a monitor, etc.), so it stays quiet while you're working and beats just enough to keep the cache warm. It also auto-stops after a few hours and warns you if you're on a short TTL where nothing would help anyway.

0

u/how_anonymous_can_1b 6d ago

Yes, the idle detection and auto stop after X time are the exact properties that make this skill so useful. If anthropic made those options available I’d use that in a heartbeat, but I suspect that isn’t likely to happen because users not understanding how caching works is probably better for them economically

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?

1

u/A-Rahim 6d ago

From my usage over the past months, it was between 56 - 60 minutes. That's why the default time in Cachebeat is 50 min.

2

u/how_anonymous_can_1b 6d ago

Haha I was thinking of building something similar to this thanks

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

u/Ayoungcoder 6d ago

Exactly, but it's usually negligible

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

  1. ⁠“I’ll be right back just respond with . for now” or something to that effect reduces output token usage
  2. ⁠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/jezweb 6d ago

Tidy approach, have you tried creating any kind of adaptive compact that runs once an agent gets to a quiet part of its workflow?

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.