MohabYasser2/claude-code-mods/tree/main/cache-band
Claude Code改造
Claude Codeの改造は3つ。私はClaudeに、私の最後の 30 Claude Code セッションを監査して、どこに時間がかかったかを教えてくれるように頼みました。各 MOD は、見つかった 1 つのことに答えます。 |モジュール |何をするのか |監査で判明したこと | |---|---|---| |キャッシュバンド |プロンプト キャッシュの温度を示し、外出中も温度を保ち、400K トークンでの長い会話を圧縮します。 91 回キャッシュがコールドになりました | | Git 同期バンド |ブランチ、ahead/behind、プロンプトの上にある変更されたファイル、プル、ファイル、コミットおよびプッシュ ボタン | 1,660 git チェックを手動で行う | |スカウトルーター | Sonnet | での探索、読み取り、または調査のみを行うサブエージェントを実行します。 309 サブエージェントのうち 243 が Opus | で実行されました。これらは Claude Code の関数フック上で実行されます。これらは早期アクセス段階にあるため、API はリリース間で変更される可能性があります。これらをClaude Code 2.1.286 と 2.1.287 でビルドしてテストしました。
この mod について
Claude Codeの改造
Claude Codeの改造は3つ。私はClaudeに、私の最後の 30 Claude Code セッションを監査して、どこに時間がかかったかを教えてくれるように頼みました。各 MOD は、見つかった 1 つのことに答えます。
|モジュール |何をするのか |監査で判明したこと | |---|---|---| | キャッシュバンド |プロンプト キャッシュの温度を示し、外出中も温度を保ち、400K トークンでの長い会話を圧縮します。 91 回キャッシュがコールドになりました | | Git 同期バンド |ブランチ、ahead/behind、プロンプトの上にある変更されたファイル、プル、ファイル、コミットとプッシュ ボタン | 1,660 git チェックを手動で行う | | スカウトルーター | Sonnet | での探索、読み取り、または調査のみを行うサブエージェントを実行します。 309 サブエージェント中 243 が Opus | で実行されました。
これらは Claude Code の関数フック上で実行されます。これらは早期アクセス段階にあるため、API はリリース間で変更される可能性があります。これらをClaude Code 2.1.286 と 2.1.287 でビルドしてテストしました。
インストール
1。 MOD のフォルダーを ~/.claude/skills/ にコピーします (例: ~/.claude/skills/cache-band)。
2。新しいセッションがそれをロードします。すでに開いているセッションで、/reload-plugins を実行します。
MOD をロードする前にチェックするか、テストを実行するには:
claude plugin validate ~/.claude/skills/cache-band
claude plugin test ~/.claude/skills/cache-band
Claude Codeが MOD をロードすると、claude-code 型宣言が tsconfig.json が指す MOD の .claude-plugin/types フォルダーに書き込まれます。ここではそのフォルダーは git 無視されます。
キャッシュバンド
すべてのメッセージで会話全体が再読されます。プロンプト キャッシュはそのコストを低く抑えます。キャッシュ読み取りのコストは通常の入力価格の約 十 分の 1 です。私の計画では、キャッシュ エントリは最後に読み取られてから 1 時間存続します。コールドになると、次のメッセージによって会話全体が再びキャッシュに書き込まれ、1 時間のキャッシュ書き込みには入力価格の 2 倍のコストがかかります。 400K の会話では、それが加算されます。
バンドはプロンプトの上にあります。時間が経過すると冷えて雪の結晶になる炎、残り分、2 つのトグルとコンパクト ボタンです。
自動キャッシュ。 キャッシュがコールドになる 十 分前に、キャッシュに ping を送信します。 ping は $.model.fork を経由し、最後に 1 行のキープアライブを付けて、バックグラウンド コピーから会話の最後のリクエストを再送信します。コピーは同じ会話の一言一句であるため、API は同じキャッシュからコピーを提供し、その読み取りはキャッシュをさらに 1 時間保持します。返信は破棄され、チャットには何も追加されません。チャットに「こんにちは」と入力すると、キャッシュも温かく保たれますが、それは会話に永久に残り、Claudeがそれに基づいて行動する可能性があります。
20 ping が連続して送信されると停止します。 ping はキャッシュ (0.1x) を読み取り、コールド リスタートはキャッシュ (2x) を書き込みます。そのため、20 ping のコストは、約 16 時間で、阻止された再起動にかかる費用となります。次のメッセージによって、再び再開されます。 ping でキャッシュがすでになくなっていることが判明した場合、自動キャッシュは 1 時間ごとに全額を支払う代わりに一時停止します。自動圧縮。 会話が 400K トークンを通過すると、Claudeの返信直後、キャッシュがまだ温かいうちに圧縮されるため、要約のために会話を読むのは低コストです。
コンパクト。 ボタンは、入力したかのように /compact を実行します。デスクトップ アプリは MOD の直接圧縮呼び出しを拒否するため、これがそこで機能するルートです。
28 テストは、ゲージ、ping、および自動コンパクトをカバーします。
Git 同期バンド
プロンプトの上の帯には、分岐、分岐の前後の距離、変更されたファイル、最後にプッシュした日時が表示されます。認証情報のプロンプトや git のインデックス ロックを取得せずに、git ステータスを 1 分ごとに読み取り、5 分ごとにフェッチします。
プロンプトの前に、何も失うことができない場合は --ff-only でプルし、何が入ったのか、またはなぜ何もしなかったのかをClaudeに伝えます。バンドから直接 git をプル、ファイル、コミット、プッシュ実行します。シークレットのように見えるファイルはコミットされません。
5 テストは、バンドのレイアウトとコミット フローをカバーします。
スカウトルーター
Claudeがサブエージェントを開始すると、Scout Router はそのタイプと説明を読み取ります。 Explore エージェント、および説明が探索、読み取り、検索、研究に関する汎用エージェントは、Sonnet 上で実行されます。計画、監査、レビュー、グレーディングに関するすべての作業は、メイン モデルに残ります。各再ルートはログに記録されます。
ライセンス
マサチューセッツ工科大学
インストール
まず作者の README で marketplace とプラグイン名を確認してください。コマンドはリポジトリの構成によって変わる場合があります。
claude plugin marketplace add MohabYasser2/claude-code-mods claude plugin install cache-band
原文 / README
Claude Code mods
Three mods for Claude Code. I asked Claude to audit my last 30 Claude Code sessions and tell me where my time went. Each mod answers one thing it found.
| Mod | What it does | What the audit found | |---|---|---| | Cache Band | Shows how warm the prompt cache is, keeps it warm while you're away, and compacts long conversations at 400K tokens | My cache went cold 91 times | | Git Sync Band | Branch, ahead/behind and changed files above the prompt, with Pull, Files and Commit & push buttons | 1,660 git checks done by hand | | Scout Router | Runs subagents that only explore, read or research on Sonnet | 243 of 309 subagents ran on Opus |
They run on Claude Code's function hooks. Those are in early access, so the API can change between releases. I built and tested these on Claude Code 2.1.286 and 2.1.287.
Install
- Copy a mod's folder into
~/.claude/skills/, for example~/.claude/skills/cache-band. - New sessions load it. In a session that was already open, run
/reload-plugins.
To check a mod before you load it, or to run its tests:
claude plugin validate ~/.claude/skills/cache-band
claude plugin test ~/.claude/skills/cache-band
When Claude Code loads a mod, it writes the claude-code type declarations into the mod's .claude-plugin/types folder, which tsconfig.json points at. That folder is git-ignored here.
Cache Band
Every message re-reads the whole conversation. The prompt cache keeps that cheap: a cache read costs about a tenth of the normal input price. On my plan a cache entry lives for an hour after it was last read. Once it goes cold, the next message writes the whole conversation into the cache again, and a one-hour cache write costs twice the input price. On a 400K conversation, that adds up.
The band sits above the prompt: a flame that cools into a snowflake as the hour runs out, the minutes left, two toggles and a Compact button.
Auto cache. Ten minutes before the cache would go cold, it pings it. The ping goes through $.model.fork, which sends the conversation's last request again from a background copy, with a one-line keep-alive at the end. The copy is word for word the same conversation, so the API serves it from the same cache, and that read keeps the cache for another hour. The reply is dropped and nothing is added to your chat. A "hi" typed into the chat would keep the cache warm too, but it stays in the conversation for good, and Claude might act on it.
It stops after 20 pings in a row. A ping reads the cache (0.1x) and a cold restart writes it (2x), so 20 pings cost about what the restart they prevent would, around 16 hours in. Your next message starts it again. If a ping finds the cache already gone, Auto cache pauses instead of paying full price every hour.
Auto compact. It compacts once the conversation passes 400K tokens, right after Claude's reply, while the cache is still warm, so reading the conversation for the summary is cheap. Why 400K:
- Every message re-reads the whole conversation, so at 830K each message costs about twice what it does at 400K.
- The longer the conversation, the more Claude misses (Chroma's context rot study).
- Compacting too early summarizes a long task halfway through, and details get lost. Anthropic's API compaction defaults to 150K (docs). Claude Code's own auto-compact waits until about 83% of the window, around 830K on a 1M window.
- 400K is twice the old 200K window, so a long task fits in one go, at under half the per-message cost of 830K.
Compact. The button runs /compact as if you typed it. The desktop app refuses a mod's direct compaction call, so this is the route that works there.
28 tests cover the gauge, the pings and Auto compact.
Git Sync Band
A band above the prompt with the branch, how far ahead or behind it is, the changed files and when you last pushed. It reads git status every minute and fetches every five, with no credential prompts and without taking git's index lock, so it never gets in the way of Claude's own git.
Before your prompt, it pulls with --ff-only when that can't lose anything, and tells Claude what came in, or why nothing did. Pull, Files and Commit & push run git straight from the band, without a turn in the chat. Commit & push writes the message with one small model call and shows it to you before anything runs. It won't commit files that look like secrets (.env files, keys, credentials).
5 tests cover the band's layouts and the commit flow.
Scout Router
When Claude starts a subagent, Scout Router reads its type and description. Explore agents, and general-purpose agents whose description is about exploring, reading, searching or researching, run on Sonnet. Anything about planning, auditing, reviewing or grading stays on the main model. Agents that write code stay there too, unless you set the plugin's builders option to sonnet. Haiku requests are left alone, since Haiku is already cheaper. Each reroute is logged.
License
MIT
