Topic 1 of 4 · 4 min read
Interrupting and redirecting a running agent
Goal: Pick the moment to interrupt a running agent and write a correction that changes its next step.
Interrupt an agent at the first sign it is heading the wrong way, and give it one short correction that names what to stop, what to do instead and why. Every extra minute on a wrong path adds files to undo and wrong ideas to its context.
Check yourself · 1 of 3
A coding agent starts editing generated migration files that you never want touched. What is the best moment to step in?
Why it matters
A coding agent such as Claude Code, Codex CLI, Cursor or Copilot works in a loop: read, plan, edit, run, repeat. It does not stop to ask whether the loop still fits what you meant. Its own earlier steps stay in context, so a wrong turn at step 3 shapes steps 4 to 30. Cheap early steering beats an expensive cleanup.
How to do it
- Watch the first minutes. The plan, the files it opens and the first command it runs show whether it understood the task. Most drift is visible here.
- Know your two controls. A hard stop (Esc in most terminal agents) halts the current step now. Sending a note while it works usually queues the message, and the agent reads it at its next pause. Use the hard stop when it is about to do something harmful or irreversible. Use a queued note when the direction is fine but a detail is off.
- Stop before the command, not after. If a permission prompt shows a destructive command, deny it and redirect. That is cheaper than any rewind.
- Write the correction in three parts. What to stop, what to do instead, and the reason or constraint. The reason lets it generalise to the next file.
- Repeat, do not argue. If the same correction is needed a third time, the context is polluted. Move to the restart decision in a later topic.
Before and after
Weak: "No, that's wrong, try again." The agent must guess what was wrong, and it keeps its mistaken plan in context.
Better:
Stop. Do not edit the migration files. The schema change belongs in
src/db/schema.ts only; migrations are generated by "npm run db:generate".
Revert your edits under migrations/ and continue from schema.ts.
This names the boundary, the correct place and the cleanup, in four lines.
What goes wrong
- Interrupting too late. You wait for the summary, and by then twelve files changed.
- Interrupting on every small thing. Constant stops break its work and fill the context with corrections. Batch small notes.
- Vague corrections. "Be more careful" changes nothing. Name the file, the command or the rule.
- Correcting the symptom. If it keeps writing to the wrong folder, put the rule in the project instructions file so it holds for the next session.
Examples
A three-part correction
The agent starts rewriting the test runner config to make a failing test pass.
Stop. Do not change jest.config.js. The test fails because parseDate
returns local time, so fix parseDate in src/lib/date.ts and leave the
test as written. Then rerun only that test file.
It names the file to leave alone, the real cause and the verification step.
Hard stop versus queued note
Hard stop: the agent proposes rm -rf build/ node_modules/ .env.local. You deny it and say which files it may delete.
Queued note: the agent is correctly adding a retry to an API client but chose a 30 second delay. You send "use exponential backoff starting at 500 ms" and let it finish the current edit.
Key points
- Interrupt at the first sign of drift; the cost of a wrong path grows with every step the agent takes on it.
- Use a hard stop for harmful or irreversible actions and a queued note for a direction that is fine but needs a detail changed.
- A good correction has three parts: what to stop, what to do instead, and the reason.
- Deny a destructive command at the permission prompt instead of cleaning up afterwards.
- A correction you repeat three times belongs in the project instructions file or signals a polluted session.
Common mistakes
- Waiting for the final summary before checking direction, when the first plan and first commands already showed the drift.
- Replying "that's wrong, try again" without saying what was wrong or what to do instead.
- Interrupting for every style nit, which fills the context with corrections and slows the real work.
- Fixing the same repeated mistake by hand in each session instead of writing the rule in the project instructions file.
Check yourself · 2 of 3
Which correction is most likely to change the agent's next step?
Check yourself · 3 of 3
The agent is about to run a command that deletes a folder you did not mention. What should you do?
Practice items, not counted towards your mastery.
Start here
- Checkpointing (Claude Code docs) (opens in a new tab)DocsFree
Rewind menu, what is tracked, and the stated limits: shell changes and external edits are not restored.
- Review AI code edits (VS Code docs) (opens in a new tab)DocsFree
How an editor-based agent shows edits and lets you keep or undo them one by one.
- Effective harnesses for long-running agents (Anthropic) (opens in a new tab)ArticleFree
Progress files and clean commits that let each new session continue where the last stopped.
More for this topic
- Claude Code overview (opens in a new tab)DocsFree
What a terminal coding agent can do, as background for steering one.