A context manager for coding agents
/compact is the naive solution.
When your agent's context fills up, compaction crushes the whole session into one lossy summary. The agent stalls while it happens, and nobody can undo it. Accordion folds context one block at a time. Every fold is reversible, and the agent can pull back anything it needs by code.
pi install npm:@a-fig/accordion
A pi extension. MIT.
Then run /accordion in pi.
One summary, or 982 folds you can undo.
Same session, same pressure. Compaction replaces everything with a single summary the model writes once. Accordion swaps each block for a short tagged digest and keeps the original.
/compactwhole session, one shot- recoverable
- 982 / 982
- agent waits
- —
accordionper block, between turns- recoverable
- 982 / 982
- context
- —
/compact | Accordion | |
|---|---|---|
| Granularity | The whole session, at once | Each block on its own |
| Undo | None. The original is gone from the model's view for good. | Every fold. The original is kept, byte for byte. |
| Agent stall | Blocks on an LLM call mid-task | None. Folds apply off the critical path, in under a millisecond. |
| Reaching back | Impossible | unfold or recall by the code in the tag |
| Recent work | Summarized with everything else | The newest ~20k tokens are never folded |
| Visibility | Happens off-screen | Every block on one map, live |
Your whole context window, on one screen.
One square per block, in conversation order. Color is the kind of block and the dice face is its weight. The thick box at the bottom is the protected tail: the agent's working memory, which nothing folds.
You
Fold, unfold, pin, or rewrite any digest by hand. Your override always wins.
The agent
Sees {#hs8v8v FOLDED} and calls unfold or recall with that code when it needs the original.
A conductor
Folds for you between turns, under the same rules as your hand. Detaching it is always your call.
Five strategies, all bound by your rules.
A conductor decides what folds. It proposes edits between turns, and every edit is checked by the same code that checks yours, so it can never do anything you couldn't. Pick one from the header, or leave it on None and steer by hand.
-
thermoclinebenchmarkA 500M-parameter probe scores how much recent context still attends to each block. That decides what compresses first, and LLM summaries decide how far. A hard budget sits on top, and if your cap can't be met it says so.
-
triptychThree bands by age. The newest third stays raw, the middle turns file reads into tree-sitter skeletons (signatures kept, bodies dropped), and the oldest third is summarized. The skeletons can be recalled.
-
doormanCatches a huge fresh tool result on its way out and folds it before the model ever pays for it in full. A proof of concept.
-
handoff/handoffwithout leaving the session. It writes a handoff document, folds everything before it, and keeps going. -
compaction-naive/compact, rebuilt as a conductor. It's the baseline everything else is measured against.
Lab notes
One run of thermocline against naive compaction on a long-horizon coding benchmark, with the same model and the same context budget.
- benchmark
- SlopCodeBench, subset
- model
- DeepSeek V4 Pro, both arms
- context budget
- 100k tokens, both arms
- runs
- 1 per arm
- metric
- checkpoints reached, of 6
thermocline
83.3%
compaction-naive
33.3%
What this shows
Under the same tight budget, picking what to fold by relevance got further than summarizing everything, in this run.
What it doesn't
It's one hackathon-scale run on a subset of the problems, not a published result. Broader, repeatable evaluation is next on the roadmap.
UC Berkeley AI Hackathon 2026 · 2nd place, best token compression
Two commands.
-
1
pi install npm:@a-fig/accordionRestart pi if it's already running.
-
2
/accordionRun it inside pi. It prints a local URL that stays the same every time. Open it and you'll see every live session on the machine.
-
3
Folding starts off. Accordion only watches until you flip the toggle, then you steer by hand or pick a conductor.
A desktop app (Tauri) adds read-only browsing of saved Claude Code transcripts. Setup is in the README. The design is in VISION.md.