How auto-compact works in five coding agents
What do Claude Code, Codex, Copilot, Cursor and Antigravity do when the context window fills? Auto-compact, /compact and /clear.
Summary. The context window is all the text a model can read at once, and in a long coding session it fills up. When it does, the tools summarise the conversation on their own; this is called auto-compact. On 20 October 2026 we read what Claude Code, OpenAI’s Codex, GitHub Copilot (the CLI and VS Code), Cursor and Google’s Antigravity CLI do at that point, each in its own documentation and release notes.
- When the window fills, an agent has four options. Delete old tool output, summarise the conversation, drop the oldest messages, or write long output to a file. All five tools summarise; when they start and what you can configure differs from tool to tool.
- A summary loses things. Detailed instructions from the start of the conversation can drop out of it, the cache is written again from the start once, and the summary itself is text a model wrote. Put a rule that must be followed in the rules file, not in the conversation.
- Compact for the same task, clear for a new one. Handing a long, noisy step to a subagent, on the other hand, never fills the main conversation’s window at all.
- A code review agent cannot summarise. diffox reviews a pull request in one pass: it decides what goes in before the call, and records which file was not read in full.
What does a coding agent do when the context window fills?
The context window is all the text a model can read in a single request: your messages, the agent’s replies, the files it has read, command output, rules files and system instructions. A coding agent sends all of it to the model again at every step, so in a long session the window fills sooner or later. Our post on prompt caching explained how a cache makes that repetition cheaper; this post is about what happens when the window fills.
There is a problem even before the window fills. Anthropic’s compaction documentation says plainly why it summarises: the longer a conversation gets, the worse the answers get, so the active context has to be kept small. So an agent summarises the conversation not only to avoid an error, but also to keep working well.
As the window fills, an agent has four ways to go:

Anthropic’s API documentation describes these ways in the most detail. The context editing feature deletes old tool results, oldest first, and puts in place of each a short text saying it was removed. With the default settings, clearing starts once a request goes over 100,000 tokens, and the last 3 tool uses stay as they are. Compaction, by contrast, replaces the older turns with a summary Claude writes on the server.
Coding tools combine these ways. Claude Code first clears old tool output, then summarises the conversation if there is still not enough room. Copilot CLI writes a tool output larger than 20 KiB to a temporary file; the model gets only the file’s path and a preview. Cursor also writes long shell and MCP output to a file instead of cutting it, and the agent reads the rest of the file when it needs to; Cursor described this in a post from January 2026.
Dropping the oldest messages, on the other hand, is not given as the default in any of the five tools’ documentation; all of them describe summarising. Copilot’s documentation also says why: without a summary, old messages would be deleted without leaving any record, and Copilot could not know what had been in them.
How does auto-compact work in the five tools?
All five tools summarise the conversation on their own and give you a command to do it by hand. They differ in when the summary starts, what you can configure and what changed in the last two months. We read the facts in the table in each tool’s own documentation and release notes on 20 October 2026:
| Tool | When it summarises | By hand and in settings | What changed in September–October |
|---|---|---|---|
| Claude Code | At the model’s limit; on models with a 1M token window, at about 967K tokens | /compact <focus>; threshold with /autocompact or autoCompactWindow; a “Compact Instructions” section in CLAUDE.md | 2.1.288 (2 October): threshold per model; 2.1.296 (9 October): a separate threshold for subagents; 2.1.299 (14 October): summarising an idle conversation |
| Codex | At the model’s default threshold; the number is not stated in the documentation | /compact; threshold with model_auto_compact_token_limit, summary instructions with compact_prompt | 8 October: remote compaction for custom providers; 15 October: a setting for asynchronous compaction |
| GitHub Copilot CLI | Starts in the background at about 80% full; at 95% full it waits until the summary is done | /compact [focus]; a setting that changes the threshold is not stated in the documentation | 1.0.85 (16 September): every automatic summary is saved as a checkpoint; 1.0.92 (5 October): your latest prompt is kept |
| Copilot, VS Code | When the window fills; the threshold is not stated in the documentation | /compact [focus]; a setting turns the automatic summary off | — |
| Cursor | When the window is close to full; the threshold is not stated in the documentation | /summarize in the CLI; a setting is not stated in the documentation | CLI 2026.10.08: a session that hits the limit summarises and carries on, and your latest request is kept word for word |
| Antigravity CLI | On its own; the threshold is not stated in the documentation | /compact; a setting is not stated in the documentation | 1.2.8 (22 September): a long first instruction is no longer cut to a small slice in the summary; 1.3.5 (14 October): /compact arrived |
Source: each tool’s documentation and release notes, 20 October 2026. “Not stated in the documentation”: in the pages we read that day, we found no sentence that says this. “—”: in the release notes we read, we found no change from these months. Cursor’s CLI version is the date it was released. /compact came to Antigravity’s desktop app with version 2.24.0 (15 October). The two Codex changes shipped in versions 0.162.0 and 0.163.0.
Claude Code describes its threshold in tokens, not as a percentage. According to the documentation, if you have not set a threshold, the conversation is summarised when it reaches the model’s context limit; on models with a 1M token window, that happens before the window fills, at about 967K tokens. If you want it to summarise earlier, you type a command such as /autocompact 500k; the value is saved to your settings for that model. Since version 2.1.299 (14 October) there is also idle summarising, which we cover in the next section.
Copilot CLI uses two thresholds instead of one. According to the documentation, the summary starts in the background when the conversation reaches about 80% of the window; the rest is held back so that tool calls can keep running while the summary is written. If the window reaches about 95% before the summary is done, the CLI waits briefly.
In Codex, the threshold is set by model_auto_compact_token_limit in the ~/.codex/config.toml file. If you leave it empty, the model’s default is used; the documentation does not give that default as a number. You can change how the summary is written with compact_prompt.
If you still use Gemini CLI: Gemini CLI compresses by default once half the context is full (compressionThreshold defaults to 0.5), and the manual command is /compress. For free-tier and Google One users, Google replaced Gemini CLI with Antigravity CLI on 18 June 2026; Gemini CLI remains in use with enterprise licences and paid API keys.
What is lost when the conversation is summarised?
Summarising has three costs, and all three are written in the tools’ own documentation.
The cache breaks. Prompt caching stores the unchanging start of a request, and later requests read it cheaply. A summary or a clearing changes the start of the conversation. The next request can use the cached copy only up to the point that changed, and writes the rest again. That is why Anthropic’s documentation recommends the clear_at_least setting: each clearing should delete at least a certain number of tokens, so that rewriting the cache is worth it. Which changes break the cache is covered in detail in our post on prompt caching.
Claude Code’s idle summarising, added on 14 October, comes from the same arithmetic. According to the release note, a conversation over 200,000 tokens that sits idle for about 54 minutes is summarised before the one-hour cache expires. According to the settings documentation, when you come back, your first message sends the summary, not the whole conversation. If you don’t want this, you can turn it off in your settings with "idleCompaction": false.
Instructions from the start of the conversation can be lost. Claude Code’s documentation is clear: your requests and key code snippets are kept, but detailed instructions you gave early in the conversation may be lost; put lasting rules in CLAUDE.md, not in the conversation. Copilot’s documentation says that small decisions made early in a long conversation may not make it into the summary, and that a finished summary cannot be undone. VS Code and Cursor say the same thing: a summary is lossy compression.
Antigravity CLI’s 1.2.8 release note is a concrete example of that loss: up to that version, when the other prompts in a conversation were short, a long first instruction was cut to a small, fixed slice in the summary. How to write a rules file is covered in our post on AGENTS.md and CLAUDE.md.
The summary itself can turn into an instruction. A summary is written by a model too, and the model that carries on after it may read it as an instruction. The clearest example is OpenAI’s report: during training, an unreleased model added unauthorised instructions to its own compaction summaries. OpenAI noticed this on 9 August, updated the report on 16 September, and found 27 such summaries in the training data.
In one example, the user had asked for a long literature review with citations. The summary added a rule nobody had asked for: the answer would be at most 30 words, with no tools and no sources. The model that carried on after the summary followed that rule and wrote a 23-word refusal. According to the report, this was seen in a training run separate from the one the final model came from, and it did not happen again when the summary was regenerated; in other words, it was not seen in a released model.
The lesson is general all the same: a summary is not an instruction you wrote, it is text a model wrote. A similar bug has been seen in coding tools too. Claude Code’s 2.1.292 release note fixes one: a summary that repeated a skill command could lead Claude to run a skill reserved for the user. If the agent does something you did not expect after a summary, look at the summary first: in Copilot CLI, /session checkpoints shows each automatic summary on its own.
When should you use clear instead of compact?
The two commands solve the same problem in two different ways. Compact replaces the conversation with a summary and carries on in the same session. Clear drops the conversation entirely and starts with an empty context; the rules and memory files on disk stay where they are. Which one you pick depends on whether the next task needs the earlier conversation:

| Tool | Summarise | Start from scratch |
|---|---|---|
| Claude Code | /compact <focus>; /rewind to summarise part of the conversation | /clear |
| Codex | /compact | /clear or /new |
| Copilot CLI | /compact [focus] | /clear or /new |
| Copilot, VS Code | /compact [focus] | A new chat in the same session, or a new session |
| Cursor | /summarize in the CLI | /clear in the CLI |
| Antigravity CLI | /compact | /clear or /new |
Source: each tool’s command documentation, 20 October 2026. The focus in square or angle brackets is optional: it is where you write what should stay in the summary.
The most concrete test for when to clear is in Claude Code’s documentation: if you have corrected Claude more than twice on the same issue, the context is full of failed attempts; type /clear and start again with a clearer prompt that includes what you learned. Copilot’s documentation adds one more: if the conversation has been summarised many times and you think something important has been lost, open a new session.
The third option is to keep the noise out of the main conversation altogether. When you hand a step such as reading a long log, scanning a large test output or searching the codebase to a subagent, everything it reads stays in the subagent’s own window, and only the result comes back to the main conversation. Claude Code, Copilot and Cursor recommend this explicitly in their documentation; we covered subagents in a separate post. In Claude Code, since version 2.1.296 (9 October), you can also give a subagent an earlier summarising threshold than the main conversation. The example in the documentation is a subagent that reads long log files:
---
name: log-reader
description: Reads long log files and reports the errors it finds
autoCompactWindow: 200000
---Write the value as a plain number. According to the documentation, Claude Code reads 200k in this field as 200; that value is outside the allowed range, so the subagent runs as if the field were not there at all.
What does the agent re-read after a summary?
The way to get through a summary intact is to keep information on disk, not in the conversation. Claude Code’s documentation lists, item by item, what comes back after a summary:
| Information | After the summary |
|---|---|
| CLAUDE.md in the project root | Re-read from disk |
| Auto memory (MEMORY.md) | Re-read from disk; the first 200 lines or the first 25 KB, whichever comes first |
| Files read or edited | Up to 5 of the most recently changed are re-read; for a file over 5,000 tokens, only the path comes back |
| Skills used | Added back: up to 5,000 tokens per skill and 25,000 in total |
Rules scoped with paths:, CLAUDE.md in subfolders | Stay inside the summary; come back when a matching file is read again |
| Instructions you gave in the conversation | Live only in the summary |
Source: Claude Code documentation, the “Explore the context window” and “Store instructions and memories” pages, 20 October 2026.
If you want an instruction you gave in the conversation to still apply after a summary, there are two ways: write it in CLAUDE.md, or use a hook that runs after every summary. Here is the example from Claude Code’s documentation:
{
"hooks": {
"SessionStart": [
{
"matcher": "compact",
"hooks": [
{
"type": "command",
"command": "echo 'Reminder: use Bun, not npm. Run bun test before committing.'"
}
]
}
]
}
}The text the hook prints is added next to the summarised context. Instead of echo, you can also run a command that reports the current state, such as git log --oneline -5. We covered hooks in a separate post. In the other tools, this is how things stand:
- Codex: local memories are off by default. The documentation tells you to write the rules your team must follow in AGENTS.md, and to treat memories only as a layer that helps you recall.
- GitHub Copilot: when the CLI summarises, it keeps the user’s original instructions and the latest state of plans and to-do lists alongside the summary. Copilot Memory (in public preview) shares facts about a repository between the CLI, the cloud agent and code review; before using a fact, it checks the code the fact relies on against the current branch. VS Code’s memory tool keeps notes locally; the documentation recommends writing the decisions your team relies on in source-controlled documents or in custom instructions files.
- Cursor: according to the documentation, the model remembers nothing between completions; rules are there for lasting context. When it summarises, Cursor also gives the agent the chat history as a file, and the agent can search it for what the summary left out (post from January 2026).
- Antigravity: the
/learncommand proposes what was learned in a session, such as a fix or a constraint that keeps being missed, as a rule or a skill; it writes nothing to a file until you approve. The documentation starts from a plain fact: agents don’t remember conversations. - Gemini CLI: the experimental
autoMemorysetting draws memory suggestions from past sessions; it is off by default, and none of them is applied until you approve it in/memory inbox.
Why can’t a code review agent summarise?
Everything so far applies to a session that talks with a person and grows as it goes. An agent that reviews a pull request does not work that way: it is a single call, it has nobody to ask, and it has no history to summarise. It has to decide before the call what goes to the model.
In diffox, that decision is made by the context pack that all the specialist agents in a review share. In the code, the pack is built like this:
- The diff comes first. Then the changed lines and symbols, the callers the change affects and the git history; the file context, the PR description and the commit messages come last. If the pack goes over the limit, it is cut from the end, and a line saying so is added where it was cut. The order was chosen so that the part whose loss costs the least is the part left at the end.
- Lock files stay out of the diff. Files a tool writes, such as
go.sum,package-lock.jsonanduv.lock, vendor folders and minified files are taken out of the diff, and their names are written on a single line. The code keeps the reason as a measurement: on one pull request in the benchmark set,go.sumandgo.work.sumwere 68.5% of the diff, and the source file holding the bug under review was 4.2%. - The area around the change goes in, not the whole file. Each skipped range of lines is written with its line numbers, so the model knows what is missing.
- The repository’s rules travel outside the pack. The rules in the rules file that must be followed are added separately to every agent’s system prompt, so the cut never touches them. This is the review side’s counterpart of the coding agents’ advice to “put lasting rules in the rules file”.
- A file that was not read is recorded. Every review records whether each changed file reached the agents whole, in part or not at all. If some files were not read in full in a review that produced no findings, the pull request comment says so in one sentence.
Whatever tool you use, the lesson is the same: if the agent did not read a file, a “no findings” answer says nothing about that file. With a coding agent too, look at what is in the window before you say “it already knows that”: in Claude Code, Copilot CLI and Antigravity CLI, /context shows it.
Frequently asked questions
When does auto-compact run in Claude Code?
If you have not set a threshold, when the conversation reaches the model’s context limit. On models with a 1M token window, by default it runs before the window fills, at about 967K tokens. You can change the threshold for one model with a command such as /autocompact 500k, or for every model with the autoCompactWindow setting. Since version 2.1.299 (14 October), a conversation over 200,000 tokens is also summarised if it sits idle for about 54 minutes.
How do you change the auto-compact threshold in Codex?
Set model_auto_compact_token_limit to a number of tokens in ~/.codex/config.toml. If you leave it empty, the model’s default is used; the documentation does not give that default as a number. You can change how the summary is written with compact_prompt, or from a file with the experimental experimental_compact_prompt_file. tool_output_token_limit, for its part, limits how much room a single tool output takes in the history. To summarise by hand, type /compact.
What is the difference between /compact and /clear?
/compact replaces the conversation with a summary and carries on in the same session; some details may be lost. /clear drops the conversation entirely and starts a new chat with an empty context; in Claude Code, project memory stays where it is. Use compact if you are carrying on with the same task, and clear if you are moving to an unrelated one. Claude Code’s documentation also recommends starting again with /clear and a clearer prompt if you have corrected Claude more than twice on the same issue.
Can you turn auto-compact off?
In Claude Code, yes: "autoCompactEnabled": false in your settings, or DISABLE_AUTO_COMPACT for a single session. A manual /compact keeps working, and idle summarising turns off too. For Copilot in VS Code, you set github.copilot.chat.summarizeAgentConversationHistory.enabled to false. The documentation of Codex, Copilot CLI, Cursor and Antigravity CLI does not mention a setting that turns the automatic summary off; in Codex you can only change the threshold.
Does compaction break the prompt cache?
For the next request, yes. A summary or a clearing changes the start of the conversation; the cached prefix no longer matches, the new start is written once more, and the requests after that read it. When clearing old tool output, Anthropic recommends deleting enough tokens each time with clear_at_least, so that rewriting the cache is worth it. That is why Claude Code summarises a large idle conversation before the one-hour cache expires: if the cache is going to go cold anyway, the summary goes out when you come back, instead of the whole conversation.
Why does the agent forget rules after a summary?
Claude Code’s documentation gives three reasons: the instruction was given only in the conversation, it was in a CLAUDE.md in a subfolder that has not been reloaded yet, or it was a rule scoped with paths: and no matching file has been read since. The fix is to put the rule in the CLAUDE.md at the project root: Claude Code re-reads it from disk after the summary. The Codex and VS Code documentation also tells you to write the rules that must be followed in AGENTS.md or in custom instructions files.
Does diffox summarise the context when it reviews a large pull request?
No. A review runs in one pass, so it decides what goes in before the call. The diff sits at the start of the pack, and the file context, the PR description and the commit messages at the end; if the limit is exceeded, the pack is cut from the end and the cut is marked. Lock files are taken out of the diff, the area around each file’s changes is sent, and the repository’s rules go to every agent separately from the pack. Which file was not read in full is recorded; in a review that produced no findings, the pull request comment says so in one sentence.