usage-meter
Plan-limit bars with burn rate and time-to-empty, session cost, cache hit ratio and tokens-per-turn sparkline.
何をするか
- 欄・トーストを描く
- /meter を足す
- session.start・turn.completeにフックする
良いところ
- ネットワークに出ない
- プロセスを起こさない
- 小さい(338 行)
- TypeScript で書かれている
作り始めるためのコード
2 種類あります。上のデザインから modscode が書いた雛形と、その Mod 自身のコードのうち描いている部分です。
雛形(register.tsx)
import type { Register } from 'claude-code'
// Drawn like usage-meter by Michael Goldenberg (pane, status, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/mishgoldenberg-usage-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 pane: open it with $.ui.open({ id: 'my-pane', title: "Usage" })
on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
const { Box, Text, Svg, Input, Button } = $.ui.resolve(e)
const status = '…'
const kind = '…'
const LABELS = '…'
const pct = '…'
const svgBar = '…'
const until = '…'
const perHour = '…'
const hoursLeft = '…'
const kind2 = '…'
const until2 = '…'
const kind3 = '…'
const until3 = '…'
const value = '…'
const value2 = '…'
const value3 = '…'
const value4 = '…'
const value5 = '…'
const value6 = '…'
const value7 = '…'
const spark = '…'
const value8 = '…'
const value9 = '…'
const value10 = '…'
return (
<Box flexDirection="column" gap={1}>
<Box gap={1}>
<Text>
▲
</Text>
<Text bold>
usage-meter
</Text>
<Text dimColor wrap="truncate-end">
{status}
</Text>
</Box>
<Box flexDirection="column">
<Box gap={1}>
<Text dimColor>
Plan limits
</Text>
</Box>
<Box flexDirection="column">
<Text dimColor>
No rate-limit windows reported (API key, or a plan without limits).
</Text>
<Box flexDirection="column">
<Box gap={1}>
<Box width={11} flexShrink={0}>
<Text wrap="truncate-end">
{kind}
</Text>
</Box>
<Box flexGrow={1} flexShrink={1}>
<Svg alt={`${LABELS} ${pct}% used`} source={`${svgBar}`} />
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
{`▲ ${pct}%`}
</Text>
</Box>
</Box>
<Box paddingLeft={12}>
<Text dimColor wrap="truncate-end">
{until}
{` · +${perHour}%/h this session · full in ~${hoursLeft}m`}
</Text>
</Box>
</Box>
<Box flexDirection="column">
<Box gap={1}>
<Box width={11} flexShrink={0}>
<Text wrap="truncate-end">
{kind2}
</Text>
</Box>
<Box flexGrow={1} flexShrink={1}>
<Svg alt={`${LABELS} ${pct}% used`} source={`${svgBar}`} />
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
{`▲ ${pct}%`}
</Text>
</Box>
</Box>
<Box paddingLeft={12}>
<Text dimColor wrap="truncate-end">
{until2}
{` · +${perHour}%/h this session · full in ~${hoursLeft}m`}
</Text>
</Box>
</Box>
<Box flexDirection="column">
<Box gap={1}>
<Box width={11} flexShrink={0}>
<Text wrap="truncate-end">
{kind3}
</Text>
</Box>
<Box flexGrow={1} flexShrink={1}>
<Svg alt={`${LABELS} ${pct}% used`} source={`${svgBar}`} />
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
{`▲ ${pct}%`}
</Text>
</Box>
</Box>
<Box paddingLeft={12}>
<Text dimColor wrap="truncate-end">
{until3}
{` · +${perHour}%/h this session · full in ~${hoursLeft}m`}
</Text>
</Box>
</Box>
</Box>
</Box>
<Box flexDirection="column">
<Box gap={1}>
<Text dimColor>
This session
</Text>
</Box>
<Box flexDirection="column">
<Box gap={1}>
<Box flexGrow={1} flexShrink={1}>
<Text dimColor wrap="truncate-end">
Cost
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
{value}
</Text>
</Box>
</Box>
<Box gap={1}>
<Box flexGrow={1} flexShrink={1}>
<Text dimColor wrap="truncate-end">
Time
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
{value2}
</Text>
</Box>
</Box>
<Box gap={1}>
<Box flexGrow={1} flexShrink={1}>
<Text dimColor wrap="truncate-end">
Turns
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
{value3}
</Text>
</Box>
</Box>
<Input />
<Box gap={1}>
<Box flexGrow={1} flexShrink={1}>
<Text dimColor wrap="truncate-end">
Output
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
{value4}
</Text>
</Box>
</Box>
<Box gap={1}>
<Box flexGrow={1} flexShrink={1}>
<Text dimColor wrap="truncate-end">
Cache read
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
{value5}
</Text>
</Box>
</Box>
<Box gap={1}>
<Box flexGrow={1} flexShrink={1}>
<Text dimColor wrap="truncate-end">
Cache write
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
{value6}
</Text>
</Box>
</Box>
<Box gap={1}>
<Box flexGrow={1} flexShrink={1}>
<Text dimColor wrap="truncate-end">
Cache hit
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text color="success">
{value7}
</Text>
</Box>
</Box>
<Text dimColor>
Low cache hit: long pauses or edits to early context break the cache.
</Text>
</Box>
</Box>
<Box flexDirection="column">
<Box gap={1}>
<Text dimColor>
Tokens per turn (new, uncached)
</Text>
</Box>
<Box flexDirection="column">
<Text color="claude">
{spark}
</Text>
<Box gap={1}>
<Box flexGrow={1} flexShrink={1}>
<Text dimColor wrap="truncate-end">
Last
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
{value8}
</Text>
</Box>
</Box>
<Box gap={1}>
<Box flexGrow={1} flexShrink={1}>
<Text dimColor wrap="truncate-end">
Average
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
{value9}
</Text>
</Box>
</Box>
<Box gap={1}>
<Box flexGrow={1} flexShrink={1}>
<Text dimColor wrap="truncate-end">
Max
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
{value10}
</Text>
</Box>
</Box>
</Box>
</Box>
<Box gap={1}>
<Button hotkey="r" variant="primary" label="Refresh" />
<Button label="Reset burn baseline" />
</Box>
</Box>
)
})
on('session.start', async ($, e, next) => {
const LABELS = '…'
const percentUsed = '…'
const until = '…'
await $.ui.toast(`${LABELS} limit at ${percentUsed}% (${until})`)
return next(e)
})
}
Mod 自身のコード
Mod のライセンス(MIT)に従って載せています。全文は下にあります。写すときは著作権表示を残してください。
plugins/usage-meter/hooks/register.tsx 182〜307 行 · ペイン
on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
const els = $.ui.resolve(e)
const { Box, Text, Button } = els
const Svg = 'Svg' in els ? els.Svg : undefined
const kit = { Box, Text }
const snap = await read($, snapshot)
const list = await read($, turns)
const base = await read($, baseline)
const cols = e.props.bodyColumns ?? 40
const width = Math.max(10, Math.min(30, cols - 20))
if (snap === null) {
return (
<Box flexDirection="column" gap={1}>
{header(kit, GLYPH.off, TONE.dim, 'usage-meter', 'no reading yet')}
{empty(kit, 'Plan limits and cost update after every turn and once a minute. Read them now to see where you stand.')}
<Box>
<Button key="refresh" hotkey="r" variant="primary" label="Read usage" onPress={() => void refresh($)} />
</Box>
</Box>
)
}
const now = snap.updatedAt
const totals = list.reduce((s, t) => ({ input: s.input + t.input, output: s.output + t.output, cacheRead: s.cacheRead + t.cacheRead, cacheWrite: s.cacheWrite + t.cacheWrite }), { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 })
const prompted = totals.input + totals.cacheRead + totals.cacheWrite
const cacheHit = prompted > 0 ? Math.round((totals.cacheRead / prompted) * 100) : null
const minutes = Math.round((now - snap.startedAt) / 60000)
const perTurn = list.map(t => t.input + t.output + t.cacheWrite)
const toneOf = (pct: number) => (pct >= 95 ? TONE.bad : pct >= warnAt ? TONE.warn : undefined)
const worst = Math.max(0, ...snap.windows.map(w => w.percentUsed))
const five = snap.windows.find(w => w.kind === 'five_hour')
const status = [five ? `5h ${Math.round(five.percentUsed)}%` : '', snap.costUsd !== null ? `$${snap.costUsd.toFixed(2)}` : '', `${list.length} turns`].filter(Boolean).join(' · ')
const stat = (label: string, value: string, color?: string) => (
<Box gap={1}>
<Box flexGrow={1} flexShrink={1}>
<Text dimColor wrap="truncate-end">
{label}
</Text>
</Box>
{num(kit, value, 9, color)}
</Box>
)
return (
<Box flexDirection="column" gap={1}>
{header(kit, worst >= warnAt ? GLYPH.warn : GLYPH.on, toneOf(worst) ?? TONE.accent, 'usage-meter', status)}
{section(
kit,
'Plan limits',
<Box flexDirection="column">
{snap.windows.length === 0 && empty(kit, 'No rate-limit windows reported (API key, or a plan without limits).')}
{snap.windows.map(w => {
const b = burn(w, base, now)
const pct = Math.round(w.percentUsed)
return (
<Box flexDirection="column">
<Box gap={1}>
<Box width={11} flexShrink={0}>
<Text wrap="truncate-end">{LABELS[w.kind] ?? w.kind}</Text>
</Box>
{Svg !== undefined ? (
<Box flexGrow={1} flexShrink={1}>
<Svg alt={`${LABELS[w.kind] ?? w.kind} ${pct}% used`} source={svgBar(w.percentUsed)} />
</Box>
) : (
<Text color={TONE.accent}>{bar(w.percentUsed, width)}</Text>
)}
{num(kit, `${w.percentUsed >= warnAt ? `${GLYPH.warn} ` : ''}${pct}%`, 6, toneOf(w.percentUsed))}
</Box>
<Box paddingLeft={12}>
<Text dimColor wrap="truncate-end">
{until(w.resetsAt, now)}
{b !== null && ` · +${b.perHour.toFixed(1)}%/h this session · full in ~${b.hoursLeft < 1 ? `${Math.round(b.hoursLeft * 60)}m` : `${b.hoursLeft.toFixed(1)}h`}`}
</Text>
</Box>
</Box>
)
})}
</Box>,
)}
{section(
kit,
'This session',
<Box flexDirection="column">
{stat('Cost', snap.costUsd !== null ? `$${snap.costUsd.toFixed(2)}` : 'n/a')}
{stat('Time', `${minutes}m`)}
{stat('Turns', String(list.length))}
{stat('Input', k(totals.input))}
{stat('Output', k(totals.output))}
{stat('Cache read', k(totals.cacheRead))}
{stat('Cache write', k(totals.cacheWrite))}
{cacheHit !== null && stat('Cache hit', `${cacheHit < 40 ? `${GLYPH.warn} ` : ''}${cacheHit}%`, cacheHit >= 70 ? TONE.ok : cacheHit >= 40 ? undefined : TONE.warn)}
{cacheHit !== null && cacheHit < 40 && <Text dimColor>Low cache hit: long pauses or edits to early context break the cache.</Text>}
</Box>,
)}
{section(
kit,
'Tokens per turn (new, uncached)',
perTurn.length < 2 ? (
empty(kit, 'The chart starts after two turns.')
) : (
<Box flexDirection="column">
{Svg !== undefined ? (
<Svg alt={`Tokens per turn over the last ${Math.min(perTurn.length, 60)} turns`} source={svgSpark(perTurn.slice(-60))} />
) : (
<Text color={TONE.accent}>{spark(perTurn.slice(-Math.max(8, cols - 4)))}</Text>
)}
{stat('Last', k(perTurn.at(-1) ?? 0))}
{stat('Average', k(perTurn.reduce((a, b) => a + b, 0) / perTurn.length))}
{stat('Max', k(Math.max(...perTurn)))}
</Box>
),
)}
<Box gap={1}>
<Button key="refresh" hotkey="r" variant="primary" label="Refresh" onPress={() => void refresh($)} />
<Button key="reset" label="Reset burn baseline" onPress={() => void update($, baseline, () => null).then(() => refresh($))} />
</Box>
</Box>
)
})plugins/usage-meter/hooks/register.tsx 12〜20 行 · ペイン
function header({ Box, Text }: Kit, glyph: string, tone: string, name: string, status: string) {
return (
<Box gap={1}>
<Text color={tone}>{glyph}</Text>
<Text bold>{name}</Text>
<Text dimColor wrap="truncate-end">{status}</Text>
</Box>
)
}plugins/usage-meter/hooks/register.tsx 45〜47 行 · ペイン
function empty({ Text }: Kit, text: string) {
return <Text dimColor>{text}</Text>
}plugins/usage-meter/hooks/register.tsx 23〜33 行 · ペイン
function section({ Box, Text }: Kit, label: string, rows: RenderChildren, aside?: RenderChildren) {
return (
<Box flexDirection="column">
<Box gap={1}>
<Text dimColor>{label}</Text>
{aside}
</Box>
{rows}
</Box>
)
}plugins/usage-meter/hooks/register.tsx 36〜42 行 · ペイン
function num({ Box, Text }: Kit, value: string, width: number, color?: string) {
return (
<Box width={width} flexShrink={0} justifyContent="flex-end">
<Text color={color}>{value}</Text>
</Box>
)
}ライセンスの全文(MIT)
MIT License Copyright (c) 2026 Michael Goldenberg 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.
コードが呼ぶもの
見つからず
コードから読み取ったデザイン
読み取ったコミットのソースから描いたもので、動かした結果ではありません。一覧は 3 回描き、条件はデスクトップアプリで描く最初の分岐を取り、動かしたときにだけ決まる値は仮の例(点線の下線)にするか省きます。色と書体はこのサイトのものです。
コードから読めること
2026-10-06 に読んだコミット 6949e8dde6af のソースから。最初のまとまりが載せる条件で、残りは自分で判断するための材料です。後のコミットは、次に読むまで見ていません。
| 載せる条件: 確かめやすいコード | |
|---|---|
| 入口を読んだ | hooks/hooks.json が名指すモジュールをすべて読んだ。plugins/usage-meter/hooks/register.tsx |
| 解析できる | すべてのファイルが TypeScript か JavaScript として解析できる。1 ファイルを解析 |
| コードが 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 .)、触るものを見て、読んだコミットを入れてください。
リポジトリがそのままマーケットプレイスです。このマーケットプレイスを足し(ターミナルでは次のコマンド、デスクトップアプリではプラグインの設定)、そこから Mod を入れます。
/plugin marketplace add mishgoldenberg/claude-mods/plugin install usage-meter@claude-mods入るのはマーケットプレイスの最新のコミットで、ここで読んだもの(6949e8dde6af)と違うことがあります。入れる前に見比べてください。
Claude に聞く
modscode のコネクタを入れると、Claude がこのデザイン・コードが触るもの・コードを読んで、それをもとに作れます。たとえば:
modscode のデザイン「mishgoldenberg-usage-meter」をコードごと読んで、同じようなペインを作って似たデザイン
-
Claude に頼む…Files⋯│●./file-name.tsx│●./file-name.tsx│●./file-name.tsxNew file Move to Recycle Bin?────────./menu-item.tsx./menu-item.tsx./menu-item.tsx────────./menu-item.tsx./menu-item.tsx./menu-item.tsx────────./menu-item.tsx./menu-item.tsx./menu-item.tsx
-
Claude に頼む…IssuesChoose a repositoryBackRefresh open⠋Refreshing…This session● buildacme/appalex● buildacme/app● buildacme/app● buildacme/appalex● buildacme/app● buildacme/app● buildacme/appalex● buildacme/app● buildacme/app● buildacme/appPress Enter to open Refresh.
-
Claude に頼む…secret-broker: waiting for Use savedSecret neededUse savedUse savedUse saved▌ THE LOG REQUIRES A SECRETUse savedClaude never sees the value. It goes to this one command, then it is gone.the command, exactly as it will runnpm test◯ build ▶ paste it here, press Enter. the log is watching. feed◯ build ▶ paste it here, press Enter. the log is watching. feed! Secret needed◉ the log remembers these for this session◯ build ▶ paste it here, press Enter. the log is watching. feedthe log waits for: Use saved n
-
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
-
Claude に頼む…great_cto: 3 gate waiting — /gatesGatesmy-app · 3 waiting · checked Gates UTCGates — Fix logina1b2c3dExpensive to undo. To approve, type Gates and press Enter.approve: Gates approveGates — Fix logina1b2c3dExpensive to undo. To approve, type Gates and press Enter.approve: Gates approveGates — Fix logina1b2c3dExpensive to undo. To approve, type Gates and press Enter.approve: Gates approve
-
Claude に頼む…agent-discoverbuildbuildbuildRefreshMCP Browse/3Tab / shift+Tab move · Enter presses · ↑↓ scroll · Esc back to the promptBrowse...Audit asks:DeclineAcceptDeclineCancelAudit asks:DeclineAcceptDeclineCancelAudit asks:DeclineAcceptDeclineCancel