context-gauge
Context, 5h/7d limits, cost, thinking time, tool timeline and a Stop button above the prompt; a foldable side pane; opt-in auto wrap-up near the limit
何をするか
- プロンプトの上の帯・欄・トーストを描く
- /gauge を足す
- ツールの呼び出しを見張る(止めることがある)
- config.set・session.append・session.measure・session.start ほか 4 個にフックする
- ターンをまたいで自分の状態を持つ
良いところ
- プロセスを起こさない
- TypeScript で書かれている
- デスクトップ専用の分岐がある
- エラーを扱う
作り始めるためのコード
2 種類あります。上のデザインから modscode が書いた雛形と、その Mod 自身のコードのうち描いている部分です。
雛形(register.tsx)
import type { Register } from 'claude-code'
// Drawn like context-gauge by kirishimarisano-rgb (pane, band, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/kirishimarisano-rgb-context-gauge/
// 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, Svg, Client } = $.ui.resolve(e)
const label = '…'
const dur = '…'
const drawn = '…'
const alt = '…'
const name = '…'
const pill = '…'
const slotLabel = '…'
const outputStyle = '…'
const error = '…'
const dur2 = '…'
const status = '…'
const name2 = '…'
const status2 = '…'
const name3 = '…'
const status3 = '…'
const name4 = '…'
const status4 = '…'
const name5 = '…'
const status5 = '…'
const name6 = '…'
const status6 = '…'
const PHASE = '…'
const dur3 = '…'
const dur4 = '…'
const dur5 = '…'
const tps = '…'
const name7 = '…'
const dur6 = '…'
return (
<Box flexDirection="column">
<Box flexDirection="row" flexWrap="wrap">
<Text>
{label}
{" "}
</Text>
<Text dimColor>
{"wrap-up prompt in "}
{dur}
{" "}
</Text>
<Button label="Cancel" hotkey="c" />
<Text>
{" "}
</Text>
<Button label="Send now" dimColor />
</Box>
<Box flexDirection="row" alignItems="center" gap={2}>
<Box flexGrow={1} flexShrink={1} minWidth={10} overflow="hidden">
<Svg source={`${drawn}`} alt={`${alt}`} />
</Box>
<Box flexDirection="row" alignItems="center" gap={2} flexShrink={0}>
<Box flexDirection="row" gap={1} flexShrink={0}>
<Client module="./slider.tsx" />
<Button label={`⚡ ${name} ⌄`} plain />
</Box>
<Box flexDirection="row" gap={1}>
<Button label="◉" plain dimColor />
<Text>
●
</Text>
<Button label="≡" plain dimColor />
</Box>
<Button label="⚙" plain dimColor />
</Box>
</Box>
<Box flexDirection="column" borderStyle="round" paddingX={1}>
<Box flexDirection="row" gap={2} alignItems="center">
<Svg source={`${pill}`} alt="position none" />
<Button label={`⊘ ${slotLabel}`} plain />
<Button label={`⊘ ${slotLabel}`} plain />
<Button label={`⊘ ${slotLabel}`} plain />
</Box>
<Box flexDirection="row" gap={2}>
<Button label="⚡ Fast on" plain />
<Button label={`Style: ${outputStyle}`} plain dimColor />
<Button label="Edit positions" plain dimColor />
<Button label="✕" plain dimColor />
</Box>
</Box>
<Box flexDirection="column" borderStyle="round" paddingX={1}>
<Box flexDirection="row" gap={2}>
<Text bold>
Claude status & usage
</Text>
<Text>
{`check failed: ${error}`}
</Text>
<Text dimColor>
{"· "}
{dur2}
{" ago"}
</Text>
<Button label="↻ Refresh" plain />
<Button label="✕" plain dimColor />
</Box>
<Box flexDirection="row" flexWrap="wrap" gap={2}>
<Box flexDirection="row">
<Text>
{"● "}
</Text>
<Text dimColor>
{name}
{" "}
{status}
</Text>
</Box>
<Box flexDirection="row">
<Text>
{"● "}
</Text>
<Text dimColor>
{name2}
{" "}
{status2}
</Text>
</Box>
<Box flexDirection="row">
<Text>
{"● "}
</Text>
<Text dimColor>
{name3}
{" "}
{status3}
</Text>
</Box>
</Box>
<Text wrap="truncate">
{`Usage: ${error}`}
</Text>
<Text wrap="truncate">
{"⚠ "}
{name4}
{" ("}
{status4}
)
</Text>
<Text wrap="truncate">
{"⚠ "}
{name5}
{" ("}
{status5}
)
</Text>
<Text wrap="truncate">
{"⚠ "}
{name6}
{" ("}
{status6}
)
</Text>
</Box>
<Box flexDirection="row" flexWrap="wrap">
<Text>
{PHASE}
{" "}
</Text>
<Text>
{dur3}
</Text>
<Text>
{" │ "}
</Text>
<Text dimColor>
{"turn "}
{dur4}
</Text>
<Text dimColor>
{" · think "}
{dur5}
</Text>
<Text dimColor>
{" · "}
{tps}
{" tok/s"}
</Text>
<Text dimColor>
{" · "}
{name7}
{" "}
{dur6}
</Text>
<Text>
{" "}
</Text>
<Button label="■ Stop" hotkey="s" />
<Text>
{" "}
</Text>
<Button label="Panel" dimColor />
<Text>
{" "}
</Text>
<Button label="History" dimColor />
</Box>
{await next(e)}
</Box>
)
})
// the pane: open it with $.ui.open({ id: 'my-pane', title: "History" })
on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
const { Box, Button, Text } = $.ui.resolve(e)
const title = '…'
const label = '…'
const a = '…'
const b = '…'
const value = '…'
const note = '…'
const label2 = '…'
const a2 = '…'
const b2 = '…'
const value2 = '…'
const note2 = '…'
const label3 = '…'
const a3 = '…'
const b3 = '…'
const value3 = '…'
const note3 = '…'
const usd = '…'
const k = '…'
const ruleText = '…'
const ruleText2 = '…'
const compactText = '…'
const dur = '…'
const title2 = '…'
const PHASE = '…'
const dur2 = '…'
const dur3 = '…'
const thinkMs = '…'
const respondMs = '…'
const toolMs = '…'
const outTokens = '…'
const name = '…'
const dur4 = '…'
const name2 = '…'
const dur5 = '…'
const name3 = '…'
const dur6 = '…'
const title3 = '…'
const dur7 = '…'
const tps = '…'
const tools = '…'
const dur8 = '…'
const dur9 = '…'
const title4 = '…'
const name4 = '…'
const k2 = '…'
const value4 = '…'
const name5 = '…'
const k3 = '…'
const value5 = '…'
const name6 = '…'
const k4 = '…'
const value6 = '…'
return (
<Box flexDirection="column">
<Box flexDirection="row" justifyContent="space-between">
<Button label="◂ expand" plain dimColor hotkey="f" />
<Button label="⚙ settings" plain dimColor />
</Box>
<Box flexDirection="column">
<Box marginTop={1}>
<Text bold>
{title}
</Text>
</Box>
<Box flexDirection="row">
<Text dimColor>
{label}
</Text>
<Text>
{a}
</Text>
<Text>
{b}
</Text>
<Text>
{" "}
{value}
</Text>
<Text dimColor>
{" "}
{note}
</Text>
</Box>
<Box flexDirection="row">
<Text dimColor>
{label2}
</Text>
<Text>
{a2}
</Text>
<Text>
{b2}
</Text>
<Text>
{" "}
{value2}
</Text>
<Text dimColor>
{" "}
{note2}
</Text>
</Box>
<Box flexDirection="row">
<Text dimColor>
{label3}
</Text>
<Text>
{a3}
</Text>
<Text>
{b3}
</Text>
<Text>
{" "}
{value3}
</Text>
<Text dimColor>
{" "}
{note3}
</Text>
</Box>
</Box>
<Box flexDirection="column" marginTop={1}>
<Text dimColor>
{`$${usd} this session`}
{` · auto-compact at ${k}`}
</Text>
<Text dimColor>
{"wrap-up 5h "}
{ruleText}
{" · 7d "}
{ruleText2}
{" · /compact "}
{compactText}
</Text>
</Box>
<Box flexDirection="row" marginTop={1}>
<Text>
{"wrap-up in "}
{dur}
{" "}
</Text>
<Button label="Cancel" />
</Box>
<Box flexDirection="column">
<Box marginTop={1}>
<Text bold>
{title2}
</Text>
</Box>
<Box flexDirection="row">
<Text>
{PHASE}
{" "}
</Text>
<Text>
{dur2}
</Text>
<Text>
{" "}
</Text>
<Button label="■ Stop" hotkey="s" />
</Box>
<Text dimColor>
{"total "}
{dur3}
{" · think "}
{`${thinkMs}0`}
{" · write"}
{" "}
{`${respondMs}0`}
{" · tools"}
{" "}
{`${toolMs}0`}
</Text>
<Text dimColor>
{k}
{" out"}
{` · ${outTokens} tok/s`}
</Text>
<Box flexDirection="row">
<Text>
{"◌ "}
</Text>
<Text dimColor wrap="truncate">
{name}
</Text>
<Text dimColor>
{" "}
{dur4}
</Text>
</Box>
<Box flexDirection="row">
<Text>
{"◌ "}
</Text>
<Text dimColor wrap="truncate">
{name2}
</Text>
<Text dimColor>
{" "}
{dur5}
</Text>
</Box>
<Box flexDirection="row">
<Text>
{"◌ "}
</Text>
<Text dimColor wrap="truncate">
{name3}
</Text>
<Text dimColor>
{" "}
{dur6}
</Text>
</Box>
</Box>
<Box flexDirection="column">
<Box marginTop={1}>
<Text bold>
{title3}
</Text>
</Box>
<Box flexDirection="row">
<Text>
{"● "}
</Text>
<Text>
{dur7}
</Text>
<Text dimColor>
{` · think ${dur}`}
{` · ${tps} tok/s`}
{` · ${tools} tools`}
{" · stopped"}
</Text>
</Box>
<Box flexDirection="row">
<Text>
{"● "}
</Text>
<Text>
{dur8}
</Text>
<Text dimColor>
{` · think ${dur}`}
{` · ${tps} tok/s`}
{` · ${tools} tools`}
{" · stopped"}
</Text>
</Box>
<Box flexDirection="row">
<Text>
{"● "}
</Text>
<Text>
{dur9}
</Text>
<Text dimColor>
{` · think ${dur}`}
{` · ${tps} tok/s`}
{` · ${tools} tools`}
{" · stopped"}
</Text>
</Box>
</Box>
<Box flexDirection="column">
<Box marginTop={1}>
<Text bold>
{title4}
</Text>
</Box>
<Box flexDirection="row">
<Text dimColor>
{name4}
{" "}
</Text>
<Text>
{k2}
</Text>
<Text dimColor>
{" · "}
{value4}
%
</Text>
</Box>
<Box flexDirection="row">
<Text dimColor>
{name5}
{" "}
</Text>
<Text>
{k3}
</Text>
<Text dimColor>
{" · "}
{value5}
%
</Text>
</Box>
<Box flexDirection="row">
<Text dimColor>
{name6}
{" "}
</Text>
<Text>
{k4}
</Text>
<Text dimColor>
{" · "}
{value6}
%
</Text>
</Box>
</Box>
</Box>
)
})
on('session.start', async ($, e, next) => {
const label = '…'
const WRAP_DELAY_MS = '…'
await $.ui.toast(`${label}: wrap-up prompt in ${WRAP_DELAY_MS}s (cancel above the prompt)`)
await $.ui.toast(`${label}: wrap-up prompt sent`)
return next(e)
})
}
Mod 自身のコード
Mod のライセンス(MIT)に従って載せています。全文は下にあります。写すときは著作権表示を残してください。
context-gauge/hooks/register.tsx 1043〜1202 行 · バンド
on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
if (e.props.hasSurvey) return next(e)
const m = await read($, meter)
const l = await read($, live)
const w = await read($, wrap)
await read($, tick)
if (!m && !l) return next(e)
const look = await lookOf($)
const now = await $.clock.now()
const { Box, Text, Button } = $.ui.resolve(e)
const Svg = svgOf($, e, look.style)
const sep = <Text color={C.rule}> │ </Text>
const ctx = m ? ctxRatio(m) : 0
const ctxColor = tone(ctx, 0.75, 0.9)
const drawn = m && readings(m, ctx, now, look.style)
const gear = <Button key="settings" label="⚙" plain dimColor onPress={() => openSettings($)} />
const chip = await drawChip($, e)
const status = await read($, serviceStatus)
const statusColor_ = !status || status.error ? C.rule : status.indicator === 'none' ? C.ok : status.indicator === 'minor' ? C.warn : C.hot
const extras = (
<Box flexDirection="row" gap={1}>
<Button key="status" label="◉" plain dimColor onPress={() => update($, isStatusOpen, x => !x)} />
<Text color={statusColor_}>{status ? '●' : '○'}</Text>
<Button key="history" label="≡" plain dimColor onPress={() => openTimeline($)} />
</Box>
)
// What the SVG line may take: the band's cells less the controls beside
// it, at a conservative 8px a cell (a desktop UI font's cell is ~7-8px).
const controlCells =
(chip ? 24 + 2 + (await chipNameLength($)) + 2 : 0) +
8
// Buttons take a little more than their cells on desktop (padding), so
// leave room to spare; the meters shrink and clip, the controls never do.
const meterCells = Math.max(16, e.props.bodyColumns - controlCells - 10)
const stripRoom = meterCells * 6.5
const meterRow =
m && drawn && Svg ? (
<Box flexDirection="row" alignItems="center" gap={2}>
<Box flexGrow={1} flexShrink={1} minWidth={10} overflow="hidden">
<Svg source={strip(drawn, m.usd, look, stripRoom)} alt={alt(drawn, m.usd)} />
</Box>
<Box flexDirection="row" alignItems="center" gap={2} flexShrink={0}>
{chip}
{extras}
{gear}
</Box>
</Box>
) : (
m && (
<Box flexDirection="row" gap={1}>
<Box flexGrow={1} flexShrink={1} minWidth={10} flexDirection="row" overflow="hidden">
{(() => {
const fit = fitTextBand(m, ctx, now, meterCells)
const [c1, c2] = bar(ctx, fit.ctxBar)
return (
<Box flexDirection="row">
<Text color={C.accent}>◆ </Text>
<Text dimColor>ctx </Text>
<Text color={ctxColor}>{c1}</Text>
<Text color={C.rule}>{c2}</Text>
<Text color={ctxColor} bold>
{' '}
{m.percent ?? 0}%
</Text>
{fit.tokens && m.tokens !== undefined && (
<Text dimColor>
{' '}
{k(m.tokens)}/{k(m.isAutoCompact && m.threshold ? m.threshold : m.window)}
</Text>
)}
{fit.delta && m.delta ? (
<Text dimColor>
{' '}
{m.delta > 0 ? '+' : ''}
{k(m.delta)}
</Text>
) : null}
{ctx >= 0.9 && <Text color={C.hot}> ⚠ compacts soon</Text>}
{m.limits
.filter(x => fit.kinds.includes(x.kind))
.map(x => {
const c = tone(x.percent / 100, 0.7, 0.9)
const [a, b] = bar(x.percent / 100, fit.blocks, '▰', '▱')
return (
<Box flexDirection="row">
{sep}
<Text dimColor>{limitLabel(x.kind)} </Text>
<Text color={c}>{a}</Text>
<Text color={C.rule}>{b}</Text>
<Text color={c}> {x.percent}%</Text>
{fit.resets && <Text dimColor> {resetIn(x, now)}</Text>}
</Box>
)
})}
{fit.cost && m.usd !== undefined && (
<Box flexDirection="row">
{sep}
<Text dimColor>${m.usd.toFixed(2)}</Text>
</Box>
)}
</Box>
)
})()}
</Box>
<Box flexDirection="row" gap={1} flexShrink={0}>
{chip}
{extras}
{gear}
</Box>
</Box>
)
)
const running = l && l.tools.find(t => t.ms === null)
const tps = l && l.genMs > 500 ? Math.round(l.outTokens / (l.genMs / 1000)) : null
const phaseNow = l ? now - l.phaseSince : 0
const thinkTotal = l ? l.thinkMs + (l.phase === 'thinking' ? phaseNow : 0) : 0
const liveRow = l && (
<Box flexDirection="row" flexWrap="wrap">
<Text color={C.accent}>{PHASE[l.phase]} </Text>
<Text>{dur(phaseNow)}</Text>
{sep}
<Text dimColor>turn {dur(now - l.startedAt)}</Text>
{thinkTotal > 0 && <Text dimColor> · think {dur(thinkTotal)}</Text>}
{tps !== null && <Text dimColor> · {tps} tok/s</Text>}
{running && <Text dimColor> · {running.name} {dur(now - running.startedAt)}</Text>}
<Text> </Text>
<Button key="stop" label="■ Stop" hotkey="s" onPress={() => stopTurn($)} />
<Text> </Text>
<Button key="pane" label="Panel" dimColor onPress={() => $.ui.open({ id: PANE, title: 'Gauge' })} />
<Text> </Text>
<Button key="timeline" label="History" dimColor onPress={() => openTimeline($)} />
</Box>
)
const wrapRow = w.pending && (
<Box flexDirection="row" flexWrap="wrap">
<Text color={C.hot}>{w.pending.label} </Text>
<Text dimColor>wrap-up prompt in {dur(w.pending.deadline - now)} </Text>
<Button key="wrap-cancel" label="Cancel" hotkey="c" onPress={() => cancelWrap($)} />
<Text> </Text>
<Button key="wrap-now" label="Send now" dimColor onPress={() => fireWrap($)} />
</Box>
)
const picker = await drawInlinePicker($, e)
const statusPanel = await drawStatus($, e)
return (
<Box flexDirection="column">
{wrapRow}
{meterRow}
{picker}
{statusPanel}
{liveRow}
</Box>context-gauge/hooks/register.tsx 1504〜1544 行 · バンド
async function drawChip($: EngineInterface, e: RenderInput<'AbovePrompt'>) {
const s = await read($, settings)
if (!s.models.isShown) return null
const c = await read($, current)
const isOpen = await read($, isPickerOpen)
const { Box, Button } = $.ui.resolve(e)
const Client =
e.surface === 'terminal' || e.surface === 'desktop'
? ($.ui.resolve(e) as { Client?: ElementConstructor<ClientProps> }).Client
: undefined
const at = activeSlot(c, s.models)
const slot = at === null ? undefined : s.models.slots[at]
const name = slot ? slotLabel(slot) : c.model ? modelLabel(familyOf(c.model) ?? c.model) : 'Model'
const n = s.models.slots.length
return (
<Box flexDirection="row" gap={1} flexShrink={0}>
{Client && (
<Client
key="model-track"
module="./slider.tsx"
props={{
labels: s.models.slots.map(slotLabel),
locked: s.models.slots.map(x => isLocked(x, s.models)),
active: at,
accent: CLAUDE,
compact: true,
rail: (c.theme ?? '').startsWith('light') ? '#dcdce0' : '#3a3b40',
}}
width={(n - 1) * 5 + 3}
/>
)}
<Button
key="model-chip"
label={`${c.fast ? '⚡ ' : ''}${name} ${isOpen ? '⌄' : '›'}`}
plain
dimColor={!isOpen}
onPress={() => update($, isPickerOpen, x => !x)}
/>
</Box>
)
}context-gauge/hooks/register.tsx 1561〜1592 行 · バンド
async function drawInlinePicker($: EngineInterface, e: RenderInput<'AbovePrompt'>) {
if (!(await read($, isPickerOpen))) return null
const { Box, Button } = $.ui.resolve(e)
const s = await read($, settings)
const c = await read($, current)
const at = activeSlot(c, s.models)
const slots = s.models.slots
const locked = slots.map(x => isLocked(x, s.models))
const Svg = e.surface === 'terminal' ? undefined : ($.ui.resolve(e) as { Svg?: ElementConstructor<SvgProps> }).Svg
return (
<Box flexDirection="column" borderStyle="round" borderColor={C.rule} paddingX={1}>
<Box flexDirection="row" gap={2} alignItems="center">
{Svg && <Svg source={pill(slots.length, at, locked, CLAUDE, 0.5 * SCALE[s.look.size])} alt={`position ${at === null ? 'none' : at + 1}`} />}
{slots.map((x, i) => (
<Button
key={`pick-${i}`}
label={`${locked[i] ? '⊘ ' : ''}${slotLabel(x)}`}
plain
dimColor={i !== at}
onPress={() => applySlot($, i)}
/>
))}
</Box>
<Box flexDirection="row" gap={2}>
<Button key="picker-fast" label={c.fast ? '⚡ Fast on' : '⚡ Fast'} plain dimColor={!c.fast} onPress={() => toggleFast($)} />
<Button key="picker-style" label={`Style: ${c.outputStyle ?? 'default'}`} plain dimColor onPress={() => void setStyle($).then(t => $.ui.toast(t))} />
<Button key="picker-settings" label="Edit positions" plain dimColor onPress={() => update($, settingsTab, () => 'models').then(() => openSettings($))} />
<Button key="picker-close" label="✕" plain dimColor onPress={() => update($, isPickerOpen, () => false)} />
</Box>
</Box>
)
}context-gauge/hooks/register.tsx 1617〜1673 行 · バンド
async function drawStatus($: EngineInterface, e: RenderInput<'AbovePrompt'>) {
if (!(await read($, isStatusOpen))) return null
const { Box, Text, Button } = $.ui.resolve(e)
const st = await read($, serviceStatus)
const usage = await read($, usageCheck)
const m = await read($, meter)
const now = await $.clock.now()
const colorOf = (status: string) =>
status === 'operational' || status === 'none' ? C.ok : status === 'degraded_performance' || status === 'minor' || status === 'under_maintenance' ? C.warn : C.hot
return (
<Box flexDirection="column" borderStyle="round" borderColor={C.rule} paddingX={1}>
<Box flexDirection="row" gap={2}>
<Text bold>Claude status & usage</Text>
{st ? (
<Text color={st.error ? C.hot : colorOf(st.indicator)}>{st.error ? `check failed: ${st.error}` : st.description || st.indicator}</Text>
) : (
<Text dimColor>not checked yet</Text>
)}
{st && <Text dimColor>· {dur(now - st.at)} ago</Text>}
<Button
key="status-refresh"
label="↻ Refresh"
plain
onPress={async () => {
usageAskedAt = 0
await Promise.all([refreshStatus($), checkUsage($)])
}}
/>
<Button key="status-close" label="✕" plain dimColor onPress={() => update($, isStatusOpen, () => false)} />
</Box>
{st && st.components.length > 0 && (
<Box flexDirection="row" flexWrap="wrap" gap={2}>
{st.components.map(c => (
<Box flexDirection="row">
<Text color={colorOf(c.status)}>● </Text>
<Text dimColor>
{c.name} {COMPONENT_LABEL[c.status] ?? c.status.replace(/_/g, ' ')}
</Text>
</Box>
))}
</Box>
)}
{usage && (
<Text color={usage.error ? C.warn : undefined} dimColor={!usage.error} wrap="truncate">
{usage.error
? `Usage: ${usage.error}`
: `Usage, ${dur(now - usage.at)} ago: ${(m?.limits ?? []).map(x => `${limitLabel(x.kind)} ${x.percent}%`).join(' · ')}`}
</Text>
)}
{st?.incidents.map(i => (
<Text color={i.impact === 'none' || i.impact === 'minor' ? C.warn : C.hot} wrap="truncate">
⚠ {i.name} ({i.status})
</Text>
))}
</Box>
)
}context-gauge/hooks/register.tsx 1231〜1231 行 · ペイン
on('ui.render', { component: 'Pane', requestId: PANE }, ($, e) => drawGauge($, e, e.props.bodyColumns))context-gauge/hooks/register.tsx 1897〜2056 行 · ペイン
async function drawGauge($: EngineInterface, e: RenderInput<'Pane' | 'CommandOutput'>, columns: number) {
const { Box, Text, Button } = $.ui.resolve(e)
const m = await read($, meter)
const l = await read($, live)
const hist = await read($, history)
const w = await read($, wrap)
const s = await read($, settings)
const collapsed = await read($, isCollapsed)
const look = await lookOf($)
const Svg = svgOf($, e, look.style)
await read($, tick)
const now = await $.clock.now()
const width = Math.max(12, columns - 2)
const barW = Math.max(6, Math.min(24, width - 18))
const ctx = m ? ctxRatio(m) : 0
const drawn = m && readings(m, ctx, now, look.style)
const head = (title: string) => (
<Box marginTop={1}>
<Text color={C.accent} bold>
{title.toUpperCase()}
</Text>
</Box>
)
const header = (
<Box flexDirection="row" justifyContent="space-between" width={width}>
<Button
key="fold"
label={collapsed ? '◂ expand' : '▸ fold'}
plain
dimColor
hotkey="f"
onPress={() => toggleCollapsed($)}
/>
<Button key="pane-settings" label="⚙ settings" plain dimColor onPress={() => openSettings($)} />
</Box>
)
if (collapsed) {
return (
<Box flexDirection="column">
{header}
<Text color={tone(ctx, 0.75, 0.9)}>ctx {m?.percent ?? 0}%</Text>
{(m?.limits ?? []).map(x => (
<Text color={tone(x.percent / 100, 0.7, 0.9)}>
{limitLabel(x.kind)} {x.percent}%
</Text>
))}
{l && <Text color={C.accent}>{PHASE[l.phase]}</Text>}
</Box>
)
}
// The meters: small SVG bars where the surface draws them, text elsewhere.
const meters =
m && drawn && Svg ? (
<Box marginTop={1}>
<Svg source={stack(drawn, width * 7, look)} alt={alt(drawn, m.usd)} />
</Box>
) : (
m && (
<Box flexDirection="column">
{head('Usage')}
{[
{ label: 'ctx', ratio: ctx, value: `${m.percent ?? 0}%`, note: `${k(m.tokens ?? 0)}/${k(m.window)}`, warn: 0.75 },
...m.limits.map(x => ({
label: limitLabel(x.kind),
ratio: x.percent / 100,
value: `${x.percent}%`,
note: resetIn(x, now),
warn: 0.7,
})),
].map(r => {
const [a, b] = bar(r.ratio, barW)
return (
<Box flexDirection="row">
<Text dimColor>{r.label.padEnd(4)}</Text>
<Text color={tone(r.ratio, r.warn, 0.9)}>{a}</Text>
<Text color={C.rule}>{b}</Text>
<Text color={r.ratio >= 0.9 ? C.hot : undefined}> {r.value.padStart(4)}</Text>
<Text dimColor> {r.note}</Text>
</Box>
)
})}
</Box>
)
)
const summary = m && (
<Box flexDirection="column" marginTop={1}>
<Text dimColor>
{m.usd !== undefined ? `$${m.usd.toFixed(2)} this session` : ''}
{m.isAutoCompact && m.threshold ? ` · auto-compact at ${k(m.threshold)}` : ''}
</Text>
<Text dimColor>
wrap-up 5h {ruleText(s.wrap5h)} · 7d {ruleText(s.wrap7d)} · /compact {compactText(s)}
</Text>
</Box>
)
const turnSection = l && (
<Box flexDirection="column">
{head('This turn')}
<Box flexDirection="row">
<Text color={C.accent}>{PHASE[l.phase]} </Text>
<Text>{dur(now - l.phaseSince)}</Text>
<Text> </Text>
<Button key="pane-stop" label="■ Stop" hotkey="s" onPress={() => stopTurn($)} />
</Box>
<Text dimColor>
total {dur(now - l.startedAt)} · think {dur(l.thinkMs + (l.phase === 'thinking' ? now - l.phaseSince : 0))} · write{' '}
{dur(l.respondMs + (l.phase === 'responding' ? now - l.phaseSince : 0))} · tools{' '}
{dur(l.toolMs + (l.phase === 'tool' ? now - l.phaseSince : 0))}
</Text>
<Text dimColor>
{k(l.outTokens)} out{l.genMs > 500 ? ` · ${Math.round(l.outTokens / (l.genMs / 1000))} tok/s` : ''}
</Text>
{l.tools.slice(-8).map(t => {
const ms = t.ms ?? now - t.startedAt
return (
<Box flexDirection="row">
<Text color={t.ms === null ? C.accent : t.isError ? C.hot : C.ok}>
{t.ms === null ? '◌ ' : t.isError ? '✕ ' : '✓ '}
</Text>
<Text dimColor wrap="truncate">
{t.name.replace(/^mcp__/, '').slice(0, 18).padEnd(18)}
</Text>
<Text dimColor> {dur(ms)}</Text>
</Box>
)
})}
</Box>
)
// Plain numbers: block-glyph sparklines smear together in proportional UI fonts.
const recent = hist.slice(-5).reverse()
const historySection = recent.length > 0 && (
<Box flexDirection="column">
{head('Recent turns')}
{recent.map((r, i) => (
<Box flexDirection="row">
<Text color={i === 0 ? undefined : C.rule}>{i === 0 ? '● ' : '○ '}</Text>
<Text>{dur(r.ms)}</Text>
<Text dimColor>
{r.thinkMs ? ` · think ${dur(r.thinkMs)}` : ''}
{r.tps ? ` · ${r.tps} tok/s` : ''}
{r.tools ? ` · ${r.tools} tools` : ''}
{r.isAborted ? ' · stopped' : ''}
</Text>
</Box>
))}
</Box>
)
// Name, then its tokens and share of the window, on one line: a right-aligned
// column does not survive surfaces that lay text out in proportional fonts.
const breakdown = m && m.categories.length > 0 && (
<Box flexDirection="column">
{head('Context breakdown')}ライセンスの全文(MIT)
MIT License Copyright (c) 2026 kirishimarisano-rgb 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 に読んだコミット d866a4fd879e のソースから。最初のまとまりが載せる条件で、残りは自分で判断するための材料です。後のコミットは、次に読むまで見ていません。
| 載せる条件: 確かめやすいコード | |
|---|---|
| 入口を読んだ | hooks/hooks.json が名指すモジュールをすべて読んだ。context-gauge/hooks/register.tsx |
| 解析できる | すべてのファイルが TypeScript か JavaScript として解析できる。3 ファイルを解析 |
| コードが 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 のホスト)がコードに書いてあるか。https://api.anthropic.com, https://status.claude.com |
| プログラム | 起動するプログラムの名前がコードに書いてあり、シェル・インタプリタ・通信用の道具でないか。プログラムを起動しない |
| 読んで送る | ファイルや環境変数を読み、かつ通信するか。通信するが、ファイルも環境変数も読まない |
| ソースの鍵 | ソースに API キーや秘密鍵らしきものがあるか。ソースに鍵なし |
| ライセンス | オープンなライセンス(MIT・Apache-2.0・BSD・ISC・Unlicense・0BSD・CC0)で全文があれば、modscode にコードを載せる。違えばリンクだけ。MIT |
コードの文面を読んだだけで、安全の審査ではありません。動かしてはおらず、起動するプログラムの中で何が起きるかも見えません。入れる前の確認はあなたの役目です。 載せる条件
入れる
入れる前に、必ず自分で確かめてください。Mod はサンドボックスなしで、あなたの権限で動きます。modscode はこのコードの安全を保証しません。下のコードを読み(またはフォルダーで claude plugin validate .)、触るものを見て、読んだコミットを入れてください。
リポジトリがそのままマーケットプレイスです。このマーケットプレイスを足し(ターミナルでは次のコマンド、デスクトップアプリではプラグインの設定)、そこから Mod を入れます。
/plugin marketplace add kirishimarisano-rgb/Claude-code-usage-context-cost-show/plugin install context-gauge@kirishima-mods入るのはマーケットプレイスの最新のコミットで、ここで読んだもの(d866a4fd879e)と違うことがあります。入れる前に見比べてください。
Claude に聞く
modscode のコネクタを入れると、Claude がこのデザイン・コードが触るもの・コードを読んで、それをもとに作れます。たとえば:
modscode のデザイン「kirishimarisano-rgb-context-gauge」をコードごと読んで、同じようなペインを作って似たデザイン
-
Claude に頼む…Skins0 Your promptadd rate limiting to the hub api0 Tool rows: finished, running, failedYour prompt Spinner0 Folded group of reads and searches●main · note 3 · note 3 · note 30 Edit diff cardDesktop only; the terminal keeps Claude Code's diff.0 Shell output cardDesktop only.0 Code block cardDesktop only; the terminal keeps Claude Code's markdown.0 TableAccentAccentAccentAccentAccentAccentAccentAccentAccentAccentAccentAccentCopyAccentAccentAccentAccentAccentAccentAccentAccentAccentAccentAccentAccentCopyAccentAccentAccentAccentAccentAccentAccentAccentAccentAccentAccentAccentCopy0 SpinnerAccent SpinnerSpinnerSpinner… 2h 10m0 Band above the prompt: normal, then nudging to compact█████░░░ 42% build█████░░░ 42% build█████░░░ 42% buildContext is 42% full0 Compact now0 Band above a questionTable BashBashBash0 Turn footer (terminal)3 build in 2h 10m · Grep · +3 −3
-
Claude に頼む…蹦一蹦Claude needs youBack to ClaudeClick, hold SpaceContextShortcutShortcutShortcutSlow network, still loading…3 Skills33 Skills33 Skills3SkillsLeave leaderboardok. Showing the last resultsRetry3♪
-
Claude に頼む…────────Clear doneClaude⋯└─ buildCancelCancelCancel└─ buildCancelCancelCancel└─ buildCancelCancelCancel
-
何をするか
- 欄・プロンプトの上の帯を描く
- /lingo を足す
- prompt.edit・prompt.submit・session.startにフックする
- ターンをまたいで自分の状態を持つ
-
Claude に頼む…Model routerLast reply: Fix login → a1b2c3dKept off Opus to save the cache. Start a prompt with @Opus to force it.OnOffRoutes model and effort for each kind of prompt0 Fix loginbuildbuildbuildbuildbuildbuild0 Fix loginbuildbuildbuildbuildbuildbuild0 Fix loginbuildbuildbuildbuildbuildbuildYour rules checked firstNo rules yet. Pick a model and effort, type the words, press Add rule.Tasksa1b2c3d✕Tasksa1b2c3d✕Tasksa1b2c3d✕words, for example landing page, redesign Add rulebuildbuildbuildbuildbuildbuildOptions CoolingWhen still broken after xhigh, move tobuildbuildbuildCache saver: skip one-off model switches in long chatsbuildbuildbuildOne prompt only: start it with @opus, @max or @hardReset
-
Claude に頼む…Timer● MonAprNo timer runningStopResume last CollapseFri week./meter.tsxUnbilled Wed h$1.24 · expenses MarMayToday, Oct 6This week