# Compaction & context

> How a long-running thread stays under the model's context limit without you pruning the conversation.

Every model has a finite context window, and a thread that ships real work will run long. darting.dev's answer isn't "start a new chat" — it's to keep the window small on purpose, and to compact automatically when it still fills up.

## What's in the window

Each turn, an agent carries two things:

- **Its system prompt** — your [project rules](https://darting.dev/docs/rules-and-skills/) read verbatim, the skills index, and the [knowledge manifest](https://darting.dev/docs/structured-memory/) grouped by [Atlas](https://darting.dev/docs/the-atlas/) area.
- **The conversation so far** — every message, tool call, and tool result in the thread.

The first part is deliberately cheap: rules are the only thing pasted in full. Skills and knowledge arrive as an *index* — titles and one-line triggers — and an agent reads the one entry it needs on demand. That's the quiet third leg of context economy, and it's why a project with hundreds of knowledge entries doesn't cost more per turn than one with ten.

The second part is what grows. Two defenses handle it, in order.

## Defense one: delegation keeps the lead lean

Heavy exploration, UI validation, and review don't happen in the lead's context at all — they happen in [sub-agents](https://darting.dev/docs/sub-agents/) with their own fresh context. The lead sends a task and receives a short result, not the whole investigation: a hundred file reads become a paragraph, a browser walkthrough becomes a video and a verdict.

This is the main thing that keeps a long-running thread from filling its window, and it's why [delegation and review](https://darting.dev/docs/delegation-and-review/) are structural here rather than an optimization you remember to apply.

## Defense two: compaction at the wall

When a thread does approach the model's context limit, it compacts itself and keeps going:

1. **Drop spent tool output first.** The bulky results the agent has already acted on — file dumps, command output, search results — go first. The decisions made from them stay.
2. **Summarize earlier turns if that isn't enough.** Older exchanges collapse into a single note carrying what still matters, so the thread continues rather than hitting a wall.

The order matters: the cheapest thing to forget is a file the agent already read and reasoned about, because the reasoning is still in the transcript.

Compaction is a per-thread setting, not a black box. You can change the strategy, trigger a compaction yourself before a big turn, or turn it off entirely for a thread where you want the raw history preserved.

## Watching it happen

The [context inspector](https://darting.dev/docs/context-inspector/) shows the live token count for the lead or any sub-agent, and warns you as the window fills — so you can compact, delegate, or [switch models](https://darting.dev/docs/models-and-auto-mode/) before it becomes a problem, instead of guessing.
