How full a model's context is, and what's filling it - with the thresholds spelled out, a compact action, a ring for tight spots and a sparkline per turn.
Used for
- Show context left
- Warn before a limit
- Compact a long chat
- Break down token use
- Header usage ring
Examples
View
Installation
npx knowns-ui@latest add context-windowFor Claude Code, Cursor or Codex: installs it and wires the props to your own data.
Paste this into your coding agent (Claude Code, Cursor, Codex). It checks your project, sets up the registry, runs the install and verifies it.
Install prompt
Install Context window from Knowns UI into this project. Work step by step, show me each change, and ask before you edit files outside this project.
Context: Knowns UI (https://ui.knowns.dev) is a shadcn registry. Items land in the project as source files. Docs: https://ui.knowns.dev/docs/context-window
1. Check the project first. Stop and tell me if any of these is missing:
- React 19 and Tailwind CSS v4.
- A components.json at the project root. If there is none, ask me before running `npx knowns-ui@latest init --no-key` (it runs shadcn init when needed, then adds the registries).
2. Run:
```bash
npx knowns-ui@latest add context-window
```
It writes these files:
- lib/knowns/run.ts
- lib/knowns/json.tsx
- lib/knowns/status.ts
- lib/knowns/tone.ts
- lib/knowns/types.ts
- lib/knowns/use-abortable.ts
- lib/knowns/utils.ts
- components/ui/knowns/spinner.tsx
- components/ui/knowns/button.tsx
- lib/knowns/motion.tsx
- lib/knowns/motion-utils.ts
- components/ui/knowns/use-floating.ts
- components/ui/knowns/tooltip.tsx
- components/ui/knowns/tooltip-utils.ts
- components/ui/knowns/context-window/context-window.tsx
- components/ui/knowns/context-window/context-cells.tsx
- components/ui/knowns/context-window/context-utils.ts
and installs these npm packages: clsx@^2.1.1, tailwind-merge@^3.7.0, class-variance-authority@^0.7.1.
3. While it runs:
- It also adds a few @keyframes (all named kn-*) to the global CSS file (globals.css or the file components.json points at). Let it: they only add animations.
- If it asks to overwrite files under lib/knowns/: these are shared by every Knowns UI item. List them, say whether I changed them (check git), and ask me before you answer.
- If it asks to overwrite any other file, show me the diff and ask me.
4. Verify:
- Every file in the list above exists.
- The project type-checks (for example `npx tsc --noEmit`) and the dev build has no new errors.
5. Use it: follow the examples and props on https://ui.knowns.dev/docs/context-window, and ask me if anything about my data is unclear.
If the Knowns UI MCP server is connected (https://ui.knowns.dev/docs/ai-and-mcp), use get_component({ name: "context-window" }) or search_docs for details.
Finish with a short summary: the files you added or changed, the packages you installed, and anything I still need to do.Props
- segments
{ id, label, tokens, kind?, color?, reserve? }[]- What fills the window, in order. kind ("system" | "tools" | "history" | "files" | "output" | "other") picks a colour; "output" is a reserve: hatched after what is used, not counted as used. Custom segments get their own colour.
- limit
number- Window size in tokens.
- model / limits
string / Record<string, number>- Look the size up in your own table when limit isn't given (exact name, then ignoring case and spaces). No vendor numbers are built in. Unknown: the breakdown shows without a percentage.
- warnAt / fullAt
number- Default
0.8 / 0.95 - Shares of the window (used + reserved). Stated in words ("Warns at 80% · full at 95%"), drawn as hairlines on the bar and the sparkline. States: "60k free", "Filling up · 24k left, compact soon", "Almost full · the next turn may not fit", "Over the limit by 12k".
- history
number[]- Tokens after each turn: a sparkline with the thresholds; drops of a fifth or more are marked as compactions. Hover for a turn's value.
- view / cellTokens
"bar"|"cells" / number- Default
"bar" / auto - Cells: the window as equal cells, each worth cellTokens (default a round number for about 240 cells). Free cells turn amber past warnAt and red past fullAt. Hover a cell or a legend row to light that segment; while compacting the conversation's cells shimmer, then change colour together.
- segments[].parts
{ id, label, tokens, detail? }[]- What a segment is made of (files, turns). Its legend row opens to list them; tokens: 0 on the segment sums them.
- onRemove
(segmentId, partId) => void- Shows an x on each part in the open list (remove a file from the context).
- onNewChat / newChatLabel
() => void / string- Default
- / "New chat" - A footer with what's left and a New chat button (primary once it's almost full).
- onCompact / compactLabel / compacting
() => void / string / boolean- Default
- / "Compact" - A Compact button: quiet while ok, primary from warn on; compacting shows a spinner.
- action
ReactNode- Your own element in the action slot instead of the button.
- variant / size
"bar"|"ring" / number- Default
"bar" / 32 - Ring: a donut for headers with the share in the middle, a dot when it warns, and the full breakdown in its tooltip.
- title / formatTokens
ReactNode / (n) => string- Default
"Context window" / 124k - Heading (names the region and the meter) and token format.
- a11y
role=meter- aria-valuetext like "62% used, 124k of 200k tokens, 16k reserved. 60k free". Legend items are focusable; focus or hover highlights the segment.
| Prop | Type | Default | Description |
|---|---|---|---|
| segments | { id, label, tokens, kind?, color?, reserve? }[] | - | What fills the window, in order. kind ("system" | "tools" | "history" | "files" | "output" | "other") picks a colour; "output" is a reserve: hatched after what is used, not counted as used. Custom segments get their own colour. |
| limit | number | - | Window size in tokens. |
| model / limits | string / Record<string, number> | - | Look the size up in your own table when limit isn't given (exact name, then ignoring case and spaces). No vendor numbers are built in. Unknown: the breakdown shows without a percentage. |
| warnAt / fullAt | number | 0.8 / 0.95 | Shares of the window (used + reserved). Stated in words ("Warns at 80% · full at 95%"), drawn as hairlines on the bar and the sparkline. States: "60k free", "Filling up · 24k left, compact soon", "Almost full · the next turn may not fit", "Over the limit by 12k". |
| history | number[] | - | Tokens after each turn: a sparkline with the thresholds; drops of a fifth or more are marked as compactions. Hover for a turn's value. |
| view / cellTokens | "bar" | "cells" / number | "bar" / auto | Cells: the window as equal cells, each worth cellTokens (default a round number for about 240 cells). Free cells turn amber past warnAt and red past fullAt. Hover a cell or a legend row to light that segment; while compacting the conversation's cells shimmer, then change colour together. |
| segments[].parts | { id, label, tokens, detail? }[] | - | What a segment is made of (files, turns). Its legend row opens to list them; tokens: 0 on the segment sums them. |
| onRemove | (segmentId, partId) => void | - | Shows an x on each part in the open list (remove a file from the context). |
| onNewChat / newChatLabel | () => void / string | - / "New chat" | A footer with what's left and a New chat button (primary once it's almost full). |
| onCompact / compactLabel / compacting | () => void / string / boolean | - / "Compact" | A Compact button: quiet while ok, primary from warn on; compacting shows a spinner. |
| action | ReactNode | - | Your own element in the action slot instead of the button. |
| variant / size | "bar" | "ring" / number | "bar" / 32 | Ring: a donut for headers with the share in the middle, a dot when it warns, and the full breakdown in its tooltip. |
| title / formatTokens | ReactNode / (n) => string | "Context window" / 124k | Heading (names the region and the meter) and token format. |
| a11y | role=meter | - | aria-valuetext like "62% used, 124k of 200k tokens, 16k reserved. 60k free". Legend items are focusable; focus or hover highlights the segment. |
What it handles
- 01Totals the segments you pass, system prompt, tools, history, files and an output reserve, against a limit or a model looked up in your own limits table.
- 02Words the state as ok, warn, full or over, with warnAt at 0.8 and fullAt at 0.95 by default, and prints those thresholds under the bar.
- 03Hatches the output reserve and highlights a segment when you hover or focus its legend row, with a per-file list under it.
- 04Shows an x on each file part when you pass onRemove, so a single file can be dropped from the context.
- 05Offers a Compact button through onCompact that stays quiet while ok and turns primary from warn, and spins while compacting is true.
- 06Switches view to a field of cells worth cellTokens each, or variant="ring" for a small donut with the breakdown in a tooltip.
States
- First render
- Nothing. It paints as it is
- none
- Cells change
- A cell's colour changes, staggered across the field
- 280ms, ease out
- Ring fills
- The arc grows or shrinks to the new share
- 280ms, ease in-out
- Legend hover
- Other segments dim in the bar
- 180ms, ease out
- Legend row hover
- The row dims or lights
- 120ms, ease out
- Reduced motion
- Cells, ring and bar change at once
- 0ms
| State | What moves | Timing |
|---|---|---|
| First render | Nothing. It paints as it is | none |
| Cells change | A cell's colour changes, staggered across the field | 280ms, ease out |
| Ring fills | The arc grows or shrinks to the new share | 280ms, ease in-out |
| Legend hover | Other segments dim in the bar | 180ms, ease out |
| Legend row hover | The row dims or lights | 120ms, ease out |
| Reduced motion | Cells, ring and bar change at once | 0ms |
Works with
When to use
When to use
- Telling users how full the model's context is and what fills it (system, files, history, tools).
- Offering a compact or clear action before the limit hits, with thresholds explained in words.
- The ring variant fits a composer toolbar or a header where space is tight.
When not to use
- Billing, credits or spend against a plan: use Usage Meter.
- Plain progress of a task with no token breakdown: use Progress.
- A file-by-file, turn-by-turn map of what fills the context: use Context Treemap.
Using with AI
Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:
- Add the Knowns UI Context Window to my app and wire it to my own data.
- I need telling users how full the model's context is and what fills it (system, files, history, tools). Set that up with the Knowns UI Context Window.
- Which Context Window props do I need for a minimal setup? Show me a short example.
With the server connected, your assistant calls get_component({ name: "context-window" }) and search_docs({ query: "context window" }).