modscode JA

modscode / Gallery / context-meter

context-meter

A context window meter at the bottom right of the prompt; click it for the full breakdown

Code you can checkTerminal + desktopPaneBoxButtonText

What it does

  • Draws a pane
  • Adds /ctx
  • Hooks session.compact, session.measure, session.start

Good points

  • No network calls
  • Starts no processes
  • Small: 383 lines
  • Written in TypeScript

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-meter by Nafees S (pane), as modscode read it from the mod's code:
// https://modscode.com/gallery/lucenity0-context-meter/
// 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 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 percentage = '…'
    const formatTokens = '…'
    const model = '…'
    const compactNote = '…'
    const name = '…'
    const formatTokens2 = '…'
    const percentOf = '…'
    const formatTokens3 = '…'
    const percentOf2 = '…'
    const formatTokens4 = '…'
    const percentOf3 = '…'
    const value = '…'
    const formatTokens5 = '…'
    const map = '…'
    const formatTokens6 = '…'
    const note = '…'
    const formatTokens7 = '…'
    const note2 = '…'
    const formatTokens8 = '…'
    const note3 = '…'
    const formatTokens9 = '…'
    const note4 = '…'
    const formatTokens10 = '…'
    const note5 = '…'
    const formatTokens11 = '…'
    const note6 = '…'
    const formatTokens12 = '…'
    const note7 = '…'
    const formatTokens13 = '…'
    const note8 = '…'
    const formatTokens14 = '…'
    const note9 = '…'
    const formatTokens15 = '…'
    const note10 = '…'
    const formatTokens16 = '…'
    const note11 = '…'
    const formatTokens17 = '…'
    const note12 = '…'
    const formatTokens18 = '…'
    return (
      <Box flexDirection="column">
        <Box flexDirection="row" justifyContent="space-between" columnGap={2}>
          <Text>
            <Text bold>
              {percentage}
              %
            </Text>
            <Text>
              {`  ${formatTokens}`}
            </Text>
            <Text dimColor>
              {` of ${formatTokens}`}
            </Text>
          </Text>
          <Text dimColor wrap="truncate-start">
            {model}
            {" · counting…"}
          </Text>
        </Box>
        <Text>
          <Text dimColor>
            ░░░░░░░░
          </Text>
          <Text dimColor>
            ░░░░░░░░
          </Text>
          <Text dimColor>
            ░░░░░░░░
          </Text>
        </Text>
        <Text dimColor>
          {formatTokens}
          {" free · "}
          {compactNote}
        </Text>
        <Box flexDirection="column" marginTop={1}>
          <Text>
            <Text>
              ●
            </Text>
            {` ${name} `}
            <Text dimColor>
              {formatTokens2}
            </Text>
            {"  "}
            <Text>
              ━━━━━━━━
            </Text>
            {"        "}
            <Text dimColor>
              {percentOf}
            </Text>
          </Text>
          <Text>
            <Text>
              ●
            </Text>
            {` ${name} `}
            <Text dimColor>
              {formatTokens3}
            </Text>
            {"  "}
            <Text>
              ━━━━━━━━
            </Text>
            {"        "}
            <Text dimColor>
              {percentOf2}
            </Text>
          </Text>
          <Text>
            <Text>
              ●
            </Text>
            {` ${name} `}
            <Text dimColor>
              {formatTokens4}
            </Text>
            {"  "}
            <Text>
              ━━━━━━━━
            </Text>
            {"        "}
            <Text dimColor>
              {percentOf3}
            </Text>
          </Text>
          <Text dimColor wrap="truncate-end">
            {`○ ${value} `}
            {formatTokens5}
            {`  ${map}, not in the window`}
          </Text>
        </Box>
        <Box marginTop={1}>
          <Text dimColor wrap="truncate-end">
            {"last request "}
            {formatTokens6}
            {" in"}
          </Text>
        </Box>
        <Box flexDirection="column" marginTop={1}>
          <Text dimColor>
            memory
          </Text>
          <Box flexDirection="row" columnGap={1}>
            <Box flexShrink={0}>
              <Text>
                {`  ${name}`}
              </Text>
            </Box>
            <Box flexGrow={1} flexShrink={1}>
              <Text dimColor wrap="truncate-start">
                {note}
              </Text>
            </Box>
            <Box flexShrink={0}>
              <Text>
                {formatTokens7}
              </Text>
            </Box>
          </Box>
          <Box flexDirection="row" columnGap={1}>
            <Box flexShrink={0}>
              <Text>
                {`  ${name}`}
              </Text>
            </Box>
            <Box flexGrow={1} flexShrink={1}>
              <Text dimColor wrap="truncate-start">
                {note2}
              </Text>
            </Box>
            <Box flexShrink={0}>
              <Text>
                {formatTokens8}
              </Text>
            </Box>
          </Box>
          <Box flexDirection="row" columnGap={1}>
            <Box flexShrink={0}>
              <Text>
                {`  ${name}`}
              </Text>
            </Box>
            <Box flexGrow={1} flexShrink={1}>
              <Text dimColor wrap="truncate-start">
                {note3}
              </Text>
            </Box>
            <Box flexShrink={0}>
              <Text>
                {formatTokens9}
              </Text>
            </Box>
          </Box>
        </Box>
        <Box flexDirection="column" marginTop={1}>
          <Text dimColor>
            mcp servers
          </Text>
          <Box flexDirection="row" columnGap={1}>
            <Box flexShrink={0}>
              <Text>
                {`  ${name}`}
              </Text>
            </Box>
            <Box flexGrow={1} flexShrink={1}>
              <Text dimColor wrap="truncate-start">
                {note4}
              </Text>
            </Box>
            <Box flexShrink={0}>
              <Text>
                {formatTokens10}
              </Text>
            </Box>
          </Box>
          <Box flexDirection="row" columnGap={1}>
            <Box flexShrink={0}>
              <Text>
                {`  ${name}`}
              </Text>
            </Box>
            <Box flexGrow={1} flexShrink={1}>
              <Text dimColor wrap="truncate-start">
                {note5}
              </Text>
            </Box>
            <Box flexShrink={0}>
              <Text>
                {formatTokens11}
              </Text>
            </Box>
          </Box>
          <Box flexDirection="row" columnGap={1}>
            <Box flexShrink={0}>
              <Text>
                {`  ${name}`}
              </Text>
            </Box>
            <Box flexGrow={1} flexShrink={1}>
              <Text dimColor wrap="truncate-start">
                {note6}
              </Text>
            </Box>
            <Box flexShrink={0}>
              <Text>
                {formatTokens12}
              </Text>
            </Box>
          </Box>
        </Box>
        <Box flexDirection="column" marginTop={1}>
          <Text dimColor>
            skills
          </Text>
          <Box flexDirection="row" columnGap={1}>
            <Box flexShrink={0}>
              <Text>
                {`  ${name}`}
              </Text>
            </Box>
            <Box flexGrow={1} flexShrink={1}>
              <Text dimColor wrap="truncate-start">
                {note7}
              </Text>
            </Box>
            <Box flexShrink={0}>
              <Text>
                {formatTokens13}
              </Text>
            </Box>
          </Box>
          <Box flexDirection="row" columnGap={1}>
            <Box flexShrink={0}>
              <Text>
                {`  ${name}`}
              </Text>
            </Box>
            <Box flexGrow={1} flexShrink={1}>
              <Text dimColor wrap="truncate-start">
                {note8}
              </Text>
            </Box>
            <Box flexShrink={0}>
              <Text>
                {formatTokens14}
              </Text>
            </Box>
          </Box>
          <Box flexDirection="row" columnGap={1}>
            <Box flexShrink={0}>
              <Text>
                {`  ${name}`}
              </Text>
            </Box>
            <Box flexGrow={1} flexShrink={1}>
              <Text dimColor wrap="truncate-start">
                {note9}
              </Text>
            </Box>
            <Box flexShrink={0}>
              <Text>
                {formatTokens15}
              </Text>
            </Box>
          </Box>
        </Box>
        <Box flexDirection="column" marginTop={1}>
          <Text dimColor>
            agents
          </Text>
          <Box flexDirection="row" columnGap={1}>
            <Box flexShrink={0}>
              <Text>
                {`  ${name}`}
              </Text>
            </Box>
            <Box flexGrow={1} flexShrink={1}>
              <Text dimColor wrap="truncate-start">
                {note10}
              </Text>
            </Box>
            <Box flexShrink={0}>
              <Text>
                {formatTokens16}
              </Text>
            </Box>
          </Box>
          <Box flexDirection="row" columnGap={1}>
            <Box flexShrink={0}>
              <Text>
                {`  ${name}`}
              </Text>
            </Box>
            <Box flexGrow={1} flexShrink={1}>
              <Text dimColor wrap="truncate-start">
                {note11}
              </Text>
            </Box>
            <Box flexShrink={0}>
              <Text>
                {formatTokens17}
              </Text>
            </Box>
          </Box>
          <Box flexDirection="row" columnGap={1}>
            <Box flexShrink={0}>
              <Text>
                {`  ${name}`}
              </Text>
            </Box>
            <Box flexGrow={1} flexShrink={1}>
              <Text dimColor wrap="truncate-start">
                {note12}
              </Text>
            </Box>
            <Box flexShrink={0}>
              <Text>
                {formatTokens18}
              </Text>
            </Box>
          </Box>
        </Box>
        <Box marginTop={1} columnGap={1}>
          <Button label="Count exactly" hotkey="e" />
          <Button label="Refresh" hotkey="r" />
          <Button label="Compact" hotkey="c" />
          <Button label="Close" hotkey="q" role="dismiss" />
        </Box>
      </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.

context-meter/hooks/register.tsx lines 100–240 · Pane
  on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
    const { Box, Text, Button } = $.ui.resolve(e)
    const current = await read($, details)
    const loading = await read($, isLoading)
    const live = await read($, fill)
    const width = Math.max(32, e.props.bodyColumns)

    if (current === null) {
      return <Text dimColor>{loading ? 'Counting the context window…' : 'No breakdown yet.'}</Text>
    }

    const used = current.categories.filter(category => category.kind === 'used').sort((a, b) => b.tokens - a.tokens)
    const deferred = current.categories.filter(category => category.kind === 'deferred')
    const free = current.categories.find(category => category.kind === 'free')?.tokens ?? 0
    const usedTotal = used.reduce((sum, category) => sum + category.tokens, 0)
    const largest = used[0]?.tokens ?? 1

    const nameWidth = Math.min(20, Math.max(8, ...used.map(category => category.name.length)))
    const barWidth = Math.max(4, width - nameWidth - 18)
    const accent = levelColor(current.percentage)

    const compactNote = !current.isAutoCompactEnabled || current.autoCompactThreshold === undefined
      ? 'auto-compact off'
      : current.autoCompactThreshold > current.totalTokens
        ? `compacts in ${formatTokens(current.autoCompactThreshold - current.totalTokens)}`
        : 'compacts next turn'

    const section = (title: string, lines: Line[]) =>
      lines.length > 0 && (
        <Box flexDirection="column" marginTop={1}>
          <Text dimColor>{title}</Text>
          {lines.map(line => (
            <Box flexDirection="row" columnGap={1}>
              <Box flexShrink={0}>
                <Text>{`  ${line.name}`}</Text>
              </Box>
              <Box flexGrow={1} flexShrink={1}>
                {line.note !== undefined && (
                  <Text dimColor wrap="truncate-start">
                    {line.note}
                  </Text>
                )}
              </Box>
              <Box flexShrink={0}>
                <Text>{formatTokens(line.tokens).padStart(6)}</Text>
              </Box>
            </Box>
          ))}
        </Box>
      )

    const memory = current.memoryFiles.map(file => {
      const path = file.name.replace(/^\/(Users|home)\/[^/]+/, '~')
      const cut = path.lastIndexOf('/')
      return { name: path.slice(cut + 1), tokens: file.tokens, note: path.slice(0, cut) }
    })

    return (
      <Box flexDirection="column">
        <Box flexDirection="row" justifyContent="space-between" columnGap={2}>
          <Text>
            <Text bold {...(accent === undefined ? {} : { color: accent })}>
              {current.percentage}%
            </Text>
            <Text>{`  ${formatTokens(current.totalTokens)}`}</Text>
            <Text dimColor>{` of ${formatTokens(current.maxTokens)}`}</Text>
          </Text>
          <Text dimColor wrap="truncate-start">
            {current.model}
            {loading ? ' · counting…' : current.isExact ? ' · exact' : ' · estimated'}
          </Text>
        </Box>

        <Text>
          {segments(current.categories, current.maxTokens, width).map(part =>
            part.kind === 'free' ? (
              <Text dimColor>{'░'.repeat(part.cells)}</Text>
            ) : (
              <Text color={part.color}>{(part.kind === 'buffer' ? '▒' : '█').repeat(part.cells)}</Text>
            ),
          )}
        </Text>
        <Text dimColor>
          {formatTokens(free)} free · {compactNote}
        </Text>

        <Box flexDirection="column" marginTop={1}>
          {used.map(category => (
            <Text>
              <Text color={category.color}>●</Text>
              {` ${fit(category.name, nameWidth)} `}
              <Text dimColor>{formatTokens(category.tokens).padStart(6)}</Text>
              {'  '}
              <Text color={category.color}>
                {'━'.repeat(Math.max(1, Math.round((category.tokens / largest) * barWidth)))}
              </Text>
              {' '.repeat(barWidth - Math.max(1, Math.round((category.tokens / largest) * barWidth)))}
              <Text dimColor>{percentOf(category.tokens, usedTotal).padStart(5)}</Text>
            </Text>
          ))}
          {deferred.length > 0 && (
            <Text dimColor wrap="truncate-end">
              {`○ ${fit('on demand', nameWidth)} `}
              {formatTokens(deferred.reduce((sum, category) => sum + category.tokens, 0)).padStart(6)}
              {`  ${deferred.map(category => category.name).join(', ')}, not in the window`}
            </Text>
          )}
        </Box>

        {live.tokens !== undefined && (
          <Box marginTop={1}>
            <Text dimColor wrap="truncate-end">
              last request {formatTokens(live.tokens)} in
              {current.lastResponse === null
                ? ''
                : ` · ${formatTokens(current.lastResponse.cacheRead)} cached · ${formatTokens(
                    current.lastResponse.output,
                  )} out`}
            </Text>
          </Box>
        )}

        {section('memory', memory)}
        {section('mcp servers', current.mcpServers)}
        {section(
          'skills',
          current.skills === undefined || current.skills.count === 0
            ? []
            : [{ name: `${current.skills.count} listed`, tokens: current.skills.tokens }],
        )}
        {section('agents', current.agents)}

        <Box marginTop={1} columnGap={1}>
          <Button key="exact" label="Count exactly" hotkey="e" onPress={() => loadDetails($, 'full')} />
          <Button key="refresh" label="Refresh" hotkey="r" onPress={() => loadDetails($, 'summary')} />
          <Button key="compact" label="Compact" hotkey="c" onPress={() => $.session.compact()} />
          <Button key="close" label="Close" hotkey="q" role="dismiss" onPress={() => $.ui.close({ id: PANE })} />
        </Box>
      </Box>
    )
  })
Licence text (MIT)
MIT License

Copyright (c) 2026 Nafees S

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

nothing found

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 4a3ed32908c2 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-meter/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.its repository's .claude-plugin/marketplace.json does not list it: no install line to give
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's .claude-plugin/marketplace.json does not list it, so there is no install line to give. Read it as code, or follow its author's README.

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 "lucenity0-context-meter" with its code and make me a pane like it

Search them from Claude: the MCP connector

Similar designs