Fix
AI Coding Agent Changed Too Much Code
If an AI coding agent changed too much code, stop the run, save the useful diff and restart with a smaller task and file boundary. Don't keep prompting inside a bloated run, because a new focused prompt is usually faster than cleaning up a messy patch. For questions, use Ask mode, which never edits.

On this page
What should you check first?
When a run goes wrong, don't re-prompt and hope. Narrow the problem to one symptom, then make the smallest change that tells you whether you guessed right.
- 1Stop the run and save the current diff.
- 2Check whether the task was too broad or missing files.
- 3Read the failing command, log or review comment out loud.
- 4Start a smaller run with one clear done state.
- 5Run the narrowest check before asking for more changes.
Save the diff before you do anything else. A run that went badly can still contain an edit or two that were right, and if you throw everything away you pay for that work again. The diff is also easier to read than the transcript when you are working out where the run went wrong.
Re-prompting harder almost never works. If the agent misread the task, adding "please be careful" to the same prompt gives it nothing new. New information changes the outcome: the file it never opened, the exact error text instead of your paraphrase, or a boundary tight enough to remove the ambiguity. If the second attempt fails the same way as the first, look at the prompt before you blame the model.
This is covered hands-on in Troubleshooting and Operating Cursor Reliably — 7 short Units, free to read.
What usually caused it?
Most of these failures trace back to a gap the run never closed: the agent missed the context that mattered, the prompt set no boundary, or nothing checked the result before it landed. Name the gap before the next run, because each one needs a different fix. Adding context, for example, does nothing for a run that had no boundary.
The agent did not see the file, error or rule that mattered.
The prompt asked for a result without naming the boundary.
The workflow lacked a test, typecheck or review gate.
How do I get an answer without the agent 'fixing' it for me?
Switch to Ask modeA read-only mode for asking questions about a codebase without changing files; the safe way to explore unfamiliar or legacy code. Press Enter for the full definition., which is read-only. The over-edit can start when you ask Agent modeCursor's full-capability mode: the AI can read the codebase, write and edit files, move them and run terminal commands. Contrast with Ask mode, which is read-only. Press Enter for the full definition. a why question. In one walkthrough, a question about why some clicks were being dropped led Agent mode to add a debounce fix to the handler, even though the existing batching was wanted and only the explanation was needed.
- 1Undo all of the changes you didn't ask for.
- 2Ask the same question again in Ask modeA read-only mode for asking questions about a codebase without changing files; the safe way to explore unfamiliar or legacy code. Press Enter for the full definition.. Press ⇧⇥ to cycle modes, or use the mode picker.
- 3Read the explanation, then decide for yourself whether to make the edit.
In Ask modeA read-only mode for asking questions about a codebase without changing files; the safe way to explore unfamiliar or legacy code. Press Enter for the full definition., the agent answers questions and explores code without making any edits, so it explains the problem instead of making the change it assumes you want.
When you want to understand a bug before you fix it, Ask modeA read-only mode for asking questions about a codebase without changing files; the safe way to explore unfamiliar or legacy code. Press Enter for the full definition. is the guardrail.
How do I get the files back to before the agent started?
Restore a checkpoint. Agent saves checkpoints during a session and creates them automatically before significant changes, and each one captures the state of all modified files. Click a checkpoint in the chat timeline to preview your files at that point, then restore to revert them. You can also use the Restore Checkpoint button on a previous request, or the + button that appears when you hover over a message.
A restore reverts all modified files to that state, with no step where you choose which edits to keep. If a couple of the agent's edits were ones you wanted, copy them somewhere before you restore.
Checkpoints are stored locally and kept separate from Git. Cursor says to use them only for undoing Agent changes and to use Git for permanent version control.
So commit before you start a broad run, even if you throw the commit away later. A commit lives in Git, so it outlasts the session and you can push it when someone else needs it.
Should I patch the messy diff or go back to the plan?
Go back to the plan. That is Cursor's documented answer: when Agent builds something that doesn't match what you wanted, revert the changes, make the plan more specific about what you need, and run it again. Cursor says this is often faster than fixing an in-progress agent and produces cleaner results. Press ⇧⇥ from the chat input to rotate to Plan Mode.
Don't apply that to every task. Cursor also says that for quick changes, or tasks you've done many times before, going straight to Agent modeCursor's full-capability mode: the AI can read the codebase, write and edit files, move them and run terminal commands. Contrast with Ask mode, which is read-only. Press Enter for the full definition. is fine. Replanning a one-line fix costs more time than it saves. Go back to the plan when the task had more than one reasonable shape, because the plan is where that ambiguity gets settled.
For larger changes, Cursor says the hard part is often working out what change should be made, and the implementation can be delegated after that. If the agent carried out a wider task than the one you had in mind, the problem sits in that first step. Plan Mode shows you the agent's reading of the task before it edits anything, so a scope that is too wide shows up while it is still cheap to fix.
Frequently asked questions
Who is this guide for?
Developers whose agent run touched more files than the task needed, or edited code when they only asked a question.
What should I do next?
Save the current diff, then start a smaller run with one clear done state and the narrowest check that proves it.
How do I stop the agent from editing code when I only asked a question?
Use Ask mode instead of Agent mode. Agent mode can treat a why question as a request to fix the underlying issue and edit the code. Ask mode is read-only, so it explains the problem without changing anything. If Agent mode already made edits, undo them and ask again in Ask mode.
How do I undo everything an agent changed in a session?
Restore a checkpoint. Click a checkpoint in the chat timeline to preview your files at that point, then restore it. A restore reverts all modified files, with no way to pick which edits to keep, so copy any edits you want first.
Should I fix a messy agent diff or start over?
Usually start over from the plan. Cursor's guidance is to revert, make the plan more specific and run it again, which is often faster than fixing an in-progress agent. For quick changes or tasks you have done many times, going straight to Agent mode is fine.
Sources & last verified
- Cursor agent best practices
- Cursor Learn: working with agents
- Cursor Learn: context
- Cursor docs: prompting agents
- Cursor Help: Ask mode
- Cursor docs: Plan Mode
- Cursor docs: Agent overview
Cursor ships frequently. Facts verified against primary sources on October 28, 2026.