Skip to content

Context Compactor

A context window you can compact and watch. Press Compact and the old turns squeeze into one Summary segment, the farthest first, while the total rolls down and the saving is called out. Your backend decides what is folded; the component animates whatever parts come back.

On this page
Used for
  • Fold old turns into a summary
  • Show an auto-compaction
  • Free room in a long session

Examples

Installation

Installation is part of Pro

Pro components install from a licensed registry. The live preview stays open to everyone.

Props

partsrequired
CompactPart[]
What fills the context, in order: id, label, tokens, kind (system, tools, files, history, summary, other) and keep for a pinned part.
limitrequired
number
The model's context window in tokens.
onCompact
() => void
Press Compact. Set compacting while it works and pass the new parts when done. No callback, no button.
compacting
boolean
Defaultfalse
Shows a spinner on the button and is announced.
actionLabel
string
Default"Compact"
The button's words.
planCompaction / applyCompaction
helpers
A default fold: history parts not kept, except the two newest, into one summary of a tenth of their size (400 tokens at least).
Motion
-
Leaving parts squeeze to nothing on the slow token, ease in-out, the farthest from the summary first (55ms a step, 240ms in all); the summary grows from nothing; the total rolls on the Odometer; Saved pops with usePlay confirm. Reduced motion: the new parts at once.

Accessibility

  • The bar is decoration; the legend under it lists every part with its size, so nothing is said by colour alone.
  • Compacting and the result (tokens saved, share of the context used) are announced in a status line.
  • The button keeps its place and its name while it works, so focus does not jump.

What it handles

  1. 01Diffs the parts it is given: the ones that left squeeze to nothing and new ones grow from nothing, in place.
  2. 02Squeezes the leaving parts from the far end toward where the summary lands, so the eye follows the fold.
  3. 03Calls a compaction out once, with the tokens saved, when a summary part arrives as others leave.
  4. 04Rolls the total down like an odometer and keeps the share of the window, amber from 80% and red past it.
  5. 05Offers planCompaction and applyCompaction: old unpinned history, except the two newest turns, into a tenth of its size.
  6. 06Lists every part with its size under the bar, so the fold reads without colour.

States

First render
Nothing
none
Compacting
A spinner on the button
none on the bar: it waits for the new parts
Parts leave
They squeeze farthest first, then the summary grows
280ms, ease in-out, farthest first
Total changes
The changed places roll down
420ms, ease out, roll
Saved
The check pops once
420ms, ease out
Reduced motion
The new parts at once
0ms

Works with

When to use

When to use

  • A long agent session where people choose when to fold old turns into a summary.
  • Showing what an automatic compaction just did and how much room it bought.

When not to use

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 Compactor to my app and wire it to my own data.
  • I need a long agent session where people choose when to fold old turns into a summary. Set that up with the Knowns UI Context Compactor.
  • Which Context Compactor props do I need for a minimal setup? Show me a short example.

With the server connected, your assistant calls get_component({ name: "context-compactor" }) and search_docs({ query: "context compactor" }). Pro props, full examples and source come back once your license key is in the MCP config.

Need help?

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