**TL;DR:** (but read if you like saving $ and maximizing your limits...) When a long Claude Code session sits idle past its cache lifetime (1 hour in my sessions) and you come back, your next message pays to rebuild the whole conversation's cache. A tiny automatic reply every ~50 minutes avoids that. Measured from my own session logs since I've been using this...I have a membership, and it still factors in for tokens not wasted, but for API-equivalent costs: across 53 sessions, 474 pings cost ~$67 vs. ~$520 of cold-cache rebuilds.
Eg. of long session alone: 35 pings, ~$3.50, avoided ~$25.
"One ping costs ~1/40th of a full cache rebuild."
**The problem many seem to miss...**
Claude Code caches your conversation so each message doesn't re-pay for everything before it. Reading that cache is cheap, but it expires. If you walk away longer than its lifetime (dinner, sleep, a long build or training run) and then reply, the entire conversation is written to the cache again at the expensive rate. On a big session that's a real hit every time you come back.
**What I set up (the gist)**
One Claude Code **Stop hook**, with no cron or external timer. Claude Code can run a Stop hook in the background and wake the session when the hook exits with code 2 (`asyncRewake`). Mine starts a small watcher at the end of every turn. It checks the session transcript once a minute, and after 50 idle minutes it exits with a short instruction: reply with exactly "warm · 9:16 AM" (the script stamps the time, since the model has no clock), no tools, no file changes. That ~15-token reply re-reads the cache, which resets its 1-hour timer, and the end of that turn starts the next watcher.
Safety rails:
- Stops after 20 consecutive pings (~17 hours) until I send a real message, so a forgotten session can't ping forever. (In practice it never triggered: I always came back or closed the session first.), just there in case you totally space out, go touch grass for a few days and forget about it...it's not pinging/costing you perpetually...
- One watcher per session, and it dies with the session, so closing a session ends the pings.
- Global and per-project off switches.
- Logs each ping's `cache_read` / `cache_creation`, which is how I know every ping was a cache hit.
**The numbers** (Based on Opus 5.5 pricing: cache read = 0.05x input, 1-hour cache write = 2x input)
- One ping costs ~1/40th of a full cache rebuild.
- One long session: 35 pings over 8 idle stretches (1 to 12 hours) = **$3.50**; rebuilds avoided = **$25.23**. Every ping was a cache hit (big read, ~335 new tokens written).
- All 53 sessions I have historically: pings **$67**, rebuilds avoided **$520**. Only ~$11 of the $67 went unused: $9 in sessions I never returned to, $2 where I came back within the hour anyway.
- Break-even is ~40 pings on Opus 5.5, so with the 20-ping cap, any return within ~17 hours is a win. On models where cache reads cost 0.1x, the cap sits right at break-even.
**When it does NOT help**
- **You leave a session open and never come back.** Those pings are wasted. Close sessions you're done with: a closed session never pings, and the cap limits any one you forget, but it's always better to start fresh in general, the problem is starting over it not always optimal for a given instance, hence this solution...
- **You come back within the hour.** The cache was still warm, so that ping wasn't needed. Unavoidable (the hook can't know when you'll return), but tiny: $2 across ALL my sessions.
- **You come back between 50 and 60 minutes.** A ping fired at the 50-minute mark, but the cache would still have been warm when you returned, so that one ping wasn't needed. Come back sooner and no ping fires at all ($0). The hook can't know when you'll return, so this can't be avoided, but it's tiny: 14 such pings, ~$2, across ALL my sessions.
- **Your session uses the 5-minute cache.** This relies on the 1-hour cache; a 50-minute ping does nothing for a 5-minute one. Check yours (below).
- **On a subscription,** the dollar figures are API-equivalent, not actual charges. The benefit there is stretching your usage limits. Anthropic doesn't publish exactly how cache reads and rebuilds count against plan limits, so read the numbers as ratios. The savings assume your plan weighs a cheap cache read far less than a full rebuild, as API pricing does, so your limits stretch further.
**The bigger lesson: session size**
My long session for eg. had grown to ~740K tokens. Every ordinary call re-reads the whole thing (on average ~386K tokens per call over 267 calls), and that re-reading cost ~$20, about as much as the keep-warm saved in that session. Keep-warm is great for an important session you can't restart yet. But when you can, start a fresh session (with good notes or a handoff summary) so each call re-reads far less.
**How to check your own sessions**
Claude Code keeps transcripts as JSONL under `~/.claude/projects/<project>/`. Each assistant entry has `message.usage`:
- `cache_read_input_tokens` / `cache_creation_input_tokens`: a healthy resume shows a big read and a tiny write. A large `cache_creation_input_tokens` on the first message after a break is the expensive rebuild this avoids.
- `cache_creation.ephemeral_1h_input_tokens` vs `ephemeral_5m_input_tokens`: tells you whether your session uses the 1-hour or the 5-minute cache.
As with most stuff, have Claude Code set this up for you and ask me anything you want. Happy Coding!