ClaudeMods
☰
ZH-TW
● 0 人在線上 · 瀏覽 0 次
贊助提交作品
GitHub 儲存庫 · 發布者 samyakjain0606

cache-warmer

一個 Claude Code 外掛,用靜默 ping 保持閒置工作階段的提示快取溫熱,然後在快取仍然溫熱時壓縮大型工作階段一次。

samyakjain0606@samyakjain0606

samyakjain0606/awesome-learning-material/tree/main/cache-warmer

已翻譯

關於這個 mod

一個 Claude Code 外掛,會用靜默 ping 保持閒置工作階段的提示快取溫熱,然後在快取仍然溫熱時壓縮大型工作階段一次。減少冷啟動後的等待,減少「按全價重新傳送 400k tokens」的時刻,把更多速率限制留給真正的工作。

安裝

請先查看作者 README,確認 marketplace 與外掛名稱;指令可能隨儲存庫結構而變動。

claude plugin marketplace add samyakjain0606/awesome-learning-material
claude plugin install cache-warmer
原文 / README

cache-warmer

A Claude Code mod that keeps an idle session's prompt cache warm, then compacts large sessions once while the cache is still warm. Fewer cold returns, fewer "re-send 400k tokens at full price" moments, more of your rate limit left for real work.

The problem

Every message you send re-sends the whole conversation. That is cheap while the conversation is cached (a cache read costs about a tenth of a fresh read), but the cache only lives for a limited time (one hour on most accounts). Leave a session idle past that, and your next message re-sends the entire context uncached. On a 1M-context model that is easily 400k to 500k tokens, billed in full and counted against your 5-hour and weekly limits. Claude Code warns you with new task? /clear to save 230.6k tokens, but by then the only way to avoid the cost is to throw the conversation away.

What the mod does

  • After each turn, if the session is above 100k tokens, it arms a 50-minute timer. Your next prompt cancels it.
  • While you are idle, it sends one silent fork request every 50 minutes with a one-word prompt. The request shares the session's prefix, so it is served from cache and refreshes the cache's timer. Nothing is added to your transcript.
  • After 10 idle hours it stops pinging. If the session is above 500k tokens it compacts once, while the cache is still warm, with instructions to keep the task, plan, files touched and open items. Smaller sessions are simply left to cool.
  • It never pings a cache that has already lapsed (laptop asleep, timer late), stops if a ping finds the cache cold, and keeps a daily keep-alive budget shared across all your sessions.

The status line under the prompt shows what it is doing:

⚠ cache-warmer: warm · 3 pings · next 16:16 · 225k
⚠ cache-warmer: compacted · 02:40 · 225k → 30k while warm

Install

npx degit samyakjain0606/awesome-learning-material/cache-warmer ~/.claude/skills/cache-warmer

Plugins in ~/.claude/skills/<name> load automatically on your next Claude Code session. To try it in a single session instead: claude --plugin-dir ~/.claude/skills/cache-warmer.

Requires a Claude Code build with function-hook mods (2.1.287 or newer).

Commands

| Command | Does | | --- | --- | | /warm | status: phase, context size, pings this idle period, today's spend, settings | | /warm off / /warm on | turn it off or back on for this session only; other sessions keep warming | | /warm off all / /warm on all | off in every session for the rest of today, and lift that again | | /warm now | ping right now |

Settings

All in /config (or pluginConfigs.cache-warmer.options in settings.json):

| Setting | Default | Meaning | | --- | --- | --- | | Ping interval | 50 min | keep it under the cache lifetime | | Cache lifetime | 60 min | your account's prompt-cache TTL | | Warm window | 10 h | how long to keep pinging while idle | | Minimum context to ping | 100k | smaller sessions are left alone | | Minimum context to compact | 500k | above this, compact once when the warm window ends | | Daily budget | 2000k | keep-alive spend across all sessions, in full-price token equivalents |

The honest cost line

A ping reads the whole context from cache, about a tenth of a cold re-send. Twelve pings on a 500k session cost roughly 1.2 cold returns at the base rate, or about 0.6 if the re-cache is billed at the one-hour cache-write rate. The win is every time you return inside the window, which is most workdays. Overnight is roughly break-even, and the 10-hour knob is where you tune it.

Files

  • hooks/register.ts — the hooks module
  • types/index.d.ts — the state contract
  • hooks/warm.test.ts — tests: claude plugin test ~/.claude/skills/cache-warmer
  • .claude-plugin/plugin.json — manifest and settings

MIT.

其他同名作品

更多類似作品