Ballmac UI home

Token Meter

A context-window meter that stacks system, history and attachments against the limit with a reserved reply area, plus a composer pill that opens the same view in a popover.

Context window

164.5k / 200k

  • System prompt3.2k
  • Conversation118.5k
  • Attached files42.8k
  • Room for the replyreserved16k

Nearing the limit, 35.5k left

≈ $0.42

Installation

$ pnpm dlx shadcn@latest add @ballmac/token-meter

Usage

import { TokenMeter, TokenMeterPill, formatTokens, estimateTokens } from "@/components/ballmac/token-meter"

The full example is in the Code tab above.

Examples

Composer pill

API reference

<TokenMeter>

PropTypeDefault
segments*

Where the tokens go. Order sets the stacking order and the legend.

TokenSegment[]—
limit*

Size of the context window in tokens.

number—
title

Heading.

string—
warnAt

Percent used at which the meter turns to a warning.

number80
cost

Cost of the current context, already formatted, such as "$0.21".

string—
action

Adds a button in the warning and full states, such as "Compact conversation".

React.ReactNode—

<TokenMeterPill>

PropTypeDefault
side

Which side of the pill the details open on.

"top" | "bottom""top"

Also accepts the standard attributes of its root element.

Accessibility

KeyAction
Screen readersrole=meter with a value such as '142k of 200k tokens used, 71%. 58k left.'
Enter / SpaceOpens the pill's detail popover
ColorWarning and full states add an icon and words

Use with AI

segments is [{ label, tokens, reserved? }], limit is the window. The meter warns at warnAt percent (80) and again when full, with words and an icon. <TokenMeterPill> shows a ring and percentage. Exports formatTokens and estimateTokens. With the shadcn MCP server set up (guide), ask your agent:

Add the Ballmac UI Token Meter (@ballmac/token-meter) to this project with the shadcn MCP, then use it where it fits.

Use it for

  • Showing how full the model's context is
  • Nudging people to start a new chat or compact

Not for

  • Plan quotas and billing limits; use usage-meter
  • Generic progress; use progress

Registry JSON: https://ui.ballmac.com/r/token-meter.json

Credits

Free to use in personal and commercial projects.