modscode JA

modscode / Gallery / usage-mod

usage-mod

在输入框上方常驻显示上下文占用、5 小时额度、每周额度和重置时间,带一键压缩上下文的按钮

Code you can checkTerminal + desktopBandToastBoxButtonSvgText

What it does

  • Draws a band above the prompt
  • Hooks session.measure, session.start, turn.complete

Good points

  • No network calls
  • Starts no processes
  • Written in TypeScript
  • Has a desktop-specific branch

Code to start from

Two kinds: a starter modscode writes from the design above, and the lines of the mod's own code that draw it.

Starter (register.tsx)

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

// Drawn like usage-mod by qingyashizi (band, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/qingyashizi-usage-mod/
// 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 } = $.ui.resolve(e)
    const statsTitle = '…'
    const label = '…'
    const value = '…'
    const label2 = '…'
    const value2 = '…'
    const label3 = '…'
    const value3 = '…'
    const turnsText = '…'
    const turnsText2 = '…'
    const seriesLabel = '…'
    const chartDesktopOnly = '…'
    const lineIconSvg = '…'
    const tip = '…'
    const text = '…'
    const text2 = '…'
    const text3 = '…'
    const text4 = '…'
    const text5 = '…'
    const text6 = '…'
    const statsTip = '…'
    return (
      <Box width="100%" flexDirection="column" gap={1}>
        <Box flexDirection="column" width="100%" alignItems="center">
          <Box width="100%" justifyContent="center">
            <Box position="absolute" top={0} left={0}>
              <Text bold>
                {statsTitle}
              </Text>
            </Box>
            <Box gap={3}>
              <Box gap={1}>
                <Text dimColor>
                  {label}
                </Text>
                <Text bold>
                  {value}
                </Text>
              </Box>
              <Box gap={1}>
                <Text dimColor>
                  {label2}
                </Text>
                <Text bold>
                  {value2}
                </Text>
              </Box>
              <Box gap={1}>
                <Text dimColor>
                  {label3}
                </Text>
                <Text bold>
                  {value3}
                </Text>
              </Box>
            </Box>
            <Box position="absolute" top={0} right={0}>
              <Text bold>
                {turnsText}
              </Text>
            </Box>
          </Box>
          <Box flexDirection="column" width="100%" alignItems="center">
            <Box width="100%" justifyContent="center" gap={2}>
              <Box position="absolute" top={0} right={0}>
                <Text bold>
                  {turnsText2}
                </Text>
              </Box>
              <Box gap={1}>
                <Text>
                  ●
                </Text>
                <Button label={`${seriesLabel}`} plain />
              </Box>
              <Box gap={1}>
                <Text>
                  ●
                </Text>
                <Button label={`${seriesLabel}`} plain />
              </Box>
              <Box gap={1}>
                <Text>
                  ●
                </Text>
                <Button label={`${seriesLabel}`} plain />
              </Box>
            </Box>
            <Text dimColor>
              {chartDesktopOnly}
            </Text>
          </Box>
        </Box>
        <Box width="100%" justifyContent="center" gap={1}>
          <Box width={3} height={1} position="relative" justifyContent="center">
            <Svg source={`${lineIconSvg}`} alt={`${tip}`} width={24} height={22} />
            <Box position="absolute" top={0} left={0} width={3} height={1}>
              <Button label="   " plain />
            </Box>
            <Button label="🗜" plain />
            <Box position="absolute" top={0} left={3} height={1} justifyContent="center" backgroundColor="#D77757" display="none">
              <Text color="#161616">
                {tip}
              </Text>
            </Box>
          </Box>
          <Box height={1} backgroundColor="#3f3f46">
            <Box position="absolute" top={0} left={0} height={1} backgroundColor="#D77757" overflow="hidden">
              <Box position="absolute" top={0} left="0" height={1} justifyContent="center">
                <Text color="#161616" wrap="truncate-end">
                  {text}
                </Text>
              </Box>
            </Box>
            <Box position="absolute" top={0} height={1} overflow="hidden">
              <Box position="absolute" top={0} height={1} justifyContent="center">
                <Text color="#ececec" wrap="truncate-end">
                  {text2}
                </Text>
              </Box>
            </Box>
          </Box>
          <Box height={1} backgroundColor="#3f3f46">
            <Box position="absolute" top={0} left={0} height={1} backgroundColor="#D77757" overflow="hidden">
              <Box position="absolute" top={0} left="0" height={1} justifyContent="center">
                <Text color="#161616" wrap="truncate-end">
                  {text3}
                </Text>
              </Box>
            </Box>
            <Box position="absolute" top={0} height={1} overflow="hidden">
              <Box position="absolute" top={0} height={1} justifyContent="center">
                <Text color="#ececec" wrap="truncate-end">
                  {text4}
                </Text>
              </Box>
            </Box>
          </Box>
          <Box height={1} backgroundColor="#3f3f46">
            <Box position="absolute" top={0} left={0} height={1} backgroundColor="#D77757" overflow="hidden">
              <Box position="absolute" top={0} left="0" height={1} justifyContent="center">
                <Text color="#161616" wrap="truncate-end">
                  {text5}
                </Text>
              </Box>
            </Box>
            <Box position="absolute" top={0} height={1} overflow="hidden">
              <Box position="absolute" top={0} height={1} justifyContent="center">
                <Text color="#ececec" wrap="truncate-end">
                  {text6}
                </Text>
              </Box>
            </Box>
          </Box>
          <Box width={3} height={1} position="relative" justifyContent="center">
            <Svg source={`${lineIconSvg}`} alt={`${tip}`} width={24} height={22} />
            <Box position="absolute" top={0} left={0} width={3} height={1}>
              <Button label="   " plain />
            </Box>
            <Button label="≡" plain />
            <Box position="absolute" top={0} left={3} height={1} justifyContent="center" backgroundColor="#D77757" display="none">
              <Text color="#161616">
                {statsTip}
              </Text>
            </Box>
          </Box>
        </Box>
        {await next(e)}
      </Box>
    )
  })
}

The mod's own code

Shown under the mod's licence (MIT); its text is below. Keep the notice if you copy these lines.

plugins/usage-mod/hooks/register.tsx lines 386–545 · Band
  on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
    if (e.props.hasSurvey) return next(e)

    const data = await read($, usage)
    const at = await read($, now)
    const isOpen = await read($, statsOpen)
    const { total, recent } = await read($, stats)
    const hidden = await read($, hiddenSeries)

    const five = find(data.limits, 'five_hour')
    const week = find(data.limits, 'seven_day')
    const elements = $.ui.resolve(e)
    const { Box, Button, Text } = elements
    // 折线图是 SVG,只有桌面端等远程界面有这个元素。
    const Svg = 'Svg' in elements ? elements.Svg : undefined
    const isTerminal = e.surface === 'terminal'

    if (e.props.bodyColumns < 78) {
      const short = [
        data.context === undefined ? `${L.shortCtx} —` : `${L.shortCtx} ${Math.round(data.context)}%`,
        five === undefined ? `${L.shortFive} —` : `${L.shortFive} ${Math.round(five.percentUsed)}%`,
        week === undefined ? `${L.shortWeek} —` : `${L.shortWeek} ${Math.round(week.percentUsed)}%`,
      ].join(' · ')

      return (
        <Box width="100%" justifyContent="center">
          <Text>{short}</Text>
        </Box>
      )
    }

    // 三块等宽,块之间各留一格;减去的是两个按钮和四处间隙占的格数,不再额外留边距。
    const cells = Math.max(20, Math.floor((e.props.bodyColumns - 4 - 2 * BUTTON_CELLS) / 3))

    // 几何全部交给 Box:底色块铺满整块,橙色填充按百分比取宽度。
    // 文字画两层、各裁一半:填充内是深色字,填充外是浅色字,在填充边界处切开。
    // 不用空格撑宽度,因为桌面端字体不是等宽的,空格撑出来的宽度和 Box 的宽度对不上。
    const block = (key: string, label: string, percent: number | undefined, detail: string) => {
      const text = percent === undefined ? `${label} —` : `${label} ${Math.round(percent)}%${detail === '' ? '' : ` · ${detail}`}`
      const filled = percent === undefined ? 0 : percent <= 0 ? 0 : Math.min(cells, Math.max(1, Math.round((percent / 100) * cells)))
      const layer = (color: string, shift: number) => (
        <Box position="absolute" top={0} left={shift} width={cells} height={1} justifyContent="center">
          <Text color={color} wrap="truncate-end">
            {text}
          </Text>
        </Box>
      )

      return (
        <Box key={key} width={cells} height={1} backgroundColor={WARM}>
          {filled > 0 && (
            <Box position="absolute" top={0} left={0} width={filled} height={1} backgroundColor={ORANGE} overflow="hidden">
              {layer(DARK, 0)}
            </Box>
          )}
          {filled < cells && (
            <Box position="absolute" top={0} left={filled} width={cells - filled} height={1} overflow="hidden">
              {layer(LIGHT, -filled)}
            </Box>
          )}
        </Box>
      )
    }

    const ctxDetail = data.tokens === undefined ? '' : `${tokensText(data.tokens)} / ${tokensText(data.window)}`
    const fiveDetail = five === undefined ? '' : `${remaining(L, five.resetsAt, at)} · ${clock(L, five.resetsAt, at)}`
    const weekDetail = week === undefined ? '' : `${remaining(L, week.resetsAt, at)} · ${clock(L, week.resetsAt, at)}`

    const compact = async () => {
      $.ui.toast(L.compacting)
      try {
        // 不用 $.session.compact():桌面应用的会话是 SDK 无头会话,引擎不让插件直接调它。
        // 改成像用户输入 /compact 那样运行这条命令;引擎文档说回复进行中会排队到这一轮结束。
        await $.command.run({ command: 'compact' })
        $.ui.toast(L.compacted)
      } catch (err) {
        $.ui.toast(L.notCompacted(err instanceof Error ? err.message : String(err)))
      }
    }

    const toggleStats = () => void update($, statsOpen, open => !open)
    const toggleSeries = (key: SeriesKey) =>
      void update($, hiddenSeries, old => (old.includes(key) ? old.filter(one => one !== key) : [...old, key]))

    // 展开的明细:顶上是合计,中间是折线图,下面是曲线开关。画在横条里、用量条的上方,位置固定。
    const stat = (key: string, label: string, value: string) => (
      <Box key={key} gap={1}>
        <Text dimColor>{label}</Text>
        <Text bold>{value}</Text>
      </Box>
    )

    // 盖在折线图上的一排透明感应区,每轮一个,宽度按比例(flexGrow)和图里的点对齐(图是固定像素宽,Box 的宽度是格数;
    // 百分比宽度只收整数,量不准,所以按像素数当比例分)。鼠标移到某一轮上,同组(scope)的东西一起亮:这一列变成淡淡的高亮,图下面固定一行里显示那一轮的明细。
    // 悬停是应用自己处理的,没有任何东西回到插件,所以不会触发横条重画,图也就不会闪。
    // 横条的高度是应用定的(最多窗口的一半,放不下就滚动),所以图的高度跟着可用行数走,版面压紧:
    // 标题、曲线开关、关闭按钮一行,合计一行,其余都给图。一行大约按 20 像素算。
    const chartW = Math.round(Math.min(CHART_MAX_W, Math.max(CHART_MIN_W, e.props.bodyColumns * CHART_PX_PER_CELL)))
    const chartH = Math.max(140, Math.min(CHART_MAX_H, (e.props.maxRows - 5) * 20))

    // 第一行:合计在整行里居中,标题贴左、共几轮贴右(都不占位置)。放不下的东西按顺序让位:
    // 先去掉标题,再把"共几轮"挪到第二行,还不够就去掉合计里的命中率、新增输入。英文、日文的文字比中文长得多,所以按实际文字量算。
    const cols = e.props.bodyColumns
    const GAP = 3
    let items: Array<[string, string, string]> = [
      ['in', L.sIn, countText(total.input)],
      ['out', L.sOut, countText(total.output)],
      ['create', L.sCreate, countText(total.cacheCreate)],
      ['hit', L.sHit, countText(total.cacheRead)],
      ['rate', L.sRate, hitRate(total.input, total.cacheRead, total.cacheCreate)],
    ]
    const rowCells = (list: typeof items) => list.reduce((n, [, label, value]) => n + cellsOf(label) + 1 + cellsOf(value), 0) + GAP * (list.length - 1)
    for (const drop of ['rate', 'in']) if (rowCells(items) + 4 > cols) items = items.filter(([key]) => key !== drop)
    const freeSide = (cols - rowCells(items)) / 2
    const turnsText = L.statsTurns(total.turns)
    const showTitle = total.turns === 0 || freeSide >= cellsOf(L.statsTitle) + 2
    const showTurnsTop = freeSide >= cellsOf(turnsText) + 2

    const panel = (
      <Box key="stats-panel" flexDirection="column" width="100%" alignItems="center">
        {/* 第一行:五项合计居中,标题贴左、共几轮贴右;第二行:四条曲线的开关,居中。没有关闭按钮,收起靠右下角的图标。放不下时的让位顺序见上面。 */}
        <Box width="100%" justifyContent="center">
          {showTitle && (
            <Box position="absolute" top={0} left={0}>
              <Text bold>{L.statsTitle}</Text>
            </Box>
          )}
          {total.turns > 0 && (
            <Box gap={GAP}>{items.map(([key, label, value]) => stat(key, label, value))}</Box>
          )}
          {total.turns > 0 && showTurnsTop && (
            <Box position="absolute" top={0} right={0}>
              <Text bold>{turnsText}</Text>
            </Box>
          )}
        </Box>
        {total.turns === 0 ? (
          <Text dimColor>{L.statsEmpty}</Text>
        ) : (
          <Box flexDirection="column" width="100%" alignItems="center">
            {Svg !== undefined && (
              <Box width="100%" justifyContent="center" gap={2}>
                {!showTurnsTop && (
                  <Box position="absolute" top={0} right={0}>
                    <Text bold>{turnsText}</Text>
                  </Box>
                )}
                {SERIES.map(one => (
                  <Box key={one.key} gap={1}>
                    <Text color={one.color} dimColor={hidden.includes(one.key)}>
                      ●
                    </Text>
                    <Button key={`toggle-${one.key}`} label={seriesLabel(L, one.key)} plain dimColor={hidden.includes(one.key)} onPress={() => toggleSeries(one.key)} />
                  </Box>
                ))}
              </Box>
            )}
            {Svg === undefined ? (
              <Text dimColor>{L.chartDesktopOnly}</Text>
            ) : (
Licence text (MIT)
MIT License

Copyright (c) 2026 qingyashizi

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.

What its code calls

writes files

What its code shows

Read from the source at commit d114c7b07637 on 2026-10-06. 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 readEvery module hooks/hooks.json names was read.plugins/usage-mod/hooks/register.tsx
ParsesEvery file parses as TypeScript or JavaScript.2 files parsed
All its code is in the modEvery import is a file of the mod or the engine's own module; no packages, no require.all its code is in the mod
ReadableNo 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 openNetwork 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 drawsThe 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 lineWhether 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 WindowsWhether every program it starts through $.process exists on Windows (tail, date, open, osascript, /usr/… do not).runs no program a Windows PC lacks
NetworkWhether every fetch names its https host in the code.no network
ProgramsWhether 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 sendsWhether it both reads files or environment variables and reaches the network.reaches no network
Keys in the sourceWhether the source holds what looks like an API key or a private key.no keys in the source
LicenceAn 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

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 the code below (or run claude plugin validate . in its folder), weigh what it reaches, and install the commit you read.

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 qingyashizi/claude-usage-mod
/plugin install usage-mod@usage-mod

This installs the marketplace's latest commit, which may not be the one read here (d114c7b07637). Compare them before you install.

Ask Claude about it

With the modscode connector added, Claude can read this design, what its code reaches and its code, and build on them. Ask it like this:

Read the modscode design "qingyashizi-usage-mod" with its code and make me a pane like it

Search them from Claude: the MCP connector

Similar designs