Topic 5 of 5 · 6 min read
Correcting, rewinding or restarting a session
Goal: Decide from a session log whether to correct the agent, rewind to a checkpoint or start fresh with a better brief.
When a session goes wrong, pick the smallest fix that restores a clean state: correct, rewind or restart. Arguing with a confused agent for twenty messages is the most common wrong choice.
Check yourself · 1 of 3
The same bug has returned after two separate corrections in one session. What is the best next move?
Why it matters
An agent reads the whole conversation each time it answers. Wrong guesses, failed attempts and abandoned ideas all stay in that context and keep influencing it. Anthropic's best practices for Claude Code say the same: after two failed corrections on the same issue, clear the context and start again with a better prompt. A fresh start with a better brief often beats a long, tangled fix.
The three moves
- Correct. Use it when the agent is on the right track with one slip. Interrupt early (in Claude Code, press Esc) as soon as you see it going wrong, rather than after it finishes. Say exactly what to change. One correction should fix it.
- Rewind. Use it when the last step went bad but everything before it was good. Roll code back to your last commit or checkpoint, and in tools that support it, rewind the conversation too, so the bad attempt leaves no trace. Claude Code has a rewind command and checkpoints; check what they do and do not cover, because changes made by shell commands may not be tracked. A git commit always works.
- Restart. Use it when the context itself is polluted: the same error returns after two corrections, the agent contradicts earlier decisions, or the session is long and its replies have become vague. Save what you learned, start a new session, and give a better brief: the goal, the plan so far, the rules it broke, and the checks.
Reading the signs
msg 14 fix the null check -> new error in parser.ts
msg 16 fix parser.ts -> original null error is back
msg 18 no, undo that -> reverts half of both
msg 20 agent: "I apologize, let me start over"
Four messages circling the same bug is the signal. Correcting a fifth time will not help. Rewind to the last green commit, or restart.
Before and after
Weak: keep sending "still broken, try again".
Better: git reset --hard <last-green>, open a new session and paste: "Goal, steps 1 to 2 done, step 3 failed because the parser needs normalizeInput first. Do step 3 using it. Done when npm test -- parser passes."
What goes wrong
- Fighting on. Each failed attempt adds noise.
- Restarting with the same weak brief. You get the same failure.
- Rewinding code but not noting why. The agent in the new session repeats the mistake.
Examples
Correct, rewind or restart?
Case 1: the agent used var instead of const. Correct it in one message. Case 2: step 4 broke the build, steps 1 to 3 are committed. Rewind to the step 3 commit. Case 3: three fixes in a row each broke something else and the agent now argues with itself. Restart with a new brief.
A brief that carries the lesson
Continue the coupon feature. Steps 1-2 are committed.
Lesson: `parseCoupon` must call `normalizeInput` first; skipping it caused
the earlier null errors. Do step 3 only.
Done when `npm test -- checkout` passes.
Key points
- Correct early and specifically when the agent is on track with one slip; interrupt as soon as you see the problem.
- Rewind to your last good commit or checkpoint when only the last step went bad.
- Restart in a fresh session when the same error returns after two corrections or the agent contradicts itself.
- A restart needs a better brief: the goal, work done, the lesson learned and the checks.
- Git commits are the rollback you control; tool checkpoints may not cover shell-made changes.
Common mistakes
- Sending ever more corrections to a session that keeps repeating the error.
- Restarting but pasting the same vague task.
- Rewinding without a commit and losing good work.
- Assuming tool checkpoints undo everything, including shell commands.
Check yourself · 2 of 3
Only the most recent step went wrong, and steps 1 to 3 are committed. Which move fits?
Check yourself · 3 of 3
What should a fresh session's first message include after a failed attempt?
Practice items, not counted towards your mastery.
Start here
- Best practices for Claude Code (Claude Code docs) (opens in a new tab)DocsFree
A vendor's own advice: explore and plan first, give the agent a way to verify, and clear context when it drifts.
- Checkpointing (Claude Code docs) (opens in a new tab)DocsFree
How to rewind code and conversation to an earlier point in a session, and what checkpoints do not cover.
- Exploring Generative AI (martinfowler.com) (opens in a new tab)ArticleFree
Field notes from Thoughtworks on working with AI in small steps and reviewing every output.
More for this topic
- Undoing Things (Pro Git) (opens in a new tab)BookFree
The git commands for undoing a commit or a file change, which is your rollback when an agent step goes wrong.