Ballmac UI home

Context Window

New

How full an agent's context is and what fills it: a stacked bar by part with tokens and share in a legend, room kept for the answer, a plain warning when nearly full or over, and a Compact button that says why when it cannot.

v1.0.0Updated Oct 25, 2026Ships with a test
What changed

Context

118Kof 200K

  • System prompt3.8K2%
  • Tools and their schemas14K7%
  • Files in the project62K31%
  • Conversation38K19%
  • Kept free for the answer16K8%

When it fills, the oldest messages are dropped first. Compact summarises them so nothing important is lost.

Installation

$ pnpm dlx shadcn@latest add @ballmac/context-window

Usage

import { ContextWindow, formatContextTokens } from "@/components/ballmac/context-window"

The full example is in the Code tab above.

Examples

Nearly full

Context

Nearly full168Kof 200K

  • System prompt3.8K2%
  • Tools and their schemas14K7%
  • Files in the project98K49%
  • Conversation52K26%
  • Kept free for the answer16K8%

Compact now, or the next long file will push the start of the task out.

Over the limit

Context

Over the limit140Kof 128K

  • System prompt3.8K3%
  • Files in the project84K66%
  • Conversation52K41%

Older messages are already being dropped.

API reference

PropTypeDefault
segments*ContextSegment[]—
limit*

The model's context window, in tokens.

number—
reserved

Tokens kept free for the answer. Drawn hatched at the end of the bar.

number0
warnAt

From this share of the limit (0 to 1), the card warns that it is nearly full.

number0.8
title

Heading.

string—
fullNote

What happens when it is full, in a sentence. Shown under the legend.

string—
onCompact

Called by the Compact button, which summarises the conversation to free space. Reject and the card says why.

() => void | Promise<void>—

Also accepts the standard attributes of its root element.

Accessibility

KeyAction
MeterThe bar is role=meter named by the heading, with aria-valuenow, aria-valuemax and a spoken value such as '142K of 200K tokens, 71% used'
WarningNearly full and Over the limit are written in a pill with an icon, not only coloured
LegendA list of parts with tokens and share, so the bar is never the only way to read it
CompactA native button that shows busy; a failure is an alert

Use with AI

segments is [{ id, label, tokens }] (required) and limit is the window in tokens (required). reserved keeps room for the answer (drawn hatched), warnAt (default 0.8) is where it warns, title, fullNote (what happens when it is full), onCompact (adds the Compact button; reject and the card says why). The bar is a meter with a spoken value; Nearly full and Over the limit are words, not just colour. With the shadcn MCP server set up (guide), ask your agent:

Add the Ballmac UI Context Window (@ballmac/context-window) to this project with the shadcn MCP, then use it where it fits.

Use it for

  • Showing a person how much of the model's memory a conversation or run is using
  • Warning before an agent starts forgetting the start of a task

Not for

  • Spend in money; use run-ledger or usage-meter
  • A single progress value; use progress

Registry JSON: https://ui.ballmac.com/r/context-window.json

Credits

Free to use in personal and commercial projects.

Ballmac UI Pro

Need the whole screen, not one piece?

150 premium blocks (dashboards, settings, calendars, mail, shops, onboarding), a private shadcn registry and Figma tokens. Blocks that show data come with loading, empty and error states built in.

Not ready? Try three Pro blocks free

Leave your email and the blocks appear right here, ready to copy. Yours to use in any project.