modscode EN

modscode / 図鑑 / usage

usage

Model, folder, git branch/worktree, context and rate-limit band above the prompt, with threshold toasts, /limits and a /ctx pane

確かめやすいコードターミナル+デスクトップペインバンドトーストBoxButtonText

何をするか

  • プロンプトの上の帯・欄・トーストを描く
  • /autocompact・/limits・/ctx を足す
  • session.measure・session.start・turn.stepにフックする
  • プロセスを起こす

良いところ

  • ネットワークに出ない
  • TypeScript で書かれている
  • デスクトップ専用の分岐がある
  • エラーを扱う

作り始めるためのコード

2 種類あります。上のデザインから modscode が書いた雛形と、その Mod 自身のコードのうち描いている部分です。

雛形(register.tsx)

register.tsx
import type { Register } from 'claude-code'

// Drawn like usage by jacky (pane, band, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/jaaaackielai-usage/
// 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 } = $.ui.resolve(e)
    return (
      <Box flexDirection="column">
        <Box flexDirection="row" flexWrap="wrap" columnGap={1} rowGap={0} alignItems="center" />
        {await next(e)}
      </Box>
    )
  })

  // the pane: open it with $.ui.open({ id: 'my-pane', title: "Context 明細" })
  on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
    const { Box, Text, Button } = $.ui.resolve(e)
    const fmtTokens = '…'
    const fmtTokens2 = '…'
    const pct = '…'
    const name = '…'
    const fmtTokens3 = '…'
    const pctOf = '…'
    const name2 = '…'
    const fmtTokens4 = '…'
    const pctOf2 = '…'
    const name3 = '…'
    const fmtTokens5 = '…'
    const pctOf3 = '…'
    const fmtTokens6 = '…'
    const path = '…'
    const fmtTokens7 = '…'
    const path2 = '…'
    const fmtTokens8 = '…'
    const path3 = '…'
    return (
      <Box flexDirection="column">
        <Text bold>
          {"已用 "}
          {fmtTokens}
          {" / 自動壓縮 "}
          {fmtTokens2}
          (
          <Text>
            {pct}
            %
          </Text>
          )
          <Text dimColor>
            {" "}
            精確
            ,更新中…
          </Text>
        </Text>
        <Box flexDirection="row" gap={3} marginTop={1}>
          <Text>
            <Text>
              ████████
            </Text>
            <Text>
              ████████
            </Text>
            <Text>
              ████████
            </Text>
          </Text>
          <Box flexDirection="column" justifyContent="center">
            <Text>
              <Text>
                ■
              </Text>
              {" "}
              {name}
              <Text dimColor>
                {" "}
                {fmtTokens3}
                {" "}
                {pctOf}
                %
              </Text>
            </Text>
            <Text>
              <Text>
                ■
              </Text>
              {" "}
              {name2}
              <Text dimColor>
                {" "}
                {fmtTokens4}
                {" "}
                {pctOf2}
                %
              </Text>
            </Text>
            <Text>
              <Text>
                ■
              </Text>
              {" "}
              {name3}
              <Text dimColor>
                {" "}
                {fmtTokens5}
                {" "}
                {pctOf3}
                %
              </Text>
            </Text>
          </Box>
        </Box>
        <Box flexDirection="column" marginTop={1}>
          <Text dimColor>
            最大的記憶檔:
          </Text>
          <Text dimColor wrap="truncate-start">
            {"  "}
            {fmtTokens6}
            {" "}
            {path}
          </Text>
          <Text dimColor wrap="truncate-start">
            {"  "}
            {fmtTokens7}
            {" "}
            {path2}
          </Text>
          <Text dimColor wrap="truncate-start">
            {"  "}
            {fmtTokens8}
            {" "}
            {path3}
          </Text>
        </Box>
        <Box flexDirection="row" gap={1} marginTop={1}>
          <Button label="重新估算" hotkey="r" />
          <Button label="精確計算" hotkey="f" />
          <Button label="關閉" hotkey="q" />
        </Box>
      </Box>
    )
  })

  on('session.start', async ($, e, next) => {
    const label = '…'
    const pct = '…'
    const hint = '…'
    await $.ui.toast(`${label}已達 ${pct}%${hint}`)
    return next(e)
  })
}

Mod 自身のコード

Mod のライセンス(MIT)に従って載せています。全文は下にあります。写すときは著作権表示を残してください。

plugins/usage/hooks/register.tsx 449〜537 行 · バンド
  on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
    const usage = await read($, usageAtom)
    if (e.props.hasSurvey || usage === null) return next(e)
    const nowMs = await read($, nowAtom)
    const history = await read($, historyAtom)
    const effort = await read($, effortAtom)
    const ui = $.ui.resolve(e)
    const { Box, Text } = ui
    const isNarrow = e.props.bodyColumns < 80
    const hasSvg = e.surface !== 'terminal' && 'Svg' in ui

    // Desktop surfaces draw the line icons; the terminal a glyph in the same color.
    const icon = (name: IconName, color: string) =>
      hasSvg ? (
        <ui.Svg source={iconSvg(name, color)} alt={name} width={14} height={14} />
      ) : (
        <Text color={color}>{ICON_GLYPH[name]}</Text>
      )

    const chip = (key: string, tone: Tone, children: RenderChildren) => (
      <Box key={key} flexDirection="row" alignItems="center" columnGap={1} backgroundColor={tone.bg} paddingX={1}>
        {children}
      </Box>
    )
    const divider = (tone: Tone) => <Text color={tone.line}>│</Text>

    const ctx = usage.ctxPct
    const prev = history.length >= 2 ? history[history.length - 2] : undefined
    const last = history.length >= 1 ? history[history.length - 1] : undefined
    const delta = prev !== undefined && last !== undefined ? last - prev : 0

    const rate = (key: string, name: IconName, tone: Tone, w: LimitWindow | undefined, days: boolean) => {
      if (!w) return chip(key, tone, [icon(name, tone.fg), <Text color={tone.dim}>--</Text>])
      const until = untilStr(w.resetsAt, nowMs, days)
      return chip(key, tone, [
        icon(name, tone.fg),
        !isNarrow && meter(Text, w.pct, tone),
        <Text color={levelOf(w.pct) === 0 ? T_TEXT : colorOf(w.pct)} bold>{w.pct}%</Text>,
        until && divider(tone),
        until && <Text color={T_TEXT}>{until}</Text>,
      ])
    }

    const chips = [
      !isNarrow &&
        chip('model', TONE_MODEL, [
          icon('model', TONE_MODEL.fg),
          <Text color={T_TEXT} bold>{usage.model}</Text>,
          effort && divider(TONE_MODEL),
          effort && <Text color={TONE_MODEL.fg}>{effort}</Text>,
        ]),
      !isNarrow &&
        chip('dir', TONE_DIR, [
          icon('folder', TONE_DIR.fg),
          <Text color={T_TEXT}>{usage.dir}</Text>,
          usage.git && divider(TONE_DIR),
          usage.git && <Text color={C_BRANCH}>🌿 {usage.git.branch}</Text>,
          usage.git?.worktree && <Text color={C_ORANGE}>wt:{usage.git.worktree}</Text>,
        ]),
      ctx === undefined
        ? chip('ctx', TONE_DIR, [<Text color={TONE_DIR.dim}>ctx --</Text>])
        : chip('ctx', TONE_CTX, [
            <Text color={TONE_CTX.fg}>ctx</Text>,
            !isNarrow && meter(Text, ctx, TONE_CTX),
            <Text color={levelOf(ctx) === 0 ? T_TEXT : colorOf(ctx)} bold>{ctx}%</Text>,
            !isNarrow && Math.abs(delta) >= 1000 && (
              <Text color={TONE_CTX.dim}>{delta > 0 ? '▲' : '▼'}{fmtTokens(Math.abs(delta))}</Text>
            ),
          ]),
      rate('h5', 'gauge', TONE_H5, usage.h5, false),
      rate('d7', 'calendar', TONE_D7, usage.d7, true),
    ]

    const band = (
      <Box flexDirection="row" flexWrap="wrap" columnGap={1} rowGap={0} alignItems="center">
        {chips.filter(Boolean)}
      </Box>
    )

    // Share the band: whatever the plugins beneath draw (e.g. typo-picker) goes under the chips.
    const below = await next(e)
    if (!below) return band
    return (
      <Box flexDirection="column">
        {band}
        {below}
      </Box>
    )
  })
plugins/usage/hooks/register.tsx 540〜608 行 · ペイン
  on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
    const ui = $.ui.resolve(e)
    const { Box, Text, Button } = ui
    const b = await read($, breakdownAtom)
    const isLoading = await read($, loadingAtom)

    const buttons = (
      <Box flexDirection="row" gap={1} marginTop={1}>
        <Button key="refresh" label="重新估算" hotkey="r" onPress={() => loadBreakdown($, 'summary')} />
        <Button key="full" label="精確計算" hotkey="f" onPress={() => loadBreakdown($, 'full')} />
        <Button key="close" label="關閉" hotkey="q" onPress={() => $.ui.close({ id: PANE })} />
      </Box>
    )

    if (b === null) {
      return (
        <Box flexDirection="column">
          <Text dimColor>{isLoading ? '計算中…' : '尚無資料'}</Text>
          {buttons}
        </Box>
      )
    }

    const slices = pieSlices(b)
    const legend = (
      <Box flexDirection="column" justifyContent="center">
        {slices.map(s => (
          <Text>
            <Text color={s.color}>■</Text> {s.name.padEnd(18).slice(0, 18)}
            <Text dimColor> {fmtTokens(s.tokens).padStart(6)} {String(pctOf(s.tokens, b.max)).padStart(3)}%</Text>
          </Text>
        ))}
      </Box>
    )

    // The terminal draws a real pie; other surfaces get one 100% stacked bar.
    const chart =
      e.surface === 'terminal' && 'Raster' in ui ? (
        <ui.Raster key="pie" columns={PIE_COLS} rows={PIE_COLS / 2} cells={pieCells(slices, PIE_COLS)} />
      ) : (
        <Text>
          {slices.map(s => (
            <Text color={s.color}>{'█'.repeat(Math.max(s.tokens > 0 ? 1 : 0, Math.round((s.tokens / b.max) * 40)))}</Text>
          ))}
        </Text>
      )

    return (
      <Box flexDirection="column">
        <Text bold>
          已用 {fmtTokens(b.total)} / 自動壓縮 {fmtTokens(b.max)}(<Text color={colorOf(b.pct)}>{b.pct}%</Text>)
          <Text dimColor> {b.detail === 'full' ? '精確' : '估算'}{isLoading ? ',更新中…' : ''}</Text>
        </Text>
        <Box flexDirection="row" gap={3} marginTop={1}>
          {chart}
          {legend}
        </Box>
        <Box flexDirection="column" marginTop={1}>
          {b.memory.length > 0 && <Text dimColor>最大的記憶檔:</Text>}
          {b.memory.map(m => (
            <Text dimColor wrap="truncate-start">
              {'  '}{fmtTokens(m.tokens).padStart(7)} {m.path}
            </Text>
          ))}
        </Box>
        {buttons}
      </Box>
    )
  })
ライセンスの全文(MIT)
MIT License

Copyright (c) 2026 jacky

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 に読んだコミット c2406efc81e4 のソースから。最初のまとまりが載せる条件で、残りは自分で判断するための材料です。後のコミットは、次に読むまで見ていません。

載せる条件: 確かめやすいコード
入口を読んだhooks/hooks.json が名指すモジュールをすべて読んだ。plugins/usage/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 のホスト)がコードに書いてあるか。通信なし
プログラム起動するプログラムの名前がコードに書いてあり、シェル・インタプリタ・通信用の道具でないか。git(通信する)
読んで送るファイルや環境変数を読み、かつ通信するか。読んだうえで通信する
ソースの鍵ソースに API キーや秘密鍵らしきものがあるか。ソースに鍵なし
ライセンスオープンなライセンス(MIT・Apache-2.0・BSD・ISC・Unlicense・0BSD・CC0)で全文があれば、modscode にコードを載せる。違えばリンクだけ。MIT

コードの文面を読んだだけで、安全の審査ではありません。動かしてはおらず、起動するプログラムの中で何が起きるかも見えません。入れる前の確認はあなたの役目です。 載せる条件

入れる

入れる前に、必ず自分で確かめてください。Mod はサンドボックスなしで、あなたの権限で動きます。modscode はこのコードの安全を保証しません。下のコードを読み(またはフォルダーで claude plugin validate .)、触るものを見て、読んだコミットを入れてください。

リポジトリがそのままマーケットプレイスです。このマーケットプレイスを足し(ターミナルでは次のコマンド、デスクトップアプリではプラグインの設定)、そこから Mod を入れます。

/plugin marketplace add jaaaackieLai/claude-mods
/plugin install usage@claude-mods

入るのはマーケットプレイスの最新のコミットで、ここで読んだもの(c2406efc81e4)と違うことがあります。入れる前に見比べてください。

Claude に聞く

modscode のコネクタを入れると、Claude がこのデザイン・コードが触るもの・コードを読んで、それをもとに作れます。たとえば:

modscode のデザイン「jaaaackielai-usage」をコードごと読んで、同じようなペインを作って

Claude から探す: MCP コネクタ

似たデザイン