cache-keeper
Prompt-cache countdown, cost to re-warm, usage limits, cold-cache warnings and one-click handoff → clear & continue.
何をするか
- 欄・プロンプトの上の帯・トーストを描く
- /cache-keeper を足す
- session.compact・session.end・session.start・turn.complete ほか 1 個にフックする
- ターンをまたいで自分の状態を持つ
良いところ
- ネットワークに出ない
- プロセスを起こさない
- TypeScript で書かれている
- エラーを扱う
作り始めるためのコード
2 種類あります。上のデザインから modscode が書いた雛形と、その Mod 自身のコードのうち描いている部分です。
雛形(register.tsx)
import type { Register } from 'claude-code'
// Drawn like cache-keeper by etding (pane, band, status, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/etding-cache-keeper/
// Written by modscode from that reading, not copied from the mod: use it as you like.
// Each value below stands for one the mod works out at run time; put in your own.
export const register: Register = on => {
// the pane: open it with $.ui.open({ id: 'my-pane', title: "Cache keeper" })
on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
const { Box, Text, Button } = $.ui.resolve(e)
const headline = '…'
const ttlLabel = '…'
const ttlSource = '…'
const formatUsd = '…'
const priceSource = '…'
const formatTokens = '…'
const formatTokens2 = '…'
const contextPercent = '…'
const kind = '…'
const percentLeft = '…'
const formatUntil = '…'
const kind2 = '…'
const percentLeft2 = '…'
const kind3 = '…'
const percentLeft3 = '…'
const formatUsd2 = '…'
const autoCompactSummary = '…'
const formatTokens3 = '…'
return (
<Box flexDirection="column">
<Text bold>
{headline}
</Text>
<Text dimColor>
{"TTL "}
{ttlLabel}
{" ("}
{ttlSource}
) · re-warm if cold ≈
{formatUsd}
{" ("}
{priceSource}
{" price)"}
</Text>
<Text>
{" "}
</Text>
<Text>
{"Context "}
{formatTokens}
{" / "}
{formatTokens2}
{` (${contextPercent}%)`}
</Text>
<Text>
{kind}
{" "}
{percentLeft}
% left
{` · resets in ${formatUntil}`}
</Text>
<Text>
{kind2}
{" "}
{percentLeft2}
% left
{` · resets in ${formatUntil}`}
</Text>
<Text>
{kind3}
{" "}
{percentLeft3}
% left
{` · resets in ${formatUntil}`}
</Text>
<Text>
{"Session at API rates "}
{formatUsd2}
</Text>
<Box flexDirection="column" marginTop={1}>
<Text bold>
Auto-compact
</Text>
<Text dimColor>
{autoCompactSummary}
</Text>
</Box>
<Box flexDirection="row" gap={2}>
<Button label={`Sooner −${formatTokens}`} />
<Button label={`Later +${formatTokens}`} />
<Button label="Turn on" />
<Button label="Reset to default" />
</Box>
<Box flexDirection="column" marginTop={1}>
<Text bold>
Actions
</Text>
<Box flexDirection="row" gap={2}>
<Button label="🔥 Keep warm" />
<Button label="📦 Compact now" />
<Button label="🤝 Handoff" />
</Box>
</Box>
<Text color="yellow">
Handoff running…
</Text>
<Box flexDirection="row">
<Text color="green">
Handoff ready (
{formatTokens3}
{" chars) "}
</Text>
<Button label="Clear & continue" variant="primary" />
<Text>
{" "}
</Text>
<Button label="Discard" />
</Box>
</Box>
)
})
// the band above the prompt; what else goes there is drawn under it
on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
const { Box, Text, Button } = $.ui.resolve(e)
const text = '…'
const text2 = '…'
const text3 = '…'
return (
<Box flexDirection="column">
<Box flexDirection="row" justifyContent="space-between">
<Box flexDirection="row" flexGrow={1} flexShrink={1} gap={1}>
<Box flexDirection="row" flexShrink={0} borderStyle="round" borderDimColor paddingX={1} height={1}>
<Text>
{"● "}
</Text>
<Text dimColor>
{text}
</Text>
</Box>
<Box flexDirection="row" flexShrink={0} borderStyle="round" borderDimColor paddingX={1} height={1}>
<Text>
{"● "}
</Text>
<Text dimColor>
{text2}
</Text>
</Box>
<Box flexDirection="row" flexShrink={0} borderStyle="round" borderDimColor paddingX={1} height={1}>
<Text>
{"● "}
</Text>
<Text dimColor>
{text3}
</Text>
</Box>
</Box>
<Box flexDirection="row" flexShrink={0} gap={1}>
<Button label="🔥" />
<Button label="📦" />
<Button label="🤝" />
<Button label="📊" />
</Box>
</Box>
{await next(e)}
</Box>
)
})
on('session.start', async ($, e, next) => {
const formatCountdown = '…'
const formatTokens = '…'
const formatUsd = '…'
const label = '…'
const message = '…'
await $.ui.toast(`Cache goes cold in ${formatCountdown}; re-warming ${formatTokens} tokens would cost ≈${formatUsd}. Keep warm, compact or h…`)
await $.ui.toast(`cache-keeper: ${label} failed: ${message}`)
return next(e)
})
}
Mod 自身のコード
Mod のライセンス(MIT)に従って載せています。全文は下にあります。写すときは著作権表示を残してください。
cache-keeper/hooks/register.tsx 386〜487 行 · ペイン
on('ui.render', { component: 'Pane', requestId: PANE_ID }, async ($, e) => {
const { Box, Button, Text } = $.ui.resolve(e)
const view = await computeView($, config)
const handoff = await read($, handoffAtom)
const ttlLabel = view.ttlMs >= TTL_1H_MS ? '1h' : '5m'
const hasActions = view.phase !== 'running' && view.phase !== 'empty' && handoff.status === 'idle'
// The − / + buttons and "Turn on" start from the point in force, else this model's default.
const compactBase = view.compact.at ?? defaultCompactAt(view.contextWindow) ?? COMPACT_FLOOR_TOKENS
const compactCeiling = view.contextWindow > 0 ? view.contextWindow : Number.POSITIVE_INFINITY
return (
<Box flexDirection="column">
<Text bold color={PHASE_COLOR[view.phase]}>
{headline(view)}
</Text>
<Text dimColor>
TTL {ttlLabel} ({view.ttlSource}) · re-warm if cold ≈{formatUsd(view.rewarmUsd)} ({view.priceSource} price)
</Text>
<Text> </Text>
<Text>
Context {formatTokens(view.contextTokens)} / {formatTokens(view.contextWindow)}
{view.contextPercent !== undefined ? ` (${view.contextPercent}%)` : ''}
</Text>
{view.rateLimits.map(limit => (
<Text>
{LIMIT_LABEL[limit.kind] ?? limit.kind} {percentLeft(limit)}% left
{formatUntil(limit.resetsAt, view.now) ? ` · resets in ${formatUntil(limit.resetsAt, view.now)}` : ''}
</Text>
))}
{view.costUsd !== undefined && <Text>Session at API rates {formatUsd(view.costUsd)}</Text>}
{/* Auto-compact gets its own titled section so its buttons don't read as part of the actions below. */}
<Box flexDirection="column" marginTop={1}>
<Text bold>Auto-compact</Text>
<Text dimColor>{autoCompactSummary(view)}</Text>
</Box>
<Box flexDirection="row" gap={2}>
<Button
key="compact-less"
label={`Sooner −${formatTokens(COMPACT_STEP_TOKENS)}`}
onPress={() =>
runAction($, 'auto-compact', () =>
setSessionCompact($, Math.max(COMPACT_STEP_TOKENS, compactBase - COMPACT_STEP_TOKENS)),
)
}
/>
<Button
key="compact-more"
label={`Later +${formatTokens(COMPACT_STEP_TOKENS)}`}
onPress={() =>
runAction($, 'auto-compact', () =>
setSessionCompact($, Math.min(compactCeiling, compactBase + COMPACT_STEP_TOKENS)),
)
}
/>
<Button
key="compact-toggle"
label={view.compact.at === null ? 'Turn on' : 'Turn off'}
onPress={() =>
runAction($, 'auto-compact', () => setSessionCompact($, view.compact.at === null ? compactBase : 'off'))
}
/>
{view.compact.source === 'session' && (
<Button
key="compact-reset"
label="Reset to default"
onPress={() => runAction($, 'auto-compact', () => setSessionCompact($, null))}
/>
)}
</Box>
{hasActions && (
<Box flexDirection="column" marginTop={1}>
<Text bold>Actions</Text>
<Box flexDirection="row" gap={2}>
<Button key="warm" label="🔥 Keep warm" onPress={() => runAction($, 'keep warm', () => keepWarm($))} />
<Button key="compact" label="📦 Compact now" onPress={() => runAction($, 'compact', () => compactNow($))} />
<Button
key="handoff"
label="🤝 Handoff"
onPress={() => runAction($, 'handoff', () => startHandoff($, config))}
/>
</Box>
</Box>
)}
{handoff.status === 'pending' && <Text color="yellow">Handoff running…</Text>}
{handoff.status === 'ready' && (
<Box flexDirection="row">
<Text color="green">Handoff ready ({formatTokens(handoff.text.length)} chars) </Text>
<Button
key="continue"
label="Clear & continue"
variant="primary"
onPress={() => runAction($, 'clear & continue', () => clearAndContinue($))}
/>
<Text> </Text>
<Button key="discard" label="Discard" onPress={() => runAction($, 'discard', () => discardHandoff($))} />
</Box>
)}
</Box>
)
})cache-keeper/hooks/register.tsx 489〜551 行 · バンド
on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
if (e.props.hasSurvey) return next(e)
const view = await computeView($, config)
const handoff = await read($, handoffAtom)
const { Box, Button, Text } = $.ui.resolve(e)
if (handoff.status === 'ready') {
return (
<Box flexDirection="row" justifyContent="space-between">
<Text color="green">Handoff ready.</Text>
<Box flexDirection="row" flexShrink={0} gap={1}>
<Button
key="band-continue"
label="Clear & continue"
variant="primary"
onPress={() => runAction($, 'clear & continue', () => clearAndContinue($))}
/>
<Button key="band-discard" label="Discard" onPress={() => runAction($, 'discard', () => discardHandoff($))} />
</Box>
</Box>
)
}
// Always-on bar: the figures at a glance, then the actions (hidden before the first reply and while a turn runs).
const hasActions = view.phase !== 'empty' && view.phase !== 'running' && handoff.status === 'idle'
// Figures on the left (growing to fill the row), buttons pinned to the right edge.
return (
<Box flexDirection="row" justifyContent="space-between">
{/*
One outlined pill per group: a faint rounded border, gray text, a small colored dot for status.
height={1} holds the pill to one text row; without it the desktop pads the border well above and below the text.
*/}
<Box flexDirection="row" flexGrow={1} flexShrink={1} gap={1}>
{[...bandChips(view), ...(handoff.status === 'pending' ? [{ text: 'handoff running…', tone: 'warn' as const }] : [])].map(
chip => (
<Box flexDirection="row" flexShrink={0} borderStyle="round" borderDimColor paddingX={1} height={1}>
{TONE_DOT_COLOR[chip.tone] && <Text color={TONE_DOT_COLOR[chip.tone]}>● </Text>}
<Text dimColor>{chip.text}</Text>
</Box>
),
)}
</Box>
{/* One-glyph buttons to save width; the Details pane carries the same actions with word labels. */}
<Box flexDirection="row" flexShrink={0} gap={1}>
{hasActions && view.phase !== 'cold' && (
<Button key="band-warm" label="🔥" onPress={() => runAction($, 'keep warm', () => keepWarm($))} />
)}
{hasActions && (
<Button key="band-compact" label="📦" onPress={() => runAction($, 'compact', () => compactNow($))} />
)}
{hasActions && (
<Button
key="band-handoff"
label="🤝"
onPress={() => runAction($, 'handoff', () => startHandoff($, config))}
/>
)}
<Button key="band-details" label="📊" onPress={() => runAction($, 'details', () => openPane($))} />
</Box>
</Box>
)
})ライセンスの全文(MIT)
MIT License Copyright (c) 2026 etding Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
コードが呼ぶもの
Claude を動かす保存
コードから読み取ったデザイン
読み取ったコミットのソースから描いたもので、動かした結果ではありません。一覧は 3 回描き、条件はデスクトップアプリで描く最初の分岐を取り、動かしたときにだけ決まる値は仮の例(点線の下線)にするか省きます。色と書体はこのサイトのものです。
コードから読めること
2026-10-06 に読んだコミット 6a2ba1b81a49 のソースから。最初のまとまりが載せる条件で、残りは自分で判断するための材料です。後のコミットは、次に読むまで見ていません。
| 載せる条件: 確かめやすいコード | |
|---|---|
| 入口を読んだ | hooks/hooks.json が名指すモジュールをすべて読んだ。cache-keeper/hooks/register.tsx |
| 解析できる | すべてのファイルが TypeScript か JavaScript として解析できる。4 ファイルを解析 |
| コードが Mod の中で完結 | import は Mod 自身のファイルかエンジンのモジュールだけ。パッケージも require もない。コードはすべて Mod の中 |
| 読める | 圧縮した行・eval・new Function・計算した道の import()・符号化した塊がない。圧縮・eval・符号化した塊なし |
| 呼び出しが見える | 通信とプログラム起動はその場で $.http.fetch・$.process.run と書き、他へ渡さない。外への呼び出しはすべてその場の $ で |
| 入れる前に自分で判断する材料 | |
| 描く場所 | コードから読んだ、描く先。ターミナル・デスクトップアプリ・両方・何も描かない(フックだけ: 見張りやプロンプトの書き換え)のどれか。出すだけで、外す理由にはしない。ターミナルとデスクトップアプリに同じように描く |
| 入れる手順 | リポジトリ自身の .claude-plugin/marketplace.json にこの Mod が載っていて、ページに書いた手順でそのマーケットプレイスから入れられるか。リポジトリの .claude-plugin/marketplace.json に載っておらず、入れる手順は出せない |
| Windows のプログラム | $.process で起動するプログラムが Windows にあるか(tail・date・open・osascript・/usr/… などは無い)。Windows にないプログラムを使わない |
| 通信 | fetch の送り先(https のホスト)がコードに書いてあるか。通信なし |
| プログラム | 起動するプログラムの名前がコードに書いてあり、シェル・インタプリタ・通信用の道具でないか。プログラムを起動しない |
| 読んで送る | ファイルや環境変数を読み、かつ通信するか。通信しない |
| ソースの鍵 | ソースに API キーや秘密鍵らしきものがあるか。ソースに鍵なし |
| ライセンス | オープンなライセンス(MIT・Apache-2.0・BSD・ISC・Unlicense・0BSD・CC0)で全文があれば、modscode にコードを載せる。違えばリンクだけ。MIT |
コードの文面を読んだだけで、安全の審査ではありません。動かしてはおらず、起動するプログラムの中で何が起きるかも見えません。入れる前の確認はあなたの役目です。 載せる条件
入れる
入れる前に、必ず自分で確かめてください。Mod はサンドボックスなしで、あなたの権限で動きます。modscode はこのコードの安全を保証しません。下のコードを読み(またはフォルダーで claude plugin validate .)、触るものを見て、読んだコミットを入れてください。
リポジトリの .claude-plugin/marketplace.json にこの Mod が載っていないため、入れる手順は出せません。コードとして読むか、作者の README に従ってください。
Claude に聞く
modscode のコネクタを入れると、Claude がこのデザイン・コードが触るもの・コードを読んで、それをもとに作れます。たとえば:
modscode のデザイン「etding-cache-keeper」をコードごと読んで、同じようなペインを作って似たデザイン
-
Claude に頼む…2h 10m · █████░░░✓ build ✓ build ✓ buildJavaKotlin3 Python■ ok 3 ■ ok 3 ■ ok 3 Razor proven 3 Razor proven 3 Razor proven 3Phases ──────── 3/3build Pythonbuild Pythonbuild Python… 3 more phasesLua ──────── 3/Kotlin■ the whole upgrade Ruby■ build build Ruby■ build build Ruby■ build build Ruby … 3 moreNext ──────── PythonRuby (by hand)Podsclick a button, or ctrl+x tab then Tab, EnterAttention ──────── 3! Scala ! Scala ! Scala … 3 moreSession ──────── okJava
-
Open a file first: /crit-tui file <path>Reopen this one in the crit browser view.Claude に頼む…
-
Claude に頼む…TodayOct 63 left · Mar overdueRemCTL: Sep✓ All done for today.● build3● Fix login ● ⚑Jul · build✓● Fix login ● ⚑Jul · build✓● Fix login ● ⚑Jul · build✓● build3● Fix login ● ⚑Jul · build✓● Fix login ● ⚑Jul · build✓● Fix login ● ⚑Jul · build✓● build3● Fix login ● ⚑Jul · build✓● Fix login ● ⚑Jul · build✓● Fix login ● ⚑Jul · build✓Updated 14:32UndoRefresh
-
Claude に頼む…TO graph› Fix login › Fix login › Fix loginScopeThis featureWhole projectHide done stepsReconnect
-
Claude に頼む…InboxUntitled captureFinishing Open in localvoxtralUntitled captureFinishing Open in localvoxtralUntitled captureFinishing Open in localvoxtral
-
Claude に頼む…InboxUntitled captureFinishing Open in localvoxtralUntitled captureFinishing Open in localvoxtralUntitled captureFinishing Open in localvoxtral