Skip to content

Prompt Cache Keepalive for Agent Pauses

Replaying a cached prefix on a timer keeps the cache resident through an agent pause — but only pays inside a narrow band.

A keepalive sends a cheap request that replays your cached prefix during an idle gap, so the entry stays warm instead of expiring while a tool runs or a human approves a step. The technique is real and the arithmetic is documented, but it pays only under four conditions at once. Most teams that ping today are outside at least one of them.

When keepalive pays

Check all four before wiring a timer:

  • You pay per token. On Claude Pro or Max, or any seat-based plan, there is no token bill to reduce and each ping consumes request quota instead (claude-code-cache-keepalive).
  • Your pauses exceed the cache lifetime. Anthropic's default entry lives five minutes (Anthropic prompt caching), so a two-second tool call never needed help.
  • Your pauses stay under the break-even horizon. Ping rent accumulates; the re-prefill it prevents is a single charge. Khailo puts the crossover near 46 minutes on Anthropic's five-minute tier (arXiv:2607.19214).
  • Your provider actually evicts. The same measurements found Google's implicit cache "never reliably evicts" and DeepSeek's re-prefill "too cheap to insure," which empties the paying band on both.

Miss any one and the honest answer is to do nothing, or to buy a longer lifetime instead — see Prompt Caching: Architectural Discipline for Agents, which covers the five-minute against one-hour tier decision.

Why it works

A cache read restarts the eviction clock, and providers charge far less for that read than for rebuilding the entry. Anthropic states the refresh semantics directly: "The cache is refreshed for no additional cost each time the cached content is used." The prices around it make the arbitrage: cache reads bill at 0.10x base input, while a five-minute cache write bills at 1.25x (Anthropic prompt caching). A keepalive therefore buys a 0.10x read to avoid a 1.25x write. Khailo reports the same refresh-on-read behavior across the four providers measured — "In all four, reading a cached prefix refreshes it" — which is why the optimal interval falls out mechanically: the longest gap that still lands inside the retention window, minus margin for jitter and latency (arXiv:2607.19214).

Choosing the interval

The interval, not the idea, is where shipped tooling gets it wrong. Roughly 240 seconds on Anthropic holds the same retention as the conventional 30-second ping — median cache hit rate stayed at or above 98% either way. The 30-second convention just spends about 8x more for it: 7.8x across the paper's interval runs, or about $3.60 per hour against about $0.45 per hour on a 100k-token prefix at July 2026 list prices (arXiv:2607.19214).

Overshooting is the more expensive error. At Anthropic's 300-second lifetime, a 900-second interval means every ping lands on a dead entry and pays the full write price, so the keepalive "costs 4x more than never pinging" (arXiv:2607.19214). Measure your own retention rather than copying a table: cross-provider lifetimes move, and OpenAI now defaults organizations without zero data retention to a 24-hour window, contradicting the shorter lifetimes usually assumed (OpenAI API changelog).

When this backfires

  • Subscription billing. Pings cost quota and save nothing (claude-code-cache-keepalive).
  • Long walk-aways. Past the break-even horizon, accumulated rent exceeds the one re-prefill you avoided (arXiv:2607.19214).
  • An interval above real retention, which inverts the result to 4x worse than doing nothing.
  • Prefix mutation mid-pause. If tool definitions or the system prompt change while the timer runs, you warm a prefix the next real request will not match — the failure mode described in Static Content First for Cache Hits.
  • Fleet-wide adoption. Khailo argues keepalives manufacture recency, so "once every client keeps its prefixes alive, LRU has nothing left to rank and the tier degrades toward first-in-first-out-of-luck," pushing providers toward metering residency directly and closing the arbitrage (arXiv:2607.19214).

Example

Three shipped implementations, three different intervals, against Anthropic's documented 300-second lifetime:

aider --cache-keepalive-pings N   → 300 s   no margin below the TTL; off by default
claude-code-cache-keepalive       → 240 s   Stop hook sleeps, then injects a turn
openclaw #62475 (proposed)        → TTL x 0.8 (~240 s), plus a $0.10/hour cost cap

Only the second and third leave headroom for jitter. Aider fires exactly at the documented lifetime (aider docs); the Claude Code plugin sleeps 240 seconds and injects a keepalive turn through a Stop hook (repo); openclaw derived an adaptive interval of 0.8 times the TTL with an automatic cost cap, then closed the proposal as not planned (openclaw#62475). That closure is itself a signal: maintainers weighed the complexity against the saving and declined.

Key Takeaways

  • A keepalive converts a 1.25x cache write into a 0.10x cache read by exploiting documented refresh-on-read semantics.
  • Roughly 240 seconds beats the conventional 30-second ping by about 8x in spend on Anthropic, at the same retention.
  • An interval above real retention costs about 4x more than never pinging — overshooting is worse than not trying.
  • Subscription billing, sub-lifetime pauses, walk-aways past the break-even horizon, and non-evicting providers each remove the benefit entirely.
  • Measure your provider's retention window; published cross-provider lifetimes conflict and change.