As a coding agent reads files, runs commands, and troubleshoots errors, its session history grows. Context compaction condenses earlier parts of that history so the agent can keep working. The timing depends on the agent and its settings, and the condensed history may omit a detail from your docs that the agent needs at a later step.
Understanding how coding agents handle context compaction can help you decide where to place instructions and examples in your docs. By varying their placement and running the same workflow across multiple evaluations, you can test whether the agent produces the expected result more consistently, even after compaction.
How Codex and Claude Code handle context compaction
Codex can automatically compact a session when its active context reaches a token threshold. The Codex CLI uses the model’s default threshold unless the user sets a different one. When Codex uses OpenAI’s compaction service, it continues with a smaller set of inputs, including an encrypted item that carries forward information from the earlier conversation. You can see when compaction happened, but you can’t inspect that item to see whether it includes a particular requirement from your product documentation. You can still test whether Codex followed that requirement by checking the result of the task.
Claude Code also compacts automatically as a session approaches its context limit. It summarizes the conversation, reloads the project’s root CLAUDE.md, and revisits up to five files it previously read or edited, starting with the most recently modified. When Claude Code reloads CLAUDE.md, any requirements written there come back into context. If Claude Code first encountered a requirement in the conversation or in your product documentation, it may carry that detail forward in the summary or need to look it up again.
The table below compares how Codex and Claude Code handle compaction and what developers might notice when either agent uses your tool during a long session.
How compaction affects developer tool workflows
| Codex CLI | Claude Code | Effect |
|---|---|---|
| Compacts at a configurable token threshold. The default depends on the model. | Compacts as the session approaches its auto-compaction threshold. The threshold can be adjusted. | The same workflow can reach compaction at different steps across sessions. |
| When Codex uses OpenAI’s compaction service, the smaller set of inputs includes an encrypted compaction item. | Summarizes the conversation and reloads project instructions, including the root CLAUDE.md when present. |
An agent may miss guidance it encountered earlier. In Claude Code, requirements in the root CLAUDE.md become available again automatically. |
| Can reopen accessible workspace files as needed. | Revisits up to five files it read or edited, most recently modified first. For files over 5,000 tokens, it restores only the path. | The agent can recover details your tool saves to disk, though it may need another file read before it can use them. |
For large tool responses, Codex limits how much of an individual tool response it stores in history, so part of a long response may be unavailable later. Claude Code can report an error and stop retrying compaction if a large file or tool response repeatedly refills the context window.
Recovering instructions after context compaction
Recent research on context compaction offers clues about how to design developer tools and write docs that help coding agents pick up where they left off. In a November 2026 study, researchers started with tasks an agent had already solved, paused partway through, and had one of 12 models, including Claude Opus 5 and GPT-5.6-Sol, condense the history to about 10% of its original length. The same agent then resumed from the saved state. On coding tasks, even without the conversation history, the agent could recover some of its progress from edits already in the repository. But when a summary left out a previous finding, the agent sometimes repeated work. Sometimes the summary made an unverified assumption sound like a confirmed result, so the agent stopped before testing it.
OpenAI’s guidance for GPT-6 Astra recommends using brief, task-specific instructions to tell Codex where to look and when. For example, an entry in AGENTS.md can point Codex to the migration guide when a task involves an SDK upgrade. The timeline below shows how that pointer fits into a longer session. Codex can consult the guide when the relevant step comes up, whether that happens before or after compaction.
In Claude Code, where you write a rule affects when it comes back into context. The timeline below shows two points to watch. Claude Code reloads instructions from the project’s root CLAUDE.md immediately after compaction. If a rule applies only to certain files, it loads again when Claude Code reads or edits a matching file.
Drawing on this research and guidance from OpenAI and Anthropic, here are four ways to help coding agents find the instructions they need after compaction and verify that they’ve used your tool correctly. They’re listed in the order we’d prioritize them.
- Define the expected behavior. Define the expected outcome and the requirements the agent must follow throughout the workflow.
- Put the requirement beside the relevant step. Place each requirement alongside the step or example where the agent needs to act on it.
- Provide a runnable check. Provide a runnable check or an observable outcome the agent can compare with the expected behavior.
- Make the guidance easy to find again. Make guidance easy to find after compaction by keeping it in a predictable location and linking to it wherever the agent may need it again.
Conclusion
Context compaction lets coding agents keep working through long sessions, but a requirement they read early on may be missing when they need it later. Evaluating the agents can show whether they follow that requirement after compaction and whether clearer instructions or a better-placed example improve the outcome. When agents can find the guidance they need and verify their work, users can rely on them to complete more of the workflow without stepping in.


Top comments (0)