Skip to contentRealaization Logo
← Back to blog
October 30, 2026•By the RAZ Team · Edited by Mihan Tilakaratne

When to clear the context instead of compacting it

Three studies and Claude Code's own docs show when to clear the context instead of compacting it.

When to clear the context instead of compacting it

TL;DR

  • Agents anchor to their own past attempts, and in Fork-and-Flush’s runs that survived periodic compaction.
  • On SWE-Shift, all 17 coding-agent systems, including the Claude Code and Codex apps, succeeded less after a mid-run change; GPT-6 Astra fell from 67.35% to 24.79%.
  • Deleting the pre-change conversation, added after a notice and a state refresh, was the largest incremental gain in four of the five systems tested, and Claude Code’s docs now say /clear after two failed corrections.

An agent that has spent an hour on one diagnosis has an hour of its own reasoning in front of it every time it reads the conversation, and a one-line correction from you is a small weight against that. Two research teams and Anthropic’s red team watched agents fixate this month, and a third team measured the neighbouring failure, a change under a running agent. Three of them tested a fresh context over the work, or over its best candidate, and the fourth cleared the pre-change conversation after a notice and a state refresh. Drew Breunig calls it context inertia, the Berkeley paper anchoring, Fork-and-Flush idea basins and Anthropic’s red team fixation: an agent that commits to a hypothesis and keeps pursuing it after the evidence says to stop.

The agent anchors to its own attempts

Every turn spent on a wrong hypothesis writes one more example of it into the context for the next turn to read. Anthropic’s red team saw it in long runs on small open models, where one Qwen agent spent hours debugging package versions when the real bug was an endpoint that did not match the grader’s API. A Berkeley and Stanford team running DeepSeek V4.1 Flash on four discovery tasks found the setups plateaued as history accumulated, bar one task where parallel agents kept improving. Each agent anchored to its own past attempts, its edits grew fewer and smaller, and in the contest-task runs its reasoning per turn fell to a third or less. In one experiment, Anthropic’s Memento harness stopped each agent after ninety minutes and started a fresh one with the codebase, the environment and a note on what was tried, so the next could try something else.

When to clear the context instead of compacting it

Compaction leaves the fixation in place

Compaction is the obvious cure, and it did not prevent the plateau in Fork-and-Flush’s runs, where eight copies of one research agent on one task plateaued at scores from 68.3 to 100.0 and stayed apart with more compute. The group’s repair forks the agent into copies that keep the workspace but start a fresh chat, and continues from the best. Across 13 tasks at matched compute, eleven on GPT-5.6 and two on GPT-5.5, that raised the normalised average score by 66.0% over a single run.

A compaction pass keeps the stated task and the work in progress, and in a fixated session that can be the fixation itself, distilled, so a smaller context is not a fresh one. The Berkeley forgetting result points the same way: from a plateaued state on one contest task, agents allowed to forget gained 4.5 to 9.2% over the next thirty proposals per agent, against under 2% for agents that kept their history. Three runs per arm on one task give the direction and leave the size open.

When to clear the context instead of compacting it

Every system did worse after a mid-run change

SWE-Shift forks each run at a saved state into an unchanged copy and one that meets a task-relevant change, and paired success credits a run only when both copies succeed or the task was verified complete before the change.

When to clear the context instead of compacting it

Across 120 scenarios and 12 kinds of change, success fell for all 17 systems, the Claude Code and Codex apps among them. GPT-6 Astra went from 67.35% on the unchanged copy to 24.79% on the changed one, and Claude Fable 5.1 from 62.01% to 18.33%. Two kinds of change beat every system. When a tool or session changed under the agent, or the evidence it held referred to a state no longer true, paired success was 0.00% for 17 of 17.

When to clear the context instead of compacting it

Three repairs recovered under nine points

Five mid-table systems got three repairs, added one at a time: tell the agent what changed, then let it re-read the current state, then delete the conversation from before the change. Together they added 5.98 to 8.71 points, and the result still ended between 10.89% and 17.54%. More budget helped at first and then stopped, since each doubling from 500,000 to four million tokens per continuation added 0.79 to 2.67 points, and going on to sixteen million added 0.19 to 0.28. SWE-Shift changed the agent’s conditions mid-run and the forgetting study let its own attempts pile up. In SWE-Shift, removing the pre-change dialogue gave the largest increment in four of five systems, and on the contest task a combined reset of sessions and candidate history beat continuing in all three setups. Since even that left most of SWE-Shift’s runs failing, change nothing under a running agent, and when you must, do not stop at telling it.

What the two tools’ docs say about resets

Claude Code’s best-practices page says: after two failed corrections, run /clear and write one new prompt that folds in what you learned. Codex offers /new and /clear, and its subagent docs name context pollution and context rot as reasons to keep noisy work off the main thread; its pages tie a fresh chat to a new prompt, not to a stuck one.

Implications

For a developer in Claude Code or Codex, make a reset the default response to a repeated approach, and write the hand-off note before clearing. Restart the agent after anything that changes under it, a pull, a branch switch or a tool update, a policy and not a result SWE-Shift tested.

For a team building a harness, compaction stays in the loop to control cost, and the reset is a separate mechanism, run on a timer as Memento was, on a repeated approach, or after a change in the environment. The outgoing agent writes its note before the reset, and the next agent’s state lives in files. SWE-Shift’s numbers rest on single runs over 120 designed scenarios.

Takeaways

  • After the second failed correction, clear and re-prompt from a note instead of typing a third. Before that, the same page says to correct.
  • Let nothing change under a running agent, and when a file, tool or session must change, restart it on the current state. In SWE-Shift, work verified complete before a change kept its credit, so finish and verify before you change anything.
  • Treat compaction as a cost control and schedule resets with hand-off notes in a long-running harness. For short tasks whose context never grows, the schedule is overhead.
  • Stop adding budget to a stuck agent; from four to sixteen million tokens per continuation, SWE-Shift’s gains were a quarter of a point. When earlier doublings were still paying, try more budget first.