AI Context Meter - React Component | Kokonut UI
AI Context Meter
How full the context window is, as a ring in the prompt footer that opens a breakdown by source and compacts when it fills.
Installation
AI Context Meter is a free, open-source React component in the Kokonut UI AI collection. Add it with the shadcn CLI, which copies the source into components/kokonutui/ai-context-meter.tsx, so the code is yours to change.
npx shadcn@latest add @kokonutui/ai-context-meter
Or add it by hand: install its packages, then copy the source from the above code into components/kokonutui/ai-context-meter.tsx.
npm install motion
Usage
import AIContextMeter from "@/components/kokonutui/ai-context-meter";
export default function Example() {
return <AIContextMeter />;
}
Props
segments
ContextSegment[]
What fills the context window, in the order to draw it. When omitted, a demo conversation grows on its own.
limit
numberDefault200_000
The model's context window, in tokens.
compactAt
numberDefault0.8
Share of the window at which the conversation compacts, 0 to 1.
onCompact
() => void
Shows a Compact button in the panel. The demo compacts by itself.
model
stringDefault"Claude Opus"
Shown beside the meter, like the footer of a prompt box.
defaultOpen
booleanDefaultfalse
className
string
Extra classes for the root element.
ContextSegment
idrequiredstringlabelrequiredstringtokensrequirednumbercolorstring
A Tailwind background class for the segment, such as bg-sky-500.
Dependencies
| Needs | Version | Comes from |
|---|---|---|
motion |
^12.23.25 |
npm, installed by the CLI |
cn from lib/utils.ts |
shadcn init | |
| React | 19 |
Your app |
| Tailwind CSS | 4 |
Your app |
No provider, font or global CSS to set up: the file works as soon as it lands.