# Context window

Long runs fill an agent's context. Kestrel compacts old turns into a summary instead of cutting them off, so the agent keeps working with room to spare.

![As the run goes on, turns fill the window. Near the top, the oldest turns are squeezed into a short summary, and the agent carries on with the space they freed.](/illos/context-window.svg)

## What fills it

The task, the files the agent has read, every tool result and every reply. A run that reads a large repo can fill a million tokens in an hour.

## Compaction

When the window reaches 80%, Kestrel compacts it. The oldest turns are rewritten as a summary a quarter of their size. Your task and the repo's [memory](/agents/memory) are pinned: they are never compacted or dropped.

| | Value |
|---|---|
| Working context | 1M tokens |
| Compaction starts at | 80% full |
| Compaction ratio | About 4 to 1 |
| Always kept | The task, pinned memory, the last 20 turns |

## Tune it

```yaml kestrel.yaml
context:
  compact_at: 0.7     # start earlier on repos with huge files
  keep_turns: 30      # keep more recent turns word for word
```

> [!TIP]
> The trace marks each compaction, with the size before and after. If an agent repeats work after one, raise `keep_turns`.
