What is context compaction in AI agents?

Short answer

Context compaction is replacing the older turns of a conversation with a summary, so a long agent task can continue inside the context window. The Claude API offers server-side summarization; context editing separately clears selected tool results or thinking blocks. Compaction keeps the session going, but whatever the summary leaves out is gone, so knowledge that must survive belongs in a file or memory outside the window.

How compaction works

An agent adds every tool call, file and result to its context window. After enough work, the window fills up. Without intervention the next request fails; Claude’s API returns a “prompt is too long” error when the input alone exceeds the window. Long before that, quality drops, because accuracy and recall degrade as context grows.

Compaction is the answer: summarize what came before, put the summary in place of the old turns, and continue. Anthropic’s engineering article describes it as taking a conversation near the window limit, summarizing it, and continuing in a fresh window with the summary. The Claude API documentation puts the goal in two parts: keep a long task inside the window, and keep the active context small because response quality degrades as a conversation grows.

The forms it takes

Form What happens Where you find it
Tool result clearing (related: context editing) Old tool outputs are removed; the rest stays Claude API context editing; Anthropic’s engineering article calls it the lightest form of compaction
Thinking block clearing (related: context editing) Old reasoning blocks are removed Claude API context editing
Compaction on demand Your code asks for a summary when it decides to, and swaps it in Claude API, beta header compact-2026-09-04 with the compaction parameter
Compaction at a token threshold The API summarizes inside the request that reaches the limit you set Claude API, beta
Your own summarizer You write the summary call and rewrite the history yourself Any model or framework
First in, first out (truncation, not a summary) The oldest messages silently drop off Some chat interfaces, per Anthropic’s context window docs

The Claude API documentation recommends on-demand compaction where it is available. It can keep recent turns word for word, run in the background while work continues, and use your own summarization prompt when the default summary drops something a later turn needs.

What gets lost

This is the part most people miss. A summary is a lossy copy. The model writing it decides what matters, based on what it knows at that moment. Things that tend to fall out:

  • exact wording of an instruction given early on
  • the reason behind a decision, as opposed to the decision itself
  • error messages and dead ends, which the Manus team argues you should keep visible so the model does not repeat them
  • details that seemed minor then and turn out to matter later

The common misunderstanding is that compaction is memory. It is not. It is a way to keep going with less. Repeated compaction can compound omissions, especially when later summaries rely only on earlier summaries.

What to keep outside the window

The robust pattern combines compaction with storage outside the window:

  1. Notes the agent writes. Anthropic’s article calls it structured note-taking: progress, open questions and decisions go to a file, and the agent reads them back after a reset.
  2. Recoverable references. Manus keeps the URL or file path when it drops the content, so the content can be fetched again. That makes compression reversible.
  3. Instruction files that reload. In Claude Code, CLAUDE.md is loaded at the start of every session, so its rules do not depend on what an earlier session kept.
  4. Shared knowledge. Anything another person or another tool will need should never live only in one session’s history.

What it means for a team

Compaction solves a single-session problem. For a team, the bigger loss happens between sessions and between people. Information explained in one person’s session may be dropped during compaction and never reach a colleague unless it is saved and shared. Read more in what is context rot and how to set up context engineering for a team.

Where Bombos fits

Bombos is the place outside the window: a plugin that gives every AI tool a team uses one shared memory, so decisions, learned rules and team knowledge survive compaction, new sessions and switching tools. Each session retrieves only what it needs from it, and you can trace what an answer rests on. It runs in the cloud or on your own server.

Related questions

Is compaction the same as a bigger context window?

No. A bigger window postpones the limit. Compaction shrinks what is in the window. Because accuracy drops as context grows, compacting early can help even when the window is not full.

Can I control what the summary keeps?

In the Claude API, yes: you can write your own summarization prompt to replace the default one, and you can keep the most recent turns word for word.

What happens to compacted content?

It is replaced by the summary. Details the summary does not mention, such as an exact error message or a decision made early on, are no longer visible to the model.

Does compaction save money?

Often, because later requests carry fewer input tokens. Generating the summary also consumes tokens and adds processing cost.

Sources

  1. Claude API docs: Compaction overview
  2. Anthropic: Effective context engineering for AI agents
  3. Claude API docs: Context windows
  4. Manus: Context Engineering for AI Agents, Lessons from Building Manus
The first half hour · free

What does your AI forget?

  1. 01You tell us which AI you use and where it keeps starting over.
  2. 02We show what a shared memory changes there, on your own examples.
  3. 03You keep the plan, with or without Bombos.
Piet Baudoin
Piet BaudoinYou talk to Piet, from the Bombos teamDutch team from Utrecht and Nijmegen · data in Europe
We reply the same working day.