modscode JA

modscode / Gallery / 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

Code you can checkTerminal + desktopBandStatus lineToastBoxButtonInputSvgText

What it does

  • Draws a band above the prompt, the status line, toasts
  • Adds /quota
  • Hooks prompt.edit, session.measure, session.start, turn.complete and 3 more
  • Keeps its own state between turns
  • Calls the network

Good points

  • Written in TypeScript
  • Has a desktop-specific branch
  • Handles errors
  • Writes no files

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

The mod's own code

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

hooks/register.tsx lines 1001–1160 · Band
  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>
Licence 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.

What its code calls

networkruns programsreads filesenv varsremembers

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 dfe493f114cd 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.hooks/register.tsx
ParsesEvery file parses as TypeScript or JavaScript.1 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).hooks/register.tsx:800 defaults (not on Windows)
NetworkWhether every fetch names its https host in the code.https://api.anthropic.com
ProgramsWhether every program it starts is named in the code and is not a shell, an interpreter or a network tool.reg, defaults
Reads and sendsWhether it both reads files or environment variables and reaches the network.reads environment variables and files and reaches the 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 anantraghunath/claude-code-usage-quota-mod
/plugin install claude-code-usage-quota@claude-code-usage-quota-mod

This installs the marketplace's latest commit, which may not be the one read here (dfe493f114cd). 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 "anantraghunath-claude-code-usage-quota" with its code and make me a pane like it

Search them from Claude: the MCP connector

Similar designs