In the last lesson, you stopped your agent at its first wrong step and sent a correction that named the file, function, rule, or example it should follow. Most of the time, one correction like that is enough. Sometimes, though, the agent drifts back to the approach you ruled out, and you find yourself typing the same correction again.
In this lesson, you’ll learn to recognize when a session has stopped helping, write a fresh task that carries over only what the failed attempt taught, and move a correction you’ll need again into the file every session reads. Start with what a second correction tells you.
Notice When a Session Stops Helping
Typing a correction again feels like progress, because the agent agrees and changes course. But your agent works from everything in this session: your task, the files it read, command output, its own plans and edits, and your messages. The model predicts each next step from all of it.
Your correction is one short message in that context. The wrong approach, with its plan, code, test runs, and explanations, is usually much bigger. A clear correction often redirects the agent anyway, but when it drifts back, that history is still there, and resending the same message is no guarantee of a different result.
Here’s a second run of the list-rooms task, written for this lesson as an example. After the last lesson’s correction, the agent stated a new plan:
Plan:
1. Import checkRoom() from src/check-room.js.
2. For each JSON file in rooms/, call checkRoom() and
print the room's name and its verdict.
3. Add a fallback that works out whether every puzzle
can be reached, for rooms checkRoom() can't check.
4. Add a list-rooms script to package.json, and a test.
Steps 1 and 2 follow your correction. Step 3 brings back the second checker under a new name, and you’re about to send the same correction again. That’s one of two signals to stop correcting:
- The same correction, twice: You’re about to resend a correction from this session, even if you reword it, when the first one already named the file or rule.
- A context full of the wrong approach: The session is long, and much of it is the wrong attempt’s plans, code, failed runs, and undone edits. After a compaction, your correction may survive only as a summary, or not at all.
Watch out: Correcting an agent doesn’t retrain its model, so repeating a correction won’t make it stick. Some agents save notes for later sessions, but you can’t count on a correction being saved or followed.
Carry Over Only What the Attempt Taught
Once a session stops helping, a fresh session gives the agent a clean start: none of the old conversation, only the instruction file, any saved memory your agent loads, what it reads from disk, and your new task. Send the old task again, though, and nothing stops the same wrong turn.
The old session wasn’t wasted. A failed attempt shows either something your task left out or the particular way the agent broke a limit the task already set. Sort what you saw into two piles:
- Carry over: The goal and done-when, a more precise statement of any limit the agent broke, and any fact the run turned up, such as where the function to reuse lives
- Leave behind: The wrong code, the history of attempts, and remarks such as “last time you ignored this,” which point at a conversation the new session doesn’t have
On an unfinished task, first run git status and restore or delete what the abandoned attempt changed, as in the last lesson. A fresh session reads files from disk, so it would pick the wrong approach back up.
Here’s the list-rooms task rewritten after the example run, with changes in where to look and in the limits:
Add a list-rooms command that prints every room in
rooms/, one line each, with its verdict.
Read docs/map.md, then src/check-room.js, where
checkRoom() decides whether a room can be finished,
and check-room.js, which calls it for one room.
Use checkRoom() for every verdict. Don't write any
other code that works out whether puzzles can be
reached, not even as a fallback. Add no new
dependencies. Don't change check-room.js or its
output, or any file in rooms/.
Done when the command prints one line per room, each
with the verdict check-room.js gives it, and npm test
passes. Then stop and list the files you changed.
The new “where to look” says what checkRoom() does, so the agent reads it as the function to reuse. The old task already said to use checkRoom(), so the new limit makes that rule concrete: it excludes any second checker, even one disguised as a fallback. That doesn’t guarantee the agent follows it, but starting fresh removes the pile of wrong attempts. Nothing mentions the earlier session, so the task stands on its own.
To start fresh, exit your agent and start it again in the project folder, in the mode that asks before edits. Open the version for your agent, checked in December 2026 with Claude Code 2.1 and Codex CLI 0.173:
Type /exit, then start a new session with claude --permission-mode manual. /clear also starts fresh without leaving Claude Code. Don’t use claude --resume or /compact, because both keep the wrong attempt, whole or summarized. Auto memory, on by default, can carry notes into new sessions. Check them with /memory, and delete one that records the wrong approach.
Type /exit, then start a new session with codex --sandbox read-only --ask-for-approval on-request. /new also starts fresh without leaving Codex. Don’t use codex resume or /compact, because both keep the wrong attempt, whole or summarized.
Codex’s memories are off by default. If you’ve turned them on, the abandoned chat may have left a note on the wrong approach. Review the memory files under ~/.codex, and use /memories to choose whether the new session uses them.
Now write a fresh task of your own as a rehearsal. Your list-rooms command is committed from the last lesson, so don’t send the task or undo that work. If your run needed the same correction twice, write the task for it. If not, which is normal, write it for the example run. Paste the original task, the correction you’d repeat, and your fresh task for the run you chose:
On an unfinished task, you’d undo the attempt, send the fresh task in a new session, watch its first steps, then review and commit as before.
Move a Repeated Correction Into the Instruction File
A fresh task fixes the list-rooms run, but some corrections aren’t about that command alone. “Every verdict comes from checkRoom()” will matter for the next command that reports on rooms, and a future session has it only if you write it where every session reads it.
That place is the project’s instruction file, loaded at the start of every session. For each repeated correction, ask whether it would apply to a different task in this project. If so, it’s a project rule. If it’s only about this task, such as the new command’s filename, it stays in the task.
Your instruction file probably has rules already, such as never changing files in rooms/. Add the correction, worded for any task:
- Every verdict comes from checkRoom() in
src/check-room.js. Never write a second check of
whether a room can be finished, not even a fallback.
A rule there makes the agent more likely to follow it, but keep checking plans and diffs. Don’t assume a running session has picked up the edit: start a new one, or ask it to reread the file. Open the version for your agent:
Add the rule to the file that holds your other rules: CLAUDE.md, or AGENTS.md if you have no CLAUDE.md or yours only imports it with @AGENTS.md. Don’t create a CLAUDE.md next to an AGENTS.md, because Claude Code would stop reading the AGENTS.md. Commit that file with either git add CLAUDE.md or git add AGENTS.md, followed by git commit -m "Add the checkRoom() rule", then start a new session.
Add the rule to AGENTS.md in your project folder. Commit it with git add AGENTS.md and git commit -m "Add the checkRoom() rule", then start a new session.
Keep each rule to a line or two, because the file takes up room in every session. If you’re unsure whether one of your corrections belongs there, paste it with your instruction file:
Check Your Understanding
Answer these before you open the answers:
- A session on the play-test report has run for an hour. Three times, you’ve written “Tests use the small rooms in test/rooms/. Don’t copy rooms from rooms/ into the tests.” The context was compacted once, and the agent’s new test copies a room from
rooms/again. What do you expect if you correct it a fourth time, and what do you do instead? - You’re writing the fresh task for the example run in this lesson. Which of these go in it? (a) The goal and the done-when. (b) The fallback code from the second attempt, as a warning. (c) “Don’t write any other code that works out whether puzzles can be reached, not even as a fallback.” (d) “Last time you ignored this twice, so pay attention.” (e) Where
checkRoom()lives and what it decides. - In one session, your one correction landed, and the new plan and first edit fit the task. In another, you’re about to send a correction a second time. What do you do in each?
- Expect it may drift again, because the session holds three attempts that copy rooms, and the compacted summary may no longer quote your rule. Undo the last attempt with Git, start a fresh session with a task that states the rule, and add the rule to the instruction file, since every future test task needs it.
- (a), (c), and (e): the task itself, plus what the failed attempt taught. Leave out (b), because the wrong code puts the wrong approach back into the context, and (d), because the new session has no “last time”.
- In the first, keep going and keep watching, because steering is working. In the second, stop correcting. You said it clearly once, and repeating it is unlikely to change what the context pulls toward. Undo the wrong attempt, start a fresh session with a task that carries over what the attempt taught, and put the correction in the instruction file if other tasks need it.
When steering stops working, you can now start a fresh session with a better task, and move a correction you’d otherwise repeat into the instruction file.
Next, in Exercise: Redirect a Wrong Turn, the course’s first coding exercise, you’ll read example sessions from the escape-room builder and decide where you’d step in and whether you’d keep going or start fresh.
The exercise runs in your browser with no agent: write your answers as JavaScript in the editor and click Run Tests. If a test fails, read its message, change your answer, and run again. The Contents tab below the editor explains more, including Full screen.