<!-- Markdown mirror. Canonical: https://empryo.com/docs/context/compaction -->

# Context compaction

> How Empryo compacts long conversations at 95% of the real context window using structured-state (V2) or LLM-summary (V1) strategies, configurably.

When your conversation gets close to the model's context window, Empryo compacts it - summarizes older messages into a concise state, preserves the recent ones verbatim. The conversation continues, nothing is lost.

Compaction fires automatically at 95% of the model's REAL context window (capped per lane by the reply reserve). Late, so the cached prompt prefix survives as long as possible. You can also run it manually:

```
/compact
```

## Two strategies

#### V2 (default) - instant, usually free

Empryo tracks structured state - files touched, decisions, discoveries, tool results - as the conversation happens. When compaction fires, this state is already built. Most sessions compact in zero LLM calls.

Best for: typical coding sessions.

#### V1 - LLM summary

Sends the older half of the conversation to a cheap model and replaces it with a prose summary.

Best for: design-heavy sessions where nuanced reasoning matters more than structured data.

Switch with `/compact settings` or in config.

## Config

```json
{
  "compaction": {
    "strategy": "v2",
    "triggerThreshold": 0.95,
    "keepRecent": 4
  }
}
```

| Field | Default | What it does |
|-------|---------|--------------|
| `strategy` | `"v2"` | `"v2"` or `"v1"` |
| `triggerThreshold` | `0.95` | Auto-compact at this fraction of the real context window |
| `keepRecent` | `4` | Recent messages kept verbatim |
| `maxToolResults` | `30` | Rolling window of tool results (V2) |
| `llmExtraction` | `true` | Allow a cheap gap-fill pass (V2) |

## Which model compacts

Assign a cheap model in the [task router](/docs/recipes/task-router):

```json
{
  "taskRouter": {
    "compact": "google/gemini-2.5-flash"
  }
}
```

For V2, this model only runs the optional gap-fill. For V1, it does the whole summary.

## Signals

- Context bar shows compaction strategy + slot count.
- Compacting spinner during an active compaction.
- System message reports before/after context percentages.
