Xzero UI
Pro library

Context windowPro

An AI context window as a grid of 200 cells: the system prompt, tools, files, summary and messages fill it in order, a threshold row marks where compaction starts, and sending a message, attaching a file or compacting shows exactly how much still fits.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui-pro/context-window
Live · keyboard ready

When to use

When not to use

Installation

Register both Xzero UI namespaces in your project's components.json:

{
  "registries": {
    "@xzero-ui": "https://mcp.xzero.co.uk/r/{name}.json",
    "@xzero-ui-pro": "https://mcp.xzero.co.uk/r/pro/{name}.json"
  }
}
npx shadcn@4.23.0 add @xzero-ui-pro/context-window

Install xzero-foundation once, and import @/components/xzero/foundation.css in your app root. No Xzero token is used by this snapshot. For sample portraits, photos, fonts, or logos, download https://mcp.xzero.co.uk/install-assets.mjs and run node xzero-install-assets.mjs <receiving-project>.

Usage

import { ContextWindow } from "@/components/xzero/context-window/context-window";

export function SessionContext({ items }) {
  return (
    <ContextWindow
      items={items}
      threshold={0.8}
      onCompact={({ folded, summary }) => console.log(`Folded ${folded} tokens into ${summary}`)}
    />
  );
}

API reference

ContextWindow

A model's context window shown as a fixed budget of 200 cells that fills in reading order: system prompt, tools, files and memory, a summary, then the conversation, followed by free space, with the output reserve held as outlined cells at the end. A dashed line marks the compaction threshold. Send message and Attach file add tokens; crossing the threshold, switching to a smaller model or pressing Compact now folds the older messages into a short summary and the space comes back. A legend lists every part with tokens and percent, adding up to 100%.

PropTypeDefaultDescription
modelsContextModel[]sampleModelsModels to switch between, each { id, name, window, reserve, mark, color? } with window and reserve in tokens. The sample uses Claude Opus 5.5's real 1M window; reserves and the other two models are sample settings.
defaultModelIdstring–The model shown first. Defaults to the first model.
onModelChange(model: ContextModel) => void–Called when someone switches models.
itemsContextItem[]sampleItemsWhat is in the window: { id, category, label, tokens } with category "system", "tools", "files", "summary" or "messages". Items are grouped by category for the grid, so their order only matters within a category.
thresholdnumber0.8Fraction of the window at which compaction runs on its own.
turnsContextTurn[]sampleTurnsTurns that Send message adds, in order, each { label, tokens }: a message plus the tool results and reply it produced.
filesContextTurn[]sampleFilesFiles that Attach file adds, in order.
summarize(folded: ContextItem[]) => number–Returns the summary size in tokens for the folded messages. Defaults to about 6% of them, between 4K and 24K.
onCompact(compaction: ContextCompaction) => void–Called after each compaction with { folded, summary, before, after, automatic }.
onItemsChange(items: ContextItem[]) => void–Called with the new items after a send, an attachment or a compaction.
classNamestring–Class on the root section.

Keyboard interactions

KeysAction
TabMoves through the model menu, Send message, Attach file and Compact now.
Enter, SpaceOpens the model menu or runs an action.
Arrow up / Arrow down, EnterIn the model menu, moves between models and chooses one.
EscapeCloses the model menu and returns focus to its trigger.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Also in ai

Guidance for AI tools

Context window: An AI context window as a grid of 200 cells: the system prompt, tools, files, summary and messages fill it in order, a threshold row marks where compaction starts, and sending a message, attaching a file or compacting shows exactly how much still fits. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://ui.xzero.co.uk/llms.txt

Browse all components