Heartbeat Monitor pattern against the Claude Code prompt-cache TTL. The main interactive thread holds a ~1-hour effective TTL in the measured corpus ; the 5-minute default applies to the subagent/sidechain tier and the API default, not the main thread. This pattern keeps the cache warm across long idle waits by emitting one stdout line on an adaptive interval (default 3300 seconds, one tick just under the ~1-hour TTL ; scale it down to match a shorter declared window), buying resume-latency readiness against the ~1-hour TTL (the dollar payoff lands only on AFKs approaching ~1 hour with large context).
Run this in a terminal next to your active Claude Code session :
#!/usr/bin/env bash
set -uo pipefail
INTERVAL="${1:-3300}" # default 55 min ; pass e.g. 240 for a short window
ITER=0
while true ; do
ITER=$((ITER+1))
echo "BEAT-${ITER}"
sleep "$INTERVAL"
doneOr curl + run :
curl -sSL https://raw.githubusercontent.com/Regis-RCR/warmpulse/main/scripts/warmpulse.sh | bashEach BEAT-N line counts as session activity for the Claude Code runtime ; the prompt cache stays warm.
/plugin install github:Regis-RCR/warmpulseAfter install :
/warmpulsearms a WarmPulse with canonical defaults (idempotency-checked).- Opt-in auto-arm : create
~/.claude/warmpulse.config.jsonwith{"auto_arm": true}to make the SessionStart hook suggest arming on each new session.
Summary :
- The Anthropic prompt cache is two-tier in the measured corpus : the main interactive thread holds a ~1-hour effective TTL, the subagent/sidechain tier ~5 minutes. WarmPulse runs on the main thread.
- A silent idle wait past the main TTL (~1 hour) costs a full re-prime on the next interaction (10k to 50k tokens depending on context).
- A heartbeat Monitor emits one stdout line per tick (adaptive interval, default 3300s just under the ~1h main TTL, scaled down to a shorter declared window) ; each line counts as session activity and resets the TTL clock, so the prefix stays warm across the wait.
- Honest economics (v0.8.0 forensic close-out, 286886 turns) : per-tick cost is ~$0.13 (dominated by the
cache_readof the full prefix, not the ~200-token emit). On the pay-as-you-go dollar axis the heartbeat net-costs, because 96% of beats bridge sub-5-minute gaps the 1-hour cache holds for free. - Where the value lives : resume-latency, subscription quota (
cache_readis ~10% of base), and zero marginal CASH on a subscription. Arm for those on long AFKs, not for a dollar saving.
Full doctrine and the honest cost counterfactual in references/canonical-rule.md.
Companion Medium article : [link placeholder once published on AI Software Engineer publication]
Apache-2.0 ; see LICENSE. Copyright 2025-2026 Regis-RCR.
Author : Regis. AI-assisted translation on prose ; technique, data, and framing are operator-original.