Context Breakdown
What fills a model's context window: one bar split into the system prompt, tools, files and conversation, with a legend of token counts and what's free, sliding as parts grow or are compacted.
- System prompt8.2K
- Tools21.6K
- Files46.9K
- Conversation81.7K
- Free41.6K
Installation
npx shadcn@latest add "@aiellie/context-breakdown"shadcn needs the @aiellie registry in components.json first. npx aiellie add context-breakdown adds it on its first run, then installs the same way.
Context Breakdown shows what fills a model's context window: one bar split into its parts, like the system prompt, tools, files and the conversation, with a legend of token counts and what's left free. Hovering a row in the legend picks out its part of the bar.
When a part changes, its width slides to the new size, so compacting a conversation reads as the conversation shrinking. For a single number, use Meter.
Getting started
Pass the parts
maxis the model's whole window. The parts fill it in the order given, darkest first.components/context.tsximport { ContextBreakdown } from "@/components/aiellie/context-breakdown" export function Context({ usage }: { usage: Usage }) { return ( <ContextBreakdown max={200_000} segments={[ { key: "system", label: "System prompt", tokens: usage.system }, { key: "tools", label: "Tools", tokens: usage.tools }, { key: "conversation", label: "Conversation", tokens: usage.messages }, ]} /> ) }
Anatomy
<div data-slot="context-breakdown">
<div /> {/* the label, tokens used of the window, and the percent */}
<div role="meter">
<span data-dim /> {/* one per part */}
</div>
<ul /> {/* the legend, then what's free */}
</div>The bar is a meter, so a screen reader hears how much of the window is used. The fills are shades of foreground, so the parts read as one whole in both themes. formatTokens is exported too: 820, 46.9K, 1.2M.
Examples
Colour a part
A part's className replaces its fill in the bar and the legend, like bg-destructive for a conversation that's about to need compacting.
- System prompt4.1K
- Conversation117.4K
- Free6.5K
API reference
ContextBreakdown
| Prop | Type | Default | Description |
|---|---|---|---|
segments | ContextSegment[] | required | The parts, in the order they fill it. |
max | number | required | The whole window, in tokens. |
label | ReactNode | "Context" |
All other div props are forwarded.
ContextSegment
| Field | Type | Default | Description |
|---|---|---|---|
key, label | string | required | |
tokens | number | required | |
className | string | a shade of foreground | Its fill. |