Topic 5 of 5 · 3 min read
Recovering from a corrupted context
Goal: Choose the cheapest recovery (edit, remove, reset memory or restart) for a session whose context has gone wrong.
When a context has gone wrong, use the smallest fix that removes the bad material: edit the message, remove the item, reset memory, and only then restart with a clean brief. Arguing with the model rarely works, because the bad text is still in the window.
Check yourself · 1 of 3
The assistant keeps using a wrong figure from message 4. What is the cheapest effective fix?
Why it matters
Poisoning, clash and confusion all live in the window. The model reads them again every turn, so a reply that says "sorry, you are right" does not delete anything. Each fix works by changing what the model sees on the next turn. Choosing the cheapest one saves your time and keeps the good work you already did.
The ladder, cheapest first
- Edit the message. Most chat tools let you edit an earlier message of yours and rerun from there. Use it when the problem began with something you wrote, or when you can fix the line that started it. Later turns are replaced.
- Remove the item. Delete the bad attachment, drop the wrong tool result, detach the unrelated file, or disable the tool that does not fit. Use it when one identifiable item is the cause.
- Reset memory. If a saved note disagrees with the task, correct or switch off that memory entry. Use it when the same mistake appears in new chats.
- Restart with a clean brief. Open a new chat and paste a short, checked summary: the goal, verified facts, decisions made and what is still open. Use it when many things went wrong, the chat is long, or you cannot find the source.
Before and after
Before: Forty messages in, the assistant keeps using an old price. You have replied "no, the price is 45" five times.
After: You find the first message with the old price, edit it to 45, and rerun. If a saved memory also says the old price, you correct that note. The answers stay correct.
How to write a clean brief
Do not paste the old chat. Write: the goal in one sentence, the facts you have checked, the decisions already made, and the next step. Leave out guesses, dead ends and anything unverified. Ask the model to restate the brief back to you before it starts.
What goes wrong
- Restarting too early. You lose good work when a one-line edit would do.
- Restarting too late. You keep patching a context that is full of conflicting corrections.
- Copying the poison. A summary written by the model from a corrupted chat can carry the error into the new one. Check each fact yourself.
Optional: in a coding agent
/clear (reset the session), then re-state: goal, verified file paths, test command
Reload only the instructions the task needs.
Examples
Edit instead of restart
A long chat about a trip used the wrong dates from message 4. Editing message 4 and rerunning gave a correct itinerary in a minute. Starting over would have lost an hour of choices.
A clean brief
After a messy session, the user opens a new chat with: "Goal: a 5-slide update for the board. Checked: sales were 1.2M, up from 1.0M. Decided: no forecast slide. Next: draft slide outline." Four lines, all checked, nothing else.
Key points
- A reply that agrees with your correction does not remove the bad text from the window.
- Fix the cheapest thing first: edit the message, remove the item, reset memory, then restart.
- Editing an earlier message replaces everything after it, so use it when you can find the first bad line.
- A clean brief holds only the goal, checked facts, decisions and next step.
- Check any summary of a corrupted chat yourself before you paste it into a new one.
Common mistakes
- Repeating corrections instead of changing the source of the error.
- Starting a new chat when a single edit would fix the problem.
- Pasting the whole old chat into the new one.
- Forgetting that saved memory can bring the same mistake back.
Check yourself · 2 of 3
When is a full restart with a clean brief the best choice?
Check yourself · 3 of 3
Which of these belongs in a clean brief for a new chat?
Practice items, not counted towards your mastery.
Start here
- How long contexts fail (Drew Breunig) (opens in a new tab)ArticleFree
Names poisoning, distraction, confusion and clash, with examples from real agents.
- How to fix your context (Drew Breunig) (opens in a new tab)ArticleFree
Practical ways to prune, quarantine and summarise context after a failure.
- The lethal trifecta for AI agents (Simon Willison) (opens in a new tab)ArticleFree
Plain explanation of when untrusted content in context can leak private data.
More for this topic
- Effective context engineering for AI agents (Anthropic) (opens in a new tab)ArticleFree
Anthropic's guidance on keeping only the most useful information in the window.