modscode / 図鑑 / claude-code-usage-quota
claude-code-usage-quota
Your Claude plan limits, a forecast of when you'll run out, and your context window, live in a band above the prompt, with one-click and automatic compacting
何をするか
- プロンプトの上の帯・ステータス行・トーストを描く
- /quota を足す
- prompt.edit・session.measure・session.start・turn.complete ほか 3 個にフックする
- ターンをまたいで自分の状態を持つ
- ネットワークに出る
良いところ
- TypeScript で書かれている
- デスクトップ専用の分岐がある
- エラーを扱う
- ファイルを書かない
作り始めるためのコード
2 種類あります。上のデザインから modscode が書いた雛形と、その Mod 自身のコードのうち描いている部分です。
雛形(register.tsx)
import type { Register } from 'claude-code'
// Drawn like claude-code-usage-quota by Anant Raghunath (band, status, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/anantraghunath-claude-code-usage-quota/
// 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, Svg, Button, Input } = $.ui.resolve(e)
const switchSvg = '…'
const drawnAt = '…'
const percent = '…'
const at = '…'
const stale = '…'
const label = '…'
const note = '…'
const label2 = '…'
const note2 = '…'
const label3 = '…'
const note3 = '…'
const tokens = '…'
const name = '…'
const name2 = '…'
const tokens2 = '…'
const name3 = '…'
const tokens3 = '…'
return (
<Box flexDirection="column">
<Box flexDirection="column">
<Box>
<Text bold color="#8b90a0" wrap="wrap">
{" "}
</Text>
</Box>
<Box>
<Box flexDirection="row" alignItems="center" columnGap={1} flexShrink={0} flexWrap="wrap">
<Box width={4} height={1} overflow="hidden">
<Box position="absolute" top={0} left={0} width={4} height={1} borderStyle="round" borderColor="#00000000" />
<Box position="absolute" top={0} left={0} width={4} height={1} alignItems="center" justifyContent="center">
<Svg alt="Auto compact on" source={`${switchSvg}`} width={30} height={20} />
</Box>
<Box position="absolute" top={0} left={0}>
<Button label=" " plain />
</Box>
</Box>
<Text color="#8b90a0">
Auto compact
</Text>
<Box flexDirection="row" alignItems="center">
<Box width={4} overflow="hidden">
<Box width={6} flexShrink={0}>
<Input value={`${drawnAt}`} submitLabel="" />
</Box>
</Box>
<Text color="#8b90a0">
%
</Text>
</Box>
<Box marginLeft={2}>
<Button label="Compact" />
</Box>
<Button label="▲" plain />
</Box>
</Box>
</Box>
<Box flexDirection="row" alignItems="center" columnGap={1}>
<Box flexShrink={1}>
<Text color="#fbbf24" wrap="wrap">
{`Context is already at ${percent}%, past ${at}%. Auto compact:`}
</Text>
</Box>
<Box flexDirection="row" columnGap={1} flexWrap="wrap" flexShrink={0}>
<Button label="Now" />
<Button label="After my next compact" />
<Button label="Only in new chats" />
</Box>
</Box>
<Box flexDirection="column">
<Box flexDirection="column" width="50%">
<Text color="#8b90a0" wrap="wrap">
Usage limits show after the first reply.
</Text>
<Text color="#fbbf24" wrap="wrap">
{stale}
</Text>
<Box flexDirection="column">
<Box flexDirection="row">
<Box width={8} flexShrink={0}>
<Text bold wrap="truncate-end">
{label}
</Text>
</Box>
<Box flexDirection="row">
<Box>
<Text>
{" "}
</Text>
</Box>
<Box>
<Text>
{" "}
</Text>
</Box>
<Box>
<Text>
{" "}
</Text>
</Box>
</Box>
<Box marginLeft={2} flexShrink={0}>
<Text bold>
{`${percent}%`}
</Text>
</Box>
</Box>
<Text color="#8b90a0" wrap="wrap">
{note}
</Text>
<Text>
{" "}
</Text>
</Box>
<Box flexDirection="column">
<Box flexDirection="row">
<Box width={8} flexShrink={0}>
<Text bold wrap="truncate-end">
{label2}
</Text>
</Box>
<Box flexDirection="row">
<Box>
<Text>
{" "}
</Text>
</Box>
<Box>
<Text>
{" "}
</Text>
</Box>
<Box>
<Text>
{" "}
</Text>
</Box>
</Box>
<Box marginLeft={2} flexShrink={0}>
<Text bold>
{`${percent}%`}
</Text>
</Box>
</Box>
<Text color="#8b90a0" wrap="wrap">
{note2}
</Text>
<Text>
{" "}
</Text>
</Box>
<Box flexDirection="column">
<Box flexDirection="row">
<Box width={8} flexShrink={0}>
<Text bold wrap="truncate-end">
{label3}
</Text>
</Box>
<Box flexDirection="row">
<Box>
<Text>
{" "}
</Text>
</Box>
<Box>
<Text>
{" "}
</Text>
</Box>
<Box>
<Text>
{" "}
</Text>
</Box>
</Box>
<Box marginLeft={2} flexShrink={0}>
<Text bold>
{`${percent}%`}
</Text>
</Box>
</Box>
<Text color="#8b90a0" wrap="wrap">
{note3}
</Text>
<Text>
{" "}
</Text>
</Box>
</Box>
<Text>
{" "}
</Text>
<Box flexDirection="column" width="50%">
<Box flexDirection="row">
<Box>
<Text>
{" "}
</Text>
</Box>
<Box>
<Text>
{" "}
</Text>
</Box>
<Box>
<Text>
{" "}
</Text>
</Box>
</Box>
<Box flexDirection="row" justifyContent="space-between" columnGap={2}>
<Box flexDirection="row">
<Text bold>
Context
</Text>
<Box marginLeft={2}>
<Text bold>
{`${percent}% used`}
</Text>
</Box>
</Box>
<Text color="#8b90a0">
{`${tokens} free of ${tokens}`}
</Text>
</Box>
<Box flexDirection="row" justifyContent="space-between">
<Text>
{name}
</Text>
<Text color="#8b90a0">
{tokens}
</Text>
</Box>
<Box flexDirection="row" justifyContent="space-between">
<Text>
{name2}
</Text>
<Text color="#8b90a0">
{tokens2}
</Text>
</Box>
<Box flexDirection="row" justifyContent="space-between">
<Text>
{name3}
</Text>
<Text color="#8b90a0">
{tokens3}
</Text>
</Box>
</Box>
</Box>
{await next(e)}
</Box>
)
})
on('session.start', async ($, e, next) => {
const message = '…'
const skip = '…'
const percent = '…'
const at = '…'
await $.ui.status(`claude-code-usage-quota: ${message}`)
await $.ui.toast(`Auto compact was skipped: ${skip}`)
await $.ui.toast(`Context is still at ${percent}% after compacting, past your ${at}%: auto compact waits until it drops below`)
return next(e)
})
}
Mod 自身のコード
Mod のライセンス(MIT)に従って載せています。全文は下にあります。写すときは著作権表示を残してください。
hooks/register.tsx 1001〜1160 行 · バンド
on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
if (e.props.hasSurvey || !(await read($, isOn))) return next(e)
const snap = await read($, snapshot)
if (!snap) return next(e)
const table = $.ui.resolve(e)
const { Box, Text, Button, Input } = table
const Svg = e.surface === 'desktop' && 'Svg' in table ? table.Svg : undefined
usePalette(e.surface === 'desktop' && (await read($, theme)) === 'light' ? LIGHT : DARK)
const width = Math.max(20, e.props.bodyColumns)
const now = await $.clock.now()
// both windows always, once there is any reading: one the reading lacks is not running
const known = snap.limits.length === 0 ? [] : Object.keys(WINDOWS).map(kind => snap.limits.find(l => l.kind === kind) ?? { kind, percentUsed: 0 })
const list = known.map(l => forecast(l, now, snap.pace?.[l.kind])).filter((f): f is Forecast => f !== null)
const head = headline(list, now)
// free as /context has it: the window less what is used and the autocompact buffer
const buffer = snap.categories.find(c => c.kind === 'buffer')?.tokens ?? 0
const free = Math.max(0, snap.window - snap.tokens - buffer)
// highest first, as /context lists them: used categories, then the buffer, then free space
const rank = (c: Category) => (c.kind === 'used' ? 0 : c.kind === 'buffer' ? 1 : 2)
const shown = snap.categories
.map((c, i) => ({ ...c, color: colorOf(c, i) }))
.sort((a, b) => rank(a) - rank(b) || b.tokens - a.tokens)
const limits = [...list].sort((a, b) => order(a.kind) - order(b.kind))
// say so when the figures are old: the service refused and no reply has come since
const age = snap.limitsAt === undefined ? 0 : now - snap.limitsAt
const stale =
snap.limitsError && age >= 2 * 60_000 && limits.length > 0
? `usage check ${snap.limitsError} – figures from ${duration(age)} ago`
: snap.limitsError && limits.length === 0
? `usage check ${snap.limitsError}`
: undefined
const collapsed = await read($, isCollapsed)
const auto = await read($, autoCompact)
const ask = await read($, autoAsk)
const tick = await read($, fieldTick)
const drawnAt = (await read($, fieldText)) ?? `${auto.at ?? AT_DEFAULT}`
const submitAt = (value: string) => commitAt($, value)
const toggleAuto = () => {
const flipped = { isOn: !auto.isOn, at: auto.at ?? AT_DEFAULT }
void saveAuto($, flipped).then(() =>
flipped.isOn ? askIfPast($, flipped.at) : update($, autoAsk, () => null),
)
}
// Laid out to the width the chat gives the band, down to the desktop's narrowest
// chat: what fits side by side stays side by side; past that it stacks, and text
// wraps rather than cuts off.
// The header: the headline beside the controls when both fit, else the controls
// on a row of their own beneath it
// (the desktop's letters are narrower than its cells: about 0.8 of one)
const CONTROLS = 40
// the terminal draws its own hide control ([-]) over the band's top-right
// corner: the first row keeps clear of it
const HOST_HIDE = Svg ? 0 : 4
const isHeadBeside = width >= (head?.text.length ?? 0) * (Svg ? 0.8 : 1) + CONTROLS + HOST_HIDE
// the windows and the context side by side, or one above the other
const isSplit = width >= 84
const column = isSplit ? Math.floor((width - 4) / 2) : width
// the limit bars fill their column: less the label (8) and the % (2 + 4)
const cells = Math.max(6, column - 14)
// collapsed: the three bars in one row, or each on a row of its own
const isOneRow = width >= 72
// the context's two figures on one line, or the free count on the next
const isContextLine = column >= 38
// the question and its three answers on one line when they fit, else the answers
// beneath: measured from the words themselves (the desktop draws text narrower than
// a cell each, as the headline's check allows), each button's chrome and the gaps
const ASK_LABELS = ['Now', 'After my next compact', 'Only in new chats']
const askWords = (ask ? `Context is already at ${ask.percent}%, past ${ask.at}%. Auto compact:`.length : 0) + ASK_LABELS.join('').length
const isAskLine = width >= askWords * (Svg ? 0.8 : 1) + ASK_LABELS.length * (Svg ? 3 : 4) + 3
const controls = (
<Box flexDirection="row" alignItems="center" columnGap={1} flexShrink={0} flexWrap="wrap">
{/* auto compact: the switch (the press), its name, the % field beside it,
then a wide gap so the field reads as the switch's, not Compact's */}
{Svg ? (
<Box key="autoSwitch" width={SWITCH_CELLS} height={1} overflow="hidden">
{/* three layers, each the box's full size, so all share one centre: the
rounded light (unlit: an invisible border), the pill, the press */}
<Box position="absolute" top={0} left={0} width={SWITCH_CELLS} height={1} borderStyle="round" borderColor={CLEAR} hover={{ backgroundColor: SWITCH_LIT, borderColor: SWITCH_LIT }} />
<Box position="absolute" top={0} left={0} width={SWITCH_CELLS} height={1} alignItems="center" justifyContent="center">
<Svg alt={`Auto compact ${auto.isOn ? 'on' : 'off'}`} source={switchSvg(auto.isOn)} width={SWITCH_W} height={SWITCH_H} />
</Box>
{/* a chromeless button over all of it takes the click */}
<Box position="absolute" top={0} left={0}>
<Button key="auto" label={' '} plain hover={{ backgroundColor: CLEAR }} onPress={toggleAuto} />
</Box>
</Box>
) : (
<Button key="auto" label={auto.isOn ? '●' : '○'} plain onPress={toggleAuto} />
)}
<Text color={auto.isOn ? undefined : MUTED}>Auto compact</Text>
{auto.isOn ? (
// the field (3 digits) sets itself once typing pauses; a plain % right after it
<Box flexDirection="row" alignItems="center">
{/* the field's Enter chip can't be turned off: the field is drawn wider than
its box and the box clips the chip away */}
<Box width={4} overflow="hidden">
<Box width={6} flexShrink={0}>
<Input
key={`autoAt${tick}`}
value={drawnAt}
submitLabel={''}
onInput={value => typedAt($, value)}
onSubmit={value => submitAt(value)}
/>
</Box>
</Box>
<Text color={MUTED}>%</Text>
</Box>
) : Svg ? (
// off: the field's room is kept, unseen, so the switch sits at the very same
// spot and draws pixel for pixel as when on
<Box flexDirection="row" alignItems="center">
<Box width={4} />
<Text color={CLEAR}>%</Text>
</Box>
) : null}
<Box key="compactBox" marginLeft={isHeadBeside ? 2 : 0}>
<Button key="compact" label="Compact" hover={{ backgroundColor: COMPACT_LIT }} onPress={() => compactNow($)} />
</Box>
<Button
key="collapse"
label={collapsed ? '▲' : '▼'}
plain
onPress={async () => {
// from the state, not this closure's value (an older draw's); saved for
// the other chats first, so the half-second read never undoes the press
const now = !(await read($, isCollapsed))
await storeSet($, 'collapsed', now)
await update($, isCollapsed, () => now)
}}
/>
</Box>
)
const gap = Svg ? 0.5 : 1
const headText = <Text bold color={head ? ink(head.color) : MUTED} wrap="wrap">{head?.text ?? ' '}</Text>
// one bar: an Svg on the desktop, coloured cells on the terminal
const bar = (alt: string, segments: { color: string; share: number }[], barCells: number, marker?: number, f?: Forecast) =>
Svg ? (
<Box width={barCells} height={1} alignItems="center">
<Svg alt={alt} source={barSvg(segments, barCells * 8, marker)} height={BAR_PX} />
</Box>
) : f ? (
<Box flexDirection="row" width={barCells}>
{cellRuns(f, barCells).map(run => (
<Box width={run.width} backgroundColor={run.color}>
<Text> </Text>
</Box>
))}
</Box>
) : (
<Box flexDirection="row" width={barCells} overflow="hidden">
{segments.map(seg => {
const total = segments.reduce((sum, s) => sum + s.share, 0) || 1
return (
<Box backgroundColor={seg.color} flexGrow={Math.min(10000, Math.max(seg.share > 0 ? 1 : 0, Math.round((seg.share / total) * 1000)))} flexShrink={1}>
<Text> </Text>ライセンスの全文(MIT)
MIT License Copyright (c) 2026 Anant Raghunath 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 に読んだコミット dfe493f114cd のソースから。最初のまとまりが載せる条件で、残りは自分で判断するための材料です。後のコミットは、次に読むまで見ていません。
| 載せる条件: 確かめやすいコード | |
|---|---|
| 入口を読んだ | hooks/hooks.json が名指すモジュールをすべて読んだ。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/… などは無い)。hooks/register.tsx:800 defaults(Windows にない) |
| 通信 | fetch の送り先(https のホスト)がコードに書いてあるか。https://api.anthropic.com |
| プログラム | 起動するプログラムの名前がコードに書いてあり、シェル・インタプリタ・通信用の道具でないか。reg, defaults |
| 読んで送る | ファイルや環境変数を読み、かつ通信するか。reads environment variables and files and reaches the network |
| ソースの鍵 | ソースに API キーや秘密鍵らしきものがあるか。ソースに鍵なし |
| ライセンス | オープンなライセンス(MIT・Apache-2.0・BSD・ISC・Unlicense・0BSD・CC0)で全文があれば、modscode にコードを載せる。違えばリンクだけ。MIT |
コードの文面を読んだだけで、安全の審査ではありません。動かしてはおらず、起動するプログラムの中で何が起きるかも見えません。入れる前の確認はあなたの役目です。 載せる条件
入れる
入れる前に、必ず自分で確かめてください。Mod はサンドボックスなしで、あなたの権限で動きます。modscode はこのコードの安全を保証しません。下のコードを読み(またはフォルダーで claude plugin validate .)、触るものを見て、読んだコミットを入れてください。
リポジトリがそのままマーケットプレイスです。このマーケットプレイスを足し(ターミナルでは次のコマンド、デスクトップアプリではプラグインの設定)、そこから Mod を入れます。
/plugin marketplace add anantraghunath/claude-code-usage-quota-mod/plugin install claude-code-usage-quota@claude-code-usage-quota-mod入るのはマーケットプレイスの最新のコミットで、ここで読んだもの(dfe493f114cd)と違うことがあります。入れる前に見比べてください。
Claude に聞く
modscode のコネクタを入れると、Claude がこのデザイン・コードが触るもの・コードを読んで、それをもとに作れます。たとえば:
modscode のデザイン「anantraghunath-claude-code-usage-quota」をコードごと読んで、同じようなペインを作って似たデザイン
-
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 に頼む…agent-discoverbuildbuildbuildRefreshMCP Browse/3Tab / shift+Tab move · Enter presses · ↑↓ scroll · Esc back to the promptBrowse...Audit asks:DeclineAcceptDeclineCancelAudit asks:DeclineAcceptDeclineCancelAudit asks:DeclineAcceptDeclineCancel
-
spending-effort-with-jev: no TypeSafe API key, so effort tips are off. Set it in /plugin.⚠ effort: long run, fuzzy spec → have Claude interview you, then go maxClaude に頼む…
-
5h▰▰▰▰▰▰▰▰▱▱▱▱▱▱▱▱3%Winding downWinding downWinding down7d▰▰▰▰▰▰▰▰▱▱▱▱▱▱▱▱3%Winding downWinding downWinding downctx3 / 3Winding downWinding downWinding downWinding downWinding downWinding down./click-probe.tsx●RetryingRefreshing…Long run ✓Winding downWinding downWinding downClaude に頼む…
-
✦ explain as pick how Claude answers×3 ● build3 ● build3 ● build▸ VideoClaude に頼む…