Context compaction is the process of summarizing a long conversation with an AI agent to free up space in the context window. The summary replaces the old history, and work continues without starting from scratch.

How it works

Every model has a limit on the amount of text it can consider at once, the context window. In long tasks, such as programming for hours, the message history, files read and command results keep filling up that space.

When the limit is approached, the tool asks the model to write a summary of what matters: the goal, the decisions made, the files changed and what is left to do. That summary becomes the new start of the conversation, and the detailed history leaves the context.

Some tools do this on their own. Others offer a manual command that the user triggers when they want.

Practical example

You are asking a code agent to migrate a project from JavaScript to TypeScript. After dozens of exchanges, the conversation is huge and the model starts losing details.

You trigger compaction. The summary keeps something like this:

Texto
Objetivo: migrar o projeto para TypeScript.
Feito: pastas utils e api convertidas.
Pendente: pasta components e ajustes no tsconfig.
Decisão: manter modo estrito desligado até o fim.

With that, the agent picks up where it left off, using much less space.

What it is for

Compaction is used to:

  • Continue long tasks without exceeding the context window.
  • Reduce cost, since less text is sent to the model each round.
  • Keep the model focused on what matters, instead of getting lost in old details.

On platforms that coordinate multiple agents, like bridgecode, keeping each agent's context lean helps run larger projects.

Limits and cautions

Summarizing always loses something. An important detail can be left out. To reduce the risk, write the project's permanent rules in an instruction file, such as AGENTS.md or CLAUDE.md, instead of relying only on the conversation.

Another good practice is to ask for the summary to cite the files and main decisions, and check that it is correct before continuing.

Difference between compaction and a long context window

A larger context window gives more space, but it does not eliminate the limit or the cost of sending a lot of text. Compaction tackles the problem from another angle: it reduces what needs to occupy space. The two techniques can be used together.