Loading component…
Loading component…
An agent's context window filling up and being compacted – a bar of slices as wide as their tokens, folding into one summary row, or by hand with Compact now
To reuse this local React demo, copy all files from the Code tab into the same folder, then import ContextCompaction from ./context-compaction.
import { ContextCompaction, type ContextEntry } from "@/components/ui/context-compaction";
const entries: ContextEntry[] = [
{ id: "sys", kind: "system", label: "System prompt", tokens: 3200 },
{ id: "tools", kind: "tools", label: "14 tool definitions", tokens: 9800 },
{ id: "u1", kind: "user", label: "The cart total is off by a cent", tokens: 400 },
{ id: "f1", kind: "file", label: "src/cart/cart.ts", tokens: 18400 },
{ id: "t1", kind: "tool", label: "run_tests · 48 tests", tokens: 26300 },
];
export function Context() {
return <ContextCompaction title="Fix the cart total" model="Claude Sonnet" entries={entries} limit={200_000} />;
}| Name | Type | Default | Description |
|---|---|---|---|
| entries | ContextEntry[] | What sits in the window, in order – { id, kind, label, tokens, replaces?, before?, count?, apps?, total? }. kind is system, tools, user, assistant, tool, file or summary. apps – { name, path?, icon?, color?, tile? } – shows up to three overlapping logo tiles and +N for the rest of total; path is a one-color logo on a 24 grid, icon any node (a multi-color logo, a glyph) | |
| limit | number | The window's size in tokens | |
| threshold | number | Share of the limit where it compacts on its own – the dashed mark; from there the percentage turns amber. Default 0.8 | |
| compacting | string[] | Ids of the entries being compacted right now – they shimmer, and the bar says Compacting | |
| title | string | The name in the bar – default Context | |
| model | string | A small tag beside the title, e.g. the model | |
| onCompact | () => void | Shows the last row with the colors and a Compact now button | |
| rows | number | Rows the list shows before it scrolls – default 7 | |
| className | string | Extra class on the root – set the color variables on it, e.g. --ui-cpx-k-file |
The bar and the rows fit the width; labels shorten with an ellipsis
Narrow: the colors in the last row and the before-numbers on summaries go
Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"