ClaudeMap

cachebeat

A one-file Claude Code skill that heartbeats idle sessions to keep the prompt cache warm — so coming back doesn't re-bill your entire conversation.

Skills & Commandsskillprompt-cachingcostbackground-tasks

Claude is stateless: every turn re-sends the whole conversation, and once the session sits idle past the cache TTL, the next message re-processes the entire history uncached — roughly 10x the tokens a cached read would count, as money on the API or as your 5-hour window and weekly limit on subscriptions. /cachebeat arms a single background monitor inside the session. It is an inactivity timer, not a metronome: it fires only when the session has been truly silent for N minutes (default 50, clamped to 5-55), and any real message, reply or answered background event resets the clock. On firing, Claude wakes, answers with a few words, and the TTL restarts. It kills itself after a deadline (default 8 h) so an abandoned session doesn't drip-bill forever. The idle signal is the timestamp of the last transcript line — not the file mtime, which Claude Code bumps for its own housekeeping (recap rewrites, atomic saves) and which would make the beat fire late, past the TTL.

What it does

  • /cachebeat arms the monitor, /cachebeat 40 4 sets a custom idle threshold (minutes, clamped 5-55) and auto-stop deadline (hours), /cachebeat stop disarms
  • Idle measured from the last transcript line's timestamp — a bare mtime bump does not fool it; the session transcript is pinned by $CLAUDE_CODE_SESSION_ID so a sibling session can't hijack it
  • Self-checking: if a beat still lands uncached it prints CACHEBEAT_WARN (your session's TTL is too short for any heartbeat to bridge); CACHEBEAT_EXPIRED ends the monitor
  • Verify with the statusline token readout (total / served-from-cache) or a one-line grep of cache_read_input_tokens vs cache_creation_input_tokens in the transcript

When to use it

Long babysitting sessions — multi-hour training runs, CI, big downloads — on the API or on Pro/Max 5-hour windows: any session you will return to after an idle gap longer than the cache TTL. Break-even is going cold once, which costs about as much as ten heartbeats.

Getting started

mkdir -p ~/.claude/skills/cachebeat
cp SKILL.md ~/.claude/skills/cachebeat/
# project-level: copy into <your-project>/.claude/skills/cachebeat/

# then inside any Claude Code session:
/cachebeat            # fire after 50 min of inactivity, auto-stop after 8 h
/cachebeat 40 4       # custom: 40 min idle, auto-stop after 4 h
/cachebeat stop

Things to know

README says MIT, but the repo had no LICENSE file at the time of writing. Only helps sessions with the long (1-hour) cache TTL — some sessions run a 5-minute TTL no heartbeat can bridge. Each beat is a small cached read plus a few output tokens, and its exchange joins the context later turns re-read: cheap, not free. Reads Claude Code's internal transcript layout (undocumented), so a future change could require an update; POSIX shell only — Linux, WSL2 and macOS tested, native Windows untested.

Repository

ARahim3/cachebeat

Charted

Related on the map

  • Guizang's agent skill turns your repo's recent updates into a finished promo video — real components, code-rendered animation, an original code-written soundtrack — no video editor involved.

    • agent-skill
    • video
    • promo
    • marketing
  • An agent skill that geolocates a photo with nothing readable in it — OSM geometry, elevation skylines and satellite tiles turn “where was this taken?” into a measured answer with an error radius.

    • agent-skill
    • geolocation
    • osint
    • openstreetmap
  • A skill that makes AI coding agents map the architecture and declare the blast radius before they touch a line of code — rendered as one standalone HTML page.

    • skill
    • architecture
    • code-visualization
    • change-scope