ModsCode / Claude Code Mods / Ranking / cache-meter
cache-meter
Claude Code mod: /keepwarm keeps your prompt cache alive through a break; a countdown, hit rate, context fill and API value above the prompt; and a /tokens dashboard with what caching saved, what fills your context, API errors and cost per…
What it does
- Draws a band above the prompt, a pane, toasts
- Adds /tokens, /keepwarm
- Hooks classic.PostModelSwitch, classic.SessionStart, classic.StopFailure, prompt.submit and 6 more
- Keeps its own state between turns
Good points
- No network calls
- Starts no processes
- Written in TypeScript
- Handles errors
Code to start from
A starter ModsCode writes from the drawing it read, and the mod's own lines that draw, where there are any.
Starter (register.tsx)
import type { Register } from 'claude-code'
// Drawn like cache-meter by Florian Grimmer (pane, band, toast), as ModsCode read it from the mod's code:
// https://modscode.com/claude-mods/mods/florian101010-cache-meter/
// 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 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 label = '…'
const hit = '…'
const icon = '…'
const pct = '…'
const autoText = '…'
const costText = '…'
const rewriteText = '…'
return (
<Box flexDirection="column">
<Box flexDirection="row">
<Text color="success">
{"● "}
</Text>
<Text dimColor>
{"cache "}
</Text>
<Text color="error">
{label}
</Text>
<Text color="success">
{" ↻"}
</Text>
<Text>
{" "}
</Text>
<Text color="warning">
■■■■■■■■
</Text>
<Text color="inactive">
■■■■■■■■
</Text>
<Text>
{" "}
</Text>
<Text bold>
{hit}
</Text>
<Text dimColor>
{" hit · "}
</Text>
<Text>
{icon}
{" "}
</Text>
<Text dimColor>
{"context "}
</Text>
<Text bold>
{pct}
</Text>
<Text dimColor>
{autoText}
</Text>
<Text dimColor>
{costText}
</Text>
<Text color="warning" wrap="truncate-end">
{rewriteText}
</Text>
<Text>
{" "}
</Text>
<Button label="Compact" />
</Box>
{await next(e)}
</Box>
)
})
// the pane: open it with $.ui.open({ id: 'my-pane', title: "Tokens & Cache" })
on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
const { Box, Text, Button } = $.ui.resolve(e)
const row = '…'
const row2 = '…'
const row3 = '…'
const stateWord = '…'
const stateNote = '…'
const label = '…'
const text = '…'
const text2 = '…'
const text3 = '…'
const stake = '…'
const stake2 = '…'
const hhmm = '…'
const pings = '…'
const readTokens = '…'
const remainingLabel = '…'
const text4 = '…'
const text5 = '…'
const text6 = '…'
const sparkline = '…'
const saving = '…'
const usageLine = '…'
const mainSteps = '…'
const usageLine2 = '…'
const subSteps = '…'
const issues = '…'
const coldCount = '…'
const coldWritten = '…'
const written = '…'
const hhmm2 = '…'
const written2 = '…'
const hhmm3 = '…'
const written3 = '…'
const limitName = '…'
const percentUsed = '…'
const resetLabel = '…'
const limitName2 = '…'
const limitName3 = '…'
const hhmm4 = '…'
const hhmm5 = '…'
const hhmm6 = '…'
const input = '…'
const read = '…'
const write = '…'
const output = '…'
const hhmm7 = '…'
const output2 = '…'
const hhmm8 = '…'
const output3 = '…'
const output4 = '…'
const text7 = '…'
const text8 = '…'
const text9 = '…'
const name = '…'
const right = '…'
const pctOf = '…'
const name2 = '…'
const right2 = '…'
const pctOf2 = '…'
const name3 = '…'
const right3 = '…'
const pctOf3 = '…'
const homeShort = '…'
const right4 = '…'
const note = '…'
const homeShort2 = '…'
const right5 = '…'
const note2 = '…'
const homeShort3 = '…'
const right6 = '…'
const note3 = '…'
const deferredMcpTools = '…'
const name4 = '…'
const right7 = '…'
const tools = '…'
const name5 = '…'
const right8 = '…'
const name6 = '…'
const right9 = '…'
const included = '…'
const total = '…'
const tokens = '…'
const map = '…'
const text10 = '…'
const text11 = '…'
const mainSteps2 = '…'
const text12 = '…'
const usd = '…'
const text13 = '…'
const tokensAll = '…'
const text14 = '…'
const text15 = '…'
return (
<Box flexDirection="column">
<Box flexDirection="row" justifyContent="space-between">
<Box flexDirection="row" columnGap={2}>
<Text color="claude" bold>
◉ Cache Meter
</Text>
<Button plain hotkey="1">
<Text color="warning">
Overview
{" !"}
</Text>
</Button>
<Button plain hotkey="2">
<Text color="warning">
Context
{" !"}
</Text>
</Button>
<Button plain hotkey="3">
<Text color="warning">
Health
{" !"}
</Text>
</Button>
</Box>
<Text dimColor wrap="truncate-end">
prompt cache · tokens
</Text>
</Box>
<Box flexDirection="row" columnGap={1}>
<Box flexDirection="column">
<Box borderStyle="round" paddingX={1} flexDirection="column">
<Box flexDirection="row">
<Box flexDirection="column">
<Text bold>
{row}
</Text>
<Text bold>
{row2}
</Text>
<Text bold>
{row3}
</Text>
</Box>
<Box flexDirection="column" marginLeft={2} flexShrink={1}>
<Text wrap="truncate-end">
<Text bold>
{stateWord}
</Text>
<Text dimColor>
{stateNote}
</Text>
</Text>
<Text wrap="truncate-end">
<Text dimColor>
{"hit "}
</Text>
<Text bold>
–
</Text>
<Text dimColor>
{" last · "}
</Text>
<Text bold>
–
</Text>
<Text dimColor>
{" session"}
</Text>
</Text>
<Text dimColor wrap="truncate-end">
{"TTL "}
{label}
</Text>
</Box>
</Box>
<Text wrap="truncate-end">
<Text color="inactive">
{text}
</Text>
<Text color="inactive">
{text2}
</Text>
<Text color="inactive">
{text3}
</Text>
</Text>
<Text color="warning" wrap="truncate-end">
{"next message re-writes ≈ "}
{stake}
</Text>
<Text dimColor wrap="truncate-end">
{"expiry costs a re-write of ≈ "}
{stake2}
{" · ┃ keepwarm pings here"}
</Text>
</Box>
<Box borderStyle="round" borderColor="claude" paddingX={1} flexDirection="column">
<Box flexDirection="row" justifyContent="space-between">
<Text wrap="truncate-end">
<Text color="claude" bold>
↻ Keepwarm on
</Text>
<Text dimColor>
{` until ${hhmm}`}
</Text>
</Text>
<Button plain hotkey="s">
<Text color="claude" bold>
Stop
</Text>
</Button>
</Box>
<Text dimColor wrap="truncate-end">
{`${pings}/12 pings · ${readTokens} read · next ~${remainingLabel}`}
</Text>
</Box>
</Box>
<Box flexDirection="column">
<Box borderStyle="round" borderDimColor paddingX={1} flexDirection="column">
<Box flexDirection="row" justifyContent="space-between">
<Text wrap="truncate-end">
<Text color="claude" bold>
Context
{" "}
</Text>
<Text bold>
–
</Text>
</Text>
<Text dimColor />
</Box>
<Text wrap="truncate-end">
<Text color="suggestion">
{text4}
</Text>
<Text color="suggestion">
{text5}
</Text>
<Text color="suggestion">
{text6}
</Text>
</Text>
<Box flexDirection="row" justifyContent="space-between">
<Text wrap="truncate-end">
<Text color="error">
┃
</Text>
<Text dimColor>
auto-compact off
</Text>
</Text>
<Text dimColor>
{`trend ${sparkline}`}
</Text>
</Box>
</Box>
<Box borderStyle="round" borderDimColor paddingX={1} flexDirection="column">
<Box flexDirection="row" justifyContent="space-between">
<Box flexShrink={0} marginRight={1}>
<Text color="claude" bold>
Session
</Text>
</Box>
<Text bold color="success" wrap="truncate-end">
{`cache saved ${saving}%`}
</Text>
</Box>
<Text dimColor wrap="truncate-end">
{usageLine}
</Text>
<Text wrap="truncate-end">
<Text dimColor>
{mainSteps}
{" requests · "}
</Text>
<Text bold>
–
</Text>
<Text dimColor />
</Text>
<Text dimColor wrap="truncate-end">
{"subagents "}
{usageLine2}
{" · "}
{subSteps}
{" requests"}
</Text>
<Text color="warning" wrap="truncate-end">
{issues}
{" – see 3: Health"}
</Text>
<Box flexDirection="column">
<Text wrap="truncate-end">
<Text dimColor>
{"Cold "}
</Text>
<Text color="warning" bold>
{"Total "}
{coldCount}
{"× · "}
{coldWritten}
{" tokens"}
</Text>
<Text dimColor>
{" · /keepwarm before a break prevents this"}
{" · showing the last 3"}
</Text>
</Text>
<Text wrap="truncate-end">
<Text dimColor>
{" "}
{hhmm}
{" "}
</Text>
<Text color="warning">
{written}
</Text>
<Text dimColor>
{" "}
re-written
{" (after a model switch)"}
</Text>
</Text>
<Text wrap="truncate-end">
<Text dimColor>
{" "}
{hhmm2}
{" "}
</Text>
<Text color="warning">
{written2}
</Text>
<Text dimColor>
{" "}
re-written
{" (after a model switch)"}
</Text>
</Text>
<Text wrap="truncate-end">
<Text dimColor>
{" "}
{hhmm3}
{" "}
</Text>
<Text color="warning">
{written3}
</Text>
<Text dimColor>
{" "}
re-written
{" (after a model switch)"}
</Text>
</Text>
</Box>
<Text dimColor wrap="truncate-end">
Plan limits: no reading (no subscription, or no answer yet)
</Text>
<Text wrap="truncate-end">
<Text dimColor>
{limitName}
</Text>
<Text color="error">
████████
</Text>
<Text color="inactive">
░░░░░░░░
</Text>
<Text bold>
{" "}
{`${percentUsed}%`}
</Text>
<Text dimColor>
{` · resets ${resetLabel}`}
</Text>
</Text>
<Text wrap="truncate-end">
<Text dimColor>
{limitName2}
</Text>
<Text color="error">
████████
</Text>
<Text color="inactive">
░░░░░░░░
</Text>
<Text bold>
{" "}
{`${percentUsed}%`}
</Text>
<Text dimColor>
{` · resets ${resetLabel}`}
</Text>
</Text>
<Text wrap="truncate-end">
<Text dimColor>
{limitName3}
</Text>
<Text color="error">
████████
</Text>
<Text color="inactive">
░░░░░░░░
</Text>
<Text bold>
{" "}
{`${percentUsed}%`}
</Text>
<Text dimColor>
{` · resets ${resetLabel}`}
</Text>
</Text>
</Box>
</Box>
</Box>
<Box borderStyle="round" borderDimColor paddingX={1} flexDirection="column">
<Box flexDirection="row" justifyContent="space-between">
<Box flexShrink={0} marginRight={1}>
<Text color="claude" bold>
Requests
</Text>
</Box>
<Text dimColor wrap="truncate-end">
height = share not from cache · blue = first write · newest right
</Text>
</Box>
<Text dimColor>
No request measured yet.
</Text>
<Box flexDirection="row" justifyContent="space-between">
<Text dimColor>
{hhmm4}
</Text>
<Text dimColor>
{hhmm5}
</Text>
</Box>
<Text wrap="truncate-end">
<Text dimColor>
{hhmm6}
{" "}
</Text>
<Text>
{`${input}${read}${write}`}
{" "}
</Text>
<Text bold>
–
</Text>
<Text dimColor>
{" hit · out "}
{output}
</Text>
</Text>
<Text wrap="truncate-end">
<Text dimColor>
{hhmm7}
{" "}
</Text>
<Text>
{`${input}${read}${write}`}
{" "}
</Text>
<Text bold>
–
</Text>
<Text dimColor>
{" hit · out "}
{output2}
</Text>
</Text>
<Text wrap="truncate-end">
<Text dimColor>
{hhmm8}
{" "}
</Text>
<Text>
{`${input}${read}${write}`}
{" "}
</Text>
<Text bold>
–
</Text>
<Text dimColor>
{" hit · out "}
{output3}
</Text>
</Text>
<Text wrap="truncate-end">
<Text dimColor>
{"last "}
{`${input}${read}${write}`}
{" in · "}
</Text>
<Text bold>
–
</Text>
<Text dimColor>
{" hit · out "}
{output4}
</Text>
</Text>
</Box>
<Box flexDirection="column">
<Box borderStyle="round" borderDimColor paddingX={1} flexDirection="column">
<Box flexDirection="row" justifyContent="space-between">
<Text wrap="truncate-end">
<Text color="claude" bold>
Context
{" "}
</Text>
<Text bold>
–
</Text>
</Text>
<Text dimColor />
</Box>
<Text wrap="truncate-end">
<Text color="suggestion">
{text7}
</Text>
<Text color="suggestion">
{text8}
</Text>
<Text color="suggestion">
{text9}
</Text>
</Text>
<Box flexDirection="row" justifyContent="space-between">
<Text wrap="truncate-end">
<Text color="error">
┃
</Text>
<Text dimColor>
auto-compact off
</Text>
</Text>
<Text dimColor>
{`trend ${sparkline}`}
</Text>
</Box>
</Box>
<Box borderStyle="round" borderDimColor paddingX={1} flexDirection="column">
<Box flexDirection="row" justifyContent="space-between">
<Box flexShrink={0} marginRight={1}>
<Text color="claude" bold>
Where it goes
</Text>
</Box>
<Text dimColor wrap="truncate-end">
no reading yet
</Text>
</Box>
<Text dimColor>
Claude Code reports it after the first answer.
</Text>
<Box flexDirection="row">
<Box>
<Text wrap="truncate-start">
{name}
</Text>
</Box>
<Text color="suggestion">
{" "}
████████
</Text>
<Text>
{" "}
</Text>
<Text bold>
{" "}
{right}
</Text>
<Text dimColor wrap="truncate-end">
{pctOf}
</Text>
</Box>
<Box flexDirection="row">
<Box>
<Text wrap="truncate-start">
{name2}
</Text>
</Box>
<Text color="suggestion">
{" "}
████████
</Text>
<Text>
{" "}
</Text>
<Text bold>
{" "}
{right2}
</Text>
<Text dimColor wrap="truncate-end">
{pctOf2}
</Text>
</Box>
<Box flexDirection="row">
<Box>
<Text wrap="truncate-start">
{name3}
</Text>
</Box>
<Text color="suggestion">
{" "}
████████
</Text>
<Text>
{" "}
</Text>
<Text bold>
{" "}
{right3}
</Text>
<Text dimColor wrap="truncate-end">
{pctOf3}
</Text>
</Box>
<Box flexDirection="row" justifyContent="space-between">
<Text dimColor wrap="truncate-end">
Exact count: one API request per tool and memory file, as /context
</Text>
<Box flexShrink={0} marginLeft={2}>
<Button plain hotkey="x">
<Text color="claude" bold>
Count exactly
</Text>
</Button>
</Box>
</Box>
</Box>
<Box borderStyle="round" borderDimColor paddingX={1} flexDirection="column">
<Text color="claude" bold>
Heaviest items
</Text>
<Text dimColor>
Memory files (CLAUDE.md and rules)
</Text>
<Text dimColor>
{" none"}
</Text>
<Box flexDirection="row">
<Box>
<Text wrap="truncate-start">
{homeShort}
</Text>
</Box>
<Text color="suggestion">
{" "}
████████
</Text>
<Text>
{" "}
</Text>
<Text bold>
{" "}
{right4}
</Text>
<Text dimColor wrap="truncate-end">
{note}
</Text>
</Box>
<Box flexDirection="row">
<Box>
<Text wrap="truncate-start">
{homeShort2}
</Text>
</Box>
<Text color="suggestion">
{" "}
████████
</Text>
<Text>
{" "}
</Text>
<Text bold>
{" "}
{right5}
</Text>
<Text dimColor wrap="truncate-end">
{note2}
</Text>
</Box>
<Box flexDirection="row">
<Box>
<Text wrap="truncate-start">
{homeShort3}
</Text>
</Box>
<Text color="suggestion">
{" "}
████████
</Text>
<Text>
{" "}
</Text>
<Text bold>
{" "}
{right6}
</Text>
<Text dimColor wrap="truncate-end">
{note3}
</Text>
</Box>
<Text dimColor wrap="truncate-end">
MCP servers
{` · ${deferredMcpTools} more tools behind tool search, not loaded`}
</Text>
<Text dimColor>
{" none loaded"}
</Text>
<Box flexDirection="row">
<Box>
<Text wrap="truncate-start">
{name4}
</Text>
</Box>
<Text color="suggestion">
{" "}
████████
</Text>
<Text>
{" "}
</Text>
<Text bold>
{" "}
{right7}
</Text>
<Text dimColor wrap="truncate-end">
{` · ${tools} tools`}
</Text>
</Box>
<Box flexDirection="row">
<Box>
<Text wrap="truncate-start">
{name5}
</Text>
</Box>
<Text color="suggestion">
{" "}
████████
</Text>
<Text>
{" "}
</Text>
<Text bold>
{" "}
{right8}
</Text>
<Text dimColor wrap="truncate-end">
{` · ${tools} tools`}
</Text>
</Box>
<Box flexDirection="row">
<Box>
<Text wrap="truncate-start">
{name6}
</Text>
</Box>
<Text color="suggestion">
{" "}
████████
</Text>
<Text>
{" "}
</Text>
<Text bold>
{" "}
{right9}
</Text>
<Text dimColor wrap="truncate-end">
{` · ${tools} tools`}
</Text>
</Box>
<Text wrap="truncate-end">
<Text dimColor>
{"Skills "}
</Text>
<Text>
<Text bold color="warning">
{included}
{" of "}
{total}
</Text>
<Text dimColor>
{" listed · "}
{tokens}
{" tokens"}
</Text>
<Text dimColor>
{" · the rest did not fit the listing budget"}
</Text>
</Text>
</Text>
<Text dimColor wrap="truncate-end">
{"Agents "}
{map}
</Text>
</Box>
</Box>
<Box flexDirection="column">
<Box borderStyle="round" borderDimColor paddingX={1} flexDirection="column">
<Text color="claude" bold>
Session
</Text>
<Text wrap="truncate-end">
<Text dimColor>
{text10}
</Text>
<Text bold>
–
</Text>
<Text dimColor />
</Text>
<Text wrap="truncate-end">
<Text dimColor>
{text11}
</Text>
<Text bold>
–
</Text>
<Text dimColor>
{" · "}
{mainSteps2}
{" requests"}
</Text>
</Text>
<Text wrap="truncate-end">
<Text dimColor>
{text12}
</Text>
<Text bold>
–
</Text>
<Text dimColor>
{` · $${usd}/h`}
{` · $${usd}/prompt`}
</Text>
</Text>
<Text wrap="truncate-end">
<Text dimColor>
{text13}
</Text>
<Text bold>
{tokensAll}
</Text>
<Text dimColor>
{" per prompt (main conversation, in + out)"}
</Text>
</Text>
</Box>
<Box borderStyle="round" borderDimColor paddingX={1} flexDirection="column">
<Text color="claude" bold>
Requests
</Text>
<Text wrap="truncate-end">
<Text dimColor>
{text14}
</Text>
<Text color="success">
all normal
</Text>
</Text>
<Text wrap="truncate-end">
<Text dimColor>
{text15}
</Text>
<Text color="success" />
</Text>
</Box>
</Box>
</Box>
)
})
on('session.start', async ($, e, next) => {
const message = '…'
const pings = '…'
await $.ui.toast(`Exact count failed: ${message}`)
await $.ui.toast(`Keepwarm finished (${pings} pings)`)
return next(e)
})
}
The mod's own code
Shown under the mod's licence (MIT); its text is below. Keep the notice if you copy these lines.
hooks/register.tsx lines 660–756 · Band
on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
// What the mods after this one draw: kept beneath this row (interface § Pick where to draw › Band).
const theirs = await next(e)
if (e.viewport?.isFullscreen === true) isFullscreenSeen = true
if (e.props.hasSurvey) return theirs
const measure = await read($, measureA)
const cache = await read($, cacheA)
const keep = await read($, keepA)
const ttl = await ttlNow($)
const now = await $.clock.now()
const status = cacheStatus(cache, now, ttl.ms)
const { Box, Button, Text } = $.ui.resolve(e)
const cols = e.props.bodyColumns
const percent = measure?.percent ?? null
const auto = measure?.autoCompactPct ?? null
const isKeeping = keep.until !== null && keep.until > now
const isLow = status.kind === 'warm' && status.remaining <= ttl.ms * PING_SHARE
const sky = percent === null ? null : forecast(percent, auto)
const showButton = !e.props.isWorking
// Every segment's width, so the row never wraps (AbovePrompt.bodyColumns).
const label = status.kind === 'warm' ? remainingLabel(status.remaining) : status.kind === 'empty' ? 'empty' : 'expired'
const hit = cache === null || cache.hitPct === null ? '–' : `${cache.hitPct}%`
const pct = percent === null ? '–' : `${percent}%`
const autoText = measure?.isAutoCompactOff ? ' (auto-compact off)' : auto === null ? '' : ` (auto-compact ${auto}%)`
const rewriteTokens = measure?.tokens ?? cache?.contextTokens ?? 0
const rewriteText =
status.kind === 'expired' && cache !== null && rewriteTokens > 0
? ` · rewrite ${cache.rewriteUsd !== null ? `≈ $${cache.rewriteUsd.toFixed(2)}` : `≈ ${short(rewriteTokens)} tok`}`
: isLow && !isKeeping && isInteractive
? ' · /keepwarm?'
: ''
const base =
'● cache '.length +
label.length +
(isKeeping ? 2 : 0) +
1 +
hit.length +
' hit · '.length +
(sky ? 2 : 0) +
'context '.length +
pct.length +
(showButton ? '[ Compact ]'.length + 1 : 0)
// Claude Code's own cost figure, the one /cost shows: on a subscription a comparison value (what an
// API key would pay), on an API key or a cloud provider real spend. Hidden at $0.00.
const usd = measure?.usd ?? null
const costText = usd === null || usd < 0.005 ? '' : isPlan(measure) ? ` · API value $${usd.toFixed(2)}` : ` · spent $${usd.toFixed(2)}`
const minBar = 6
const showRewrite = rewriteText !== '' && base + rewriteText.length + autoText.length + minBar < cols
const showAuto = autoText !== '' && base + autoText.length + (showRewrite ? rewriteText.length : 0) + minBar < cols
// Dropped first when the row gets narrow: after it the auto-compact point, then the bar.
const showCost =
costText !== '' && base + costText.length + (showAuto ? autoText.length : 0) + (showRewrite ? rewriteText.length : 0) + minBar < cols
const free =
cols - base - (showAuto ? autoText.length : 0) - (showRewrite ? rewriteText.length : 0) - (showCost ? costText.length : 0) - 1
const cells = free >= minBar ? Math.min(20, free) : 0
const lit = status.kind === 'warm' ? litCells(status.remaining, ttl.ms, cells) : 0
const mine = (
<Box flexDirection="row">
<Text color={status.kind === 'warm' ? 'success' : 'error'}>● </Text>
<Text dimColor>cache </Text>
<Text color={status.kind === 'warm' ? (isLow ? 'warning' : 'success') : 'error'} bold={status.kind === 'warm'}>
{label}
</Text>
{isKeeping && <Text color="success"> ↻</Text>}
<Text> </Text>
{cells > 0 && <Text color={isLow ? 'warning' : 'success'}>{'■'.repeat(lit)}</Text>}
{cells > 0 && <Text color="inactive">{'■'.repeat(cells - lit)}</Text>}
{cells > 0 && <Text> </Text>}
<Text bold color={hitColor(cache?.hitPct ?? null)}>
{hit}
</Text>
<Text dimColor> hit · </Text>
{sky && <Text color={sky.color}>{sky.icon} </Text>}
<Text dimColor>context </Text>
<Text bold>{pct}</Text>
{showAuto && <Text dimColor>{autoText}</Text>}
{showCost && <Text dimColor>{costText}</Text>}
{showRewrite && (
<Text color={status.kind === 'expired' ? 'warning' : 'claude'} wrap="truncate-end">
{rewriteText}
</Text>
)}
{showButton && <Text> </Text>}
{showButton && <Button key="compact" label="Compact" onPress={() => compactNow($)} />}
</Box>
)
return (
<Box flexDirection="column">
{mine}
{theirs}
</Box>
)
})hooks/register.tsx lines 758–917 · Pane
on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
const elements = $.ui.resolve(e)
const { Box, Button, Text } = elements
seat = e.props.placement
// Raster (colored cells) is drawn by the terminal only (reference › Elements); elsewhere text.
const Raster = 'Raster' in elements ? elements.Raster : null
const steps = await read($, stepsA)
const totals: Totals = await read($, totalsA)
const measure = await read($, measureA)
const cache = await read($, cacheA)
const keep: KeepWarm = await read($, keepA)
const colds = await read($, coldA)
const map = await read($, contextMapA)
const health: Health = await read($, healthA)
const ttl = await ttlNow($)
const now = await $.clock.now()
const status = cacheStatus(cache, now, ttl.ms)
// Three widths: a narrow dock (about 48 body columns beside a 120-column terminal) drops the
// secondary text; from 110 the cards sit in two columns, so the pane also needs fewer rows.
const cols = e.props.bodyColumns
const tier = cols < 64 ? 'narrow' : cols < 110 ? 'medium' : 'wide'
const left = tier === 'wide' ? Math.floor((cols - 1) / 2) : cols
const rightW = tier === 'wide' ? cols - 1 - left : cols
// A card has a round border and one column of padding on each side: 4 columns of chrome.
const leftIn = Math.max(16, left - 4)
const rightIn = Math.max(16, rightW - 4)
const fullIn = Math.max(16, cols - 4)
// A one-row meter: Raster cells in the terminal, the same runs as colored text elsewhere.
const gauge = (key: string, width: number, fraction: number, fill: number, theme: string, marks: readonly Mark[] = []) => {
const runs = meterRuns(width, fraction, marks)
return Raster ? (
<Raster key={key} columns={width} rows={1} cells={rasterCells(meterCells(runs, fill, marks))} />
) : (
<Text wrap="truncate-end">
{runs.map(r => (
<Text color={r.role === 'fill' ? theme : r.role === 'track' ? 'inactive' : marks[r.role]?.theme}>{r.text}</Text>
))}
</Text>
)
}
// --- cache --------------------------------------------------------------------------------
const isWarm = status.kind === 'warm'
const isLow = isWarm && status.remaining <= ttl.ms * PING_SHARE
const stateColor = isWarm ? (isLow ? 'warning' : 'success') : 'error'
const remaining = isWarm ? status.remaining : 0
const isSeconds = isWarm && remaining < 60_000
const digits = tall(isWarm ? String(Math.ceil(remaining / (isSeconds ? 1000 : 60_000))) : '--')
const lastAt = cache !== null && cache.lastAt > 0 ? cache.lastAt : null
const stateWord = isWarm ? 'WARM' : status.kind === 'empty' ? 'EMPTY' : 'EXPIRED'
const stateNote = isWarm
? ` · ${isSeconds ? 's' : 'min'} left${lastAt === null || tier === 'narrow' ? '' : ` · until ${hhmm(lastAt + ttl.ms)}`}`
: status.kind === 'empty'
? ' · waiting for the first answer'
: lastAt === null
? ''
: ` · since ${hhmm(lastAt + ttl.ms)}`
const sessionHit = hitPct(totals.main)
const rewriteTokens = measure?.tokens ?? cache?.contextTokens ?? 0
const stake =
cache?.rewriteUsd != null ? `$${cache.rewriteUsd.toFixed(2)} (${short(rewriteTokens)} tokens)` : `${short(rewriteTokens)} tokens`
// Keepwarm pings once PING_SHARE of the TTL is left: the marker shows that point on the countdown.
const canKeep = isInteractive && isWarm && ttl.ms >= HOUR
const isKeeping = keep.until !== null && keep.until > now
const pingMarks: Mark[] = canKeep || isKeeping ? [{ at: markAt(PING_SHARE, leftIn), color: 0xd97757, theme: 'claude' }] : []
const cacheCard = (
<Box borderStyle="round" borderColor={stateColor} paddingX={1} flexDirection="column">
<Box flexDirection="row">
<Box flexDirection="column">
{digits.map(row => (
<Text color={stateColor} bold>
{row}
</Text>
))}
</Box>
<Box flexDirection="column" marginLeft={2} flexShrink={1}>
<Text wrap="truncate-end">
<Text color={stateColor} bold>
{stateWord}
</Text>
<Text dimColor>{stateNote}</Text>
</Text>
<Text wrap="truncate-end">
<Text dimColor>hit </Text>
<Text bold color={hitColor(cache?.hitPct ?? null)}>
{cache?.hitPct == null ? '–' : `${cache.hitPct}%`}
</Text>
{tier !== 'narrow' && <Text dimColor> last · </Text>}
{tier !== 'narrow' && (
<Text bold color={hitColor(sessionHit)}>
{sessionHit === null ? '–' : `${sessionHit}%`}
</Text>
)}
{tier !== 'narrow' && <Text dimColor> session</Text>}
</Text>
<Text dimColor wrap="truncate-end">
TTL {ttl.label}
{tier === 'narrow' ? '' : ` · ${ttl.source}`}
</Text>
</Box>
</Box>
{gauge('countdown', leftIn, isWarm ? remaining / ttl.ms : 0, isWarm ? (isLow ? FILL.low : FILL.warm) : FILL.cold, stateColor, pingMarks)}
{status.kind === 'expired' && rewriteTokens > 0 && (
<Text color="warning" wrap="truncate-end">
next message re-writes ≈ {stake}
</Text>
)}
{isWarm && rewriteTokens > 0 && (
<Text dimColor wrap="truncate-end">
expiry costs a re-write of ≈ {stake}
{pingMarks.length > 0 && tier !== 'narrow' ? ' · ┃ keepwarm pings here' : ''}
</Text>
)}
</Box>
)
// --- keepwarm -----------------------------------------------------------------------------
const pingIn = isWarm ? Math.max(0, remaining - ttl.ms * PING_SHARE) : 0
const keepCard = (
<Box borderStyle="round" borderColor="claude" borderDimColor={!isKeeping} paddingX={1} flexDirection="column">
<Box flexDirection="row" justifyContent="space-between">
<Text wrap="truncate-end">
<Text color="claude" bold>
{isKeeping ? '↻ Keepwarm on' : '↻ Keepwarm'}
</Text>
<Text dimColor>
{isKeeping && keep.until !== null ? ` until ${hhmm(keep.until)}` : ` off${keep.pings > 0 && tier !== 'narrow' ? ` · last run ${keep.pings} pings` : ''}`}
</Text>
</Text>
{isKeeping ? (
<Button key="keepwarm-stop" plain hotkey="s" onPress={() => pressKeepWarm($, null)}>
<Text color="claude" bold>
Stop
</Text>
</Button>
) : (
canKeep && (
<Button key="keepwarm-start" plain hotkey="w" onPress={() => pressKeepWarm($, 2 * HOUR)}>
<Text color="claude" bold>
Keep warm 2h
</Text>
</Button>
)
)}
</Box>
<Text dimColor wrap="truncate-end">
{isKeeping
? `${keep.pings}/${MAX_PINGS} pings · ${short(keep.readTokens)} read · next ~${remainingLabel(pingIn)}`
: canKeep
? 'Break ahead? A ping ≈ 1/20 of a re-write.'
: !isInteractive
? 'Interactive sessions only.'
: ttl.ms < HOUR
? `Not worth it at a ${ttl.label} TTL.`
: 'Available once the cache is warm.'}
</Text>Licence text (MIT)
MIT License Copyright (c) 2026 Florian Grimmer 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.
How to build this: Pane (panel), Rewrite the prompt
What its code calls
env varsdrives Clauderemembers
What its code shows
Read from the source at commit 92aef393a380. The first group decides whether a mod is listed; the rest is for you to weigh. A later commit is not read until the next crawl.
| Decides the listing: code you can check | |
|---|---|
| Entry read | Every module hooks/hooks.json names was read.hooks/register.tsx |
| Parses | Every file parses as TypeScript or JavaScript.2 files parsed |
| All its code is in the mod | Every import is a file of the mod or the engine's own module; no packages, no require.all its code is in the mod |
| Readable | No minified lines, no eval or new Function, no import of a computed path, no encoded blobs.no minified code, no eval, no encoded blobs |
| Calls in the open | Network and programs are reached as $.http.fetch and $.process.run in place, never passed around.every call outside goes through $ in the open |
| For you to weigh before installing | |
| Where it draws | The terminal, the desktop app, both, or nothing (hooks only: a guard or a prompt rewriter), as its code says. Shown, never a reason to leave a mod out.draws in the terminal and the desktop app, the same in both |
| Install line | Whether its repository's own .claude-plugin/marketplace.json lists it, so it installs from that marketplace with the lines on its page.listed in its repository's .claude-plugin/marketplace.json: installs from there |
| Programs on Windows | Whether every program it starts through $.process exists on Windows (tail, date, open, osascript, /usr/… do not).runs no program a Windows PC lacks |
| Network | Whether every fetch names its https host in the code.no network |
| Programs | Whether every program it starts is named in the code and is not a shell, an interpreter or a network tool.starts no programs |
| Reads and sends | Whether it both reads something of yours (files, environment variables, the transcript, settings) and reaches outside (the network, an MCP server, another session, telemetry).reads environment variables, settings.json, but reaches nothing outside |
| Keys in the source | Whether the source holds what looks like an API key or a private key.no keys in the source |
| Licence | An open licence (MIT, Apache-2.0, BSD, ISC, Unlicense, 0BSD, CC0) with its text lets ModsCode show its code; otherwise the code is linked.MIT |
| Settings hooks | Hooks declared in hooks/hooks.json or plugin.json beside the module: a command (a shell when it has no args), an HTTP request, an MCP tool or a model prompt at an event. They run outside $.no settings hooks: its function hooks alone |
| Servers it ships | MCP servers (a program, or a URL; a headersHelper is a shell command; a .mcpb bundle is unpacked at run time), LSP servers, monitors (a shell command for the whole session) and bin/ (on the PATH of the Bash tool).ships no MCP or LSP server, no monitor, no bin/ |
| Skills, commands, agents | What its Markdown declares beyond text: allowed-tools granted for the turn, hooks added when a skill is invoked, a command run before Claude reads the skill.no skills, commands, agents or workflows |
| Tools and MCP | Whether every tool it calls through $.tool.call and $.mcp.call is named in the code, and none is a shell (Bash through the tool runs a shell without $.process).calls no tool, MCP server or command |
| Asks of the model | Completions it runs ($.model.complete, fork, classify), subagents it spawns, prompts it submits as you, and the tools, commands and agents it adds.model.fork (sends its own transcript), adds command tokens, adds command keepwarm |
| Events it hooks | By what a hook there can do: gates (refuse a tool call, a prompt, a setting, another plugin), shapes (what the model reads: the system prompt, tool descriptions, each request), reads (your input, the events of the settings hooks, every event with *), and the rest.gates: command.run (tokens, keepwarm), prompt.submit · shapes: turn.step · reads: classic.SessionStart, classic.StopFailure, classic.PostModelSwitch · also: session.start, turn.complete, session.measure, session.compact (+2) · timers: clock.every, clock.after |
| Reads, by name | The environment variables and files it names, and whether it reads the transcript, settings.json, the prompt box or the mouse selection.env: FORCE_PROMPT_CACHING_5M, CLAUDE_CODE_PROMPT_CACHE_TTL, ENABLE_PROMPT_CACHING_1H; settings.json |
| Writes, by name | The files and environment variables it names, and whether it changes settings, the prompt box, the clipboard, the conversation (a row the model reads) or another session.writes no files, environment variables, settings or conversation rows |
This is a reading of the code text, not a security review: it does not run the mod, and it cannot see what a program the mod starts does. The check before installing is yours. How mods are chosen
Install it
Check it yourself before you install it. Mods run unsandboxed, with your permissions, and ModsCode does not vouch for what this code does. Read its code (or run claude plugin validate . in its folder), weigh what it reaches, and install the commit you read.
From its marketplace
Its repository is its marketplace. Add that marketplace (in the terminal with these commands, or in the desktop app's plugin settings) and install the mod from it:
/plugin marketplace add florian101010/cache-meter/plugin install cache-meter@cache-meter/reload-pluginsThis installs the marketplace's latest commit, which may not be the one read here (92aef393a380). Compare them before you install. /reload-plugins loads it into a session that is already open.
Try the commit ModsCode read
No marketplace needed. In a terminal, clone the repository, check out the commit read, validate the mod, and load it for one session:
git clone https://github.com/florian101010/cache-metergit -C cache-meter checkout 92aef393a380ba95090e59fbacc514c66d01b31eclaude plugin validate cache-meterclaude --plugin-dir cache-meterThe validate line lists the events the mod hooks and what it asks Claude Code to do, without running it. The last line loads the mod for this session only and writes nothing to your settings. If the author has rewritten history, the commit may no longer exist.
Ask Claude or ChatGPT about it
With ModsCode added as a connector, Claude or ChatGPT can read this mod's code, what it reaches and how its controls are wired, and build on them. Ask it like this:
Read the ModsCode mod "florian101010-cache-meter" with its code and make me one like itAdd the ModsCode MCP to Claude or ChatGPT
Similar mods
- code-modernizationAnthropic★ 37,809
- crit-tuiTomasz Tomczyk★ 1,205
- ai-maestro-secrets23blocks-OS★ 820
- remctlFederico Viticci★ 595
- agent-radarHamza Zafar★ 228
- task-orchestrator-modJeff Picklyk★ 208
Badge for your README
If this is your mod, paste this into your README. It links to this page.
[](https://modscode.com/claude-mods/mods/florian101010-cache-meter/)