# Compaction

> A handoff done in-memory: the previous session's history is summarised and seeds a fresh session. Lossy — detail traded for headroom.

A [handoff](https://ai9k.vercel.app/en/handoff) done in-memory: the previous [session](https://ai9k.vercel.app/en/session)'s history is summarised, and the summary seeds a fresh session. Lossy by design: the transcript is a [primary source](https://ai9k.vercel.app/en/primary-source), the summary a [secondary source](https://ai9k.vercel.app/en/secondary-source) — detail traded for headroom. Triggered manually by the user, or automatically via [autocompact](https://ai9k.vercel.app/en/autocompact).

The mechanism: the [context window](https://ai9k.vercel.app/en/context-window) is finite, and a long session fills it — every [tool result](https://ai9k.vercel.app/en/tool-result), every file read, every wrong turn stays in history. When it gets heavy, the [harness](https://ai9k.vercel.app/en/harness) asks the [model](https://ai9k.vercel.app/en/model) to summarise the session, throws the original history away, and seeds a fresh session with the summary. Whatever didn't make it into the summary is gone from the context. Some harnesses soften this by keeping the old transcript on disk and leaving a [context pointer](https://ai9k.vercel.app/en/context-pointer) to it in the summary — the secondary source links back to its primary source, so a detail the summary lost can be recovered by re-reading the original.

The summary is written by the model, so it can be prompted. "Preserve the schema decisions" makes the generated artifact more deliberate. Timing matters too — compact at a phase boundary, after the plan is settled, not mid-task.

Contrast with [clearing](https://ai9k.vercel.app/en/clearing), which drops everything and starts cold: compaction tries to carry the essentials across; clearing bets they're already written down somewhere better.

**Usage**

"[Context](https://ai9k.vercel.app/en/context)'s getting heavy and I still have the test pass to do."

"Compact before you start — write what must survive into the summary prompt so the new session keeps the schema decisions and drops the exploration."

---

- Section 5 — Handoffs · Term 51 of 72
- Page: https://ai9k.vercel.app/en/compaction
- Learn step by step: https://ai9k.vercel.app/en/learn#/compaction
- On the map: https://ai9k.vercel.app/en?term=compaction
- JSON: https://ai9k.vercel.app/data/terms/compaction.json
- Mentioned in: [Harness](https://ai9k.vercel.app/en/harness.md), [Input tokens](https://ai9k.vercel.app/en/input-tokens.md), [Context window](https://ai9k.vercel.app/en/context-window.md), [Session](https://ai9k.vercel.app/en/session.md), [Hallucination](https://ai9k.vercel.app/en/hallucination.md), [Attention degradation](https://ai9k.vercel.app/en/attention-degradation.md), [Smart zone](https://ai9k.vercel.app/en/smart-zone.md), [Clearing](https://ai9k.vercel.app/en/clearing.md), [Handoff](https://ai9k.vercel.app/en/handoff.md), [Secondary source](https://ai9k.vercel.app/en/secondary-source.md), [Handoff artifact](https://ai9k.vercel.app/en/handoff-artifact.md), [Autocompact](https://ai9k.vercel.app/en/autocompact.md)
- Previous: [Ticket](https://ai9k.vercel.app/en/ticket.md)
- Next: [Autocompact](https://ai9k.vercel.app/en/autocompact.md)

Every term page has a markdown copy: add .md to its address.
