Cc Cache Keepalive — Development skill for Claude Code
Keep the most recently used Claude Code prompt cache warm without polluting the original session.
How to install Cc Cache Keepalive
This entry records only its repository, not the path inside it, so there is no
exact command to give. Open Pan1127/cc-cache-keepalive and copy the folder into
~/.claude/skills/, or the file into ~/.claude/agents/.
What Cc Cache Keepalive does
Keep the most recently used Claude Code prompt cache warm without polluting the original session.
Alternatives in Development
- Caveman Micro — 6-line caveman micro prompt (85 tokens) that outperformed the original 552-token skill 162 ★
- Compact 서비스 (대화 요약) — 관찰 위치: Claude Code 내부 아키텍처 변수: NO_TOOLS_PREAMBLE, BASE_COMPACT_PROMPT, PARTIAL_COMPACT_PROMPT, PARTIAL_COMPACT 149 ★
- Pair Verify — Use after you fix a bug and before you claim it fixed — it spawns ONE skeptic sibling session via CCC that mus 130 ★
README
Claude Code Cache Keepalive
一个只为“最近使用的 Claude Code 会话”续热提示缓存的小工具。
它不会把保活消息写回原会话:每次调用都使用 `--fork-session` 和 `--no-session-persistence`。它会禁用全部内置工具和 MCP,只在返回随机 nonce 且 Claude Code 报告了缓存 token 时记录成功。
工作方式
- 从
sessions.json找出last_used最新的会话。 - 若对应 tmux 窗口正忙,本次自动跳过。
- 距离最近活动满 50 分钟后,从原会话创建一个不持久化的临时分叉。
- 验证回复和
cache_read_input_tokens/cache_creation_input_tokens。 - 只把状态和 token 计数写入独立的
status.json。
这不能保证供应商永远保留缓存,也不会减少输出 token;它只是尽量避免活跃会话的 提示缓存因一小时无请求而失效。每次保活仍会产生少量输入和输出用量。
要求
- Linux、Python 3.10+
- 已登录且可用的 Claude Code CLI
- tmux(仅用于判断交互窗口是否正忙)
- 一个由你的会话管理器维护的
sessions.json
安装
sudo install -d -m 0755 /opt/cc-cache-keepalive
sudo install -d -o claude -g claude -m 0750 /var/lib/cc-cache-keepalive
sudo install -m 0755 cc_cache_keepalive.py /opt/cc-cache-keepalive/
sudo install -o claude -g claude -m 0640 .env.example /etc/cc-cache-keepalive.env
sudo install -o claude -g claude -m 0640 sessions.example.json /var/lib/cc-cache-keepalive/sessions.json
sudo install -m 0644 cc-cache-keepalive.service cc-cache-keepalive.timer /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now cc-cache-keepalive.timer
以上命令假设运行用户和用户组都是 `claude`;如果不是,请在命令、环境文件和 service 的 `User=` 中统一替换。 把 `/etc/cc-cache-keepalive.env` 中的路径改成实际值。 `sessions.example.json` 展示了输入格式;`last_used` 是 Unix 时间戳。
接入会话管理器
每次用户真正使用某个 Claude Code 会话时,由你的程序原子更新 `sessions.json`:
{
"窗口标识": {
"sid": "Claude Code 会话 UUID",
"tmux": "可选的 tmux 会话名",
"model": "auto",
"last_used": 1788192000
}
}
`sid` 和 `last_used` 必填。没有使用 tmux 时可以省略 `tmux`;脚本仍会保活,但无法判断 该交互窗口是否正忙。写文件时应先写同目录临时文件,再用原子重命名替换,避免定时器 读到半截 JSON。
检查
systemctl list-timers cc-cache-keepalive.timer
journalctl -u cc-cache-keepalive.service -n 30 --no-pager
cat /var/lib/cc-cache-keepalive/status.json
成功状态会包含 `status: "success"`、最近成功时间和缓存 token 数。其他旧会话会标记 为 `paused`,因此不会同时保活多个窗口。
隐私与安全
- 不要提交
.env、sessions.json、status.json或任何.jsonl会话记录。 - 保活调用通过
Related Skills
Claude Prompt Cache Keepalive
Agent skill for Claude Code: keep the 1-hour prompt cache warm while you are away, with a ladder of background
Cache Keepalive
Keeps an idle Claude Code session's prompt cache warm, so the session you come back to does not start cold
Cache Tax
Keep Claude Code’s prompt cache warm during breaks and show the estimated cost before a cold send.
Claude Code Coffee
Keep your Claude Code prompt cache warm during breaks. Saves up to 92% on cache rebuild costs.
Wirescope
A transparent analytical proxy for the Claude Code & Codex CLIs — see the real per-turn cost, prompt-cache war
Ctx Handoff Mod
Claude Code mod: auto handoff to a fresh conversation when context hits a threshold, keeps the prompt cache wa
Related Agents
Context Analyst
Analyzes project structure, locates relevant files, and extracts architecture before any change is made. Use t
Worker Apply Opus
Resumable implementation worker for non-SDD work units. Applies multi-file changes from a handoff, absorbs fol
Follow Up Agent
Use to keep warm conversations from going cold: stalled threads after an accept or a maybe, people who asked t