Skip to content

Context Window

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.

On this page
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-window
For Claude Code, Cursor or Codex: installs it and wires the props to your own data.

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
Default0.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.

What it handles

  1. 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.
  2. 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.
  3. 03Hatches the output reserve and highlights a segment when you hover or focus its legend row, with a per-file list under it.
  4. 04Shows an x on each file part when you pass onRemove, so a single file can be dropped from the context.
  5. 05Offers a Compact button through onCompact that stays quiet while ok and turns primary from warn, and spins while compacting is true.
  6. 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

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" }).

Need help?

Stuck on Context Window, or found something off? We read every message.