By yujiachen-y
Automatically prevent Claude Code's prompt cache from expiring during idle pauses by injecting lightweight keepalive turns, saving on API costs and avoiding costly re-prompting during normal thinking gaps.
This plugin requires configuration values that are prompted when the plugin is enabled. Sensitive values are stored in your system keychain.
interval_secondsSeconds the Stop hook sleeps before injecting a keepalive ping. Claude Code's prompt cache TTL is 300s (5 min); 240 leaves a 60s safety margin.
${user_config.interval_seconds}keepalive_messageText injected as a user-side keepalive turn. Keep it bland so Claude replies cheaply without starting tools or generating long output.
${user_config.keepalive_message}max_loops_per_turnMax consecutive keepalive cycles per idle turn before giving up. At interval=240 and max=7, one idle turn keeps the cache warm for ~28 minutes.
Own this plugin?
Verify ownership to unlock analytics, metadata editing, and a verified badge. GitHub access is read-only (username + org membership).
Sign in to claimOwn this plugin?
Verify ownership to unlock analytics, metadata editing, and a verified badge. GitHub access is read-only (username + org membership).
Sign in to claimBased on adoption, maintenance, documentation, and repository signals. Not a security audit or endorsement.
${user_config.max_loops_per_turn}⚠️ EXPERIMENTAL — READ THIS BEFORE INSTALLING
This project is an experiment. It works by exploiting a currently-documented (but not contractually guaranteed) property of Anthropic's prompt cache: that cache reads refresh the 5-minute TTL. The economics assume you understand how it works. Used wrongly, this plugin will cost you more, not less.
Before you install, you need to understand at minimum:
- It is only useful on API-key / token-metered billing. On Pro/Max subscription plans, your quota is gated by request count, not token cost — every keepalive turn eats your 5-hour quota. On subscriptions, this plugin makes things worse. Disable it.
- Every keepalive turn is a real turn. It reads the cached prefix and produces a short reply. If your
keepalive_messagederails Claude into running tools or generating long output, the "cheap ping" stops being cheap.- The whole trick depends on one invariant (cache reads refresh the TTL). Anthropic can change that without notice — the same way they silently changed the default TTL from 1h to 5m in March 2026 (claude-code#46829). If they do, this plugin will quietly stop saving money and may start costing money.
- You must watch for community updates. Follow the linked issues and the CHANGELOG of this repo. When the community reports a behavior change on Anthropic's side, re-tune your
interval_seconds/max_loops_per_turnor disable the plugin entirely. A plugin you installed six months ago and forgot about is the exact scenario where this kind of trick silently turns against you.Read the Theoretical basis, The economics, and Caveats and warnings sections in full before enabling this. If any of those sections don't make sense to you yet, that's the signal that you are not yet ready to install this plugin. By installing, you accept that you have read and understood the mechanism and are responsible for monitoring its ongoing economics yourself.
A Claude Code plugin that keeps the prompt cache warm across idle
thinking pauses. It uses the Stop hook's decision: "block"
mechanism to inject a tiny keepalive turn just before the 5-minute
cache TTL expires. Cache reads cost ~12.5x less than cache
writes, so this saves real money on long sessions with idle gaps.
Why this exists. In March 2026 Anthropic silently lowered Claude Code's default prompt-cache TTL from 1 hour to 5 minutes. Users with normal 5+ minute thinking pauses started getting billed for full cache rewrites on every turn. See anthropics/claude-code#46829 for the original issue and the ~$2.5k of excess billing one user traced to the change. This plugin is a workaround.
This repo ships as both a Claude Code plugin and a single-plugin marketplace. Inside Claude Code:
/plugin marketplace add yujiachen-y/claude-code-cache-keepalive
/plugin install cache-keepalive@claude-cache-tools
That's it. No daemon, no tmux, no Python, no curl, no API key.
To verify the plugin is active:
/plugin
and look for cache-keepalive in the enabled list. You can also tail
the hook log:
tail -f ~/.claude/cache-keepalive/cache-keepalive.log
When Claude finishes a turn, Claude Code fires the Stop hook. This
plugin's Stop hook script sleeps for interval_seconds (default
240s, safely under the 300s TTL) and then writes this JSON to
stdout:
{"decision":"block","reason":"got it, i need some time to think about the next move"}
Claude Code treats that as "the user sent a new instruction" and asks Claude to respond. The response reads the cached prompt prefix — and cache reads refresh the 5-minute TTL. Claude replies with one short line, Stop fires again, the loop continues.
npx claudepluginhub yujiachen-y/claude-code-cache-keepalive --plugin cache-keepaliveAnalyze git history to understand a codebase before reading any code. Reveals hotspots, risk areas, team structure, and development momentum.
Ultra-compressed communication mode. Cuts 65% of output tokens (measured) while keeping full technical accuracy by speaking like a caveman.
Memory compression system for Claude Code - persist context across sessions
Multi-model consensus engine integrating OpenAI Codex CLI, Gemini CLI, and Claude CLI for collaborative code review and problem-solving.
Expert guidance for Next.js Cache Components and Partial Prerendering (PPR). Proactively activates in projects with cacheComponents: true, providing patterns for 'use cache' directive, cacheLife(), cacheTag(), cache invalidation, and parameter permutation rendering.
Harness-native ECC plugin for engineering teams - 67 agents, 277 skills, 93 legacy command shims, reusable hooks, rules, MCP conventions, and operator workflows for Claude Code plus adjacent agent harnesses