modscode JA

modscode / Gallery / context-gauge

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

Code you can checkTerminal + desktopPaneBandToastBoxButtonClientInputSvgText

What it does

  • Draws a band above the prompt, a pane, toasts
  • Adds /gauge
  • Watches tool calls and can refuse them
  • Hooks config.set, session.append, session.measure, session.start and 4 more
  • Keeps its own state between turns

Good points

  • Starts no processes
  • Written in TypeScript
  • Has a desktop-specific branch
  • Handles errors

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 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)
  })
}

The mod's own code

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

context-gauge/hooks/register.tsx lines 1043–1202 · Band
  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 lines 1504–1544 · Band
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 lines 1561–1592 · Band
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 lines 1617–1673 · Band
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 lines 1231–1231 · Pane
  on('ui.render', { component: 'Pane', requestId: PANE }, ($, e) => drawGauge($, e, e.props.bodyColumns))
context-gauge/hooks/register.tsx lines 1897–2056 · Pane
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')}
Licence text (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.

What its code calls

networkdrives Claudetool callsremembers

The design, read from code

Drawn from the mod's source at the commit read, not from a run: a list is drawn three times, a condition takes its first branch that draws in the desktop app, and a value only the run time knows is shown as a made-up sample (dotted underline) or left out. Colours and type are this site's.

What its code shows

Read from the source at commit d866a4fd879e 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.context-gauge/hooks/register.tsx
ParsesEvery file parses as TypeScript or JavaScript.3 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, with its own branch for the desktop
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.https://api.anthropic.com, https://status.claude.com
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 the network, but reads no files and no environment variables
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 kirishimarisano-rgb/Claude-code-usage-context-cost-show
/plugin install context-gauge@kirishima-mods

This installs the marketplace's latest commit, which may not be the one read here (d866a4fd879e). 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 "kirishimarisano-rgb-context-gauge" with its code and make me a pane like it

Search them from Claude: the MCP connector

Similar designs