Best for · AI tools
How to prevent AI coding agent mistakes: nine fixes that actually stick
- Last checked
- 3 sources, linked below
- By the vectaai team
We read every plan page. Paid links are labelled. Money never changes a ranking. How we pick.
Verdict Our pick
The bar guide has a call.

- Most AI coding agent mistakes come from two gaps: the agent cannot see something you know (a rule, a deploy step, what "done" means), or it has no way to check its own work.
Compared here
- 01A check the agent can run
- 02Well-scoped tasks with acceptance criteria
- 03AGENTS.md / CLAUDE.md / copilot-instructions.md
- 04Hooks and deny rules
- 05Fresh-eyes review
- 06Rewind and clear
Short answer
Most AI coding agent mistakes come from two gaps: the agent cannot see something you know (a rule, a deploy step, what "done" means), or it has no way to check its own work. Anthropic's Claude Code guide puts the second one bluntly: without a check, "looks done" is all the agent has, and "in practice that makes you the test suite." So the biggest fix is to give it something that comes back pass or fail, a test, a build, a linter, and ask for the output as evidence.
Then: scope the task with clear acceptance criteria (GitHub says its agent does better on "clear, well-scoped tasks" and should stay off production incidents and fuzzy work), write your project rules in an instructions file like AGENTS.md, enforce the rules that can have no exceptions with hooks and deny rules instead of shouting in capitals, have someone who did not write the code review the diff, and when the agent goes wrong twice, start over with a better prompt instead of a third correction. Sources: code.claude.com, docs.github.com and agents.md, read 4 December 2026.
At a glance
| Mistake you see | Usual cause | Fix | Where it is enforced |
|---|---|---|---|
| Says 'done' but it is broken | No check it can run | Tests, build, linter; ask for the output | Prompt, or a Stop hook / CI |
| Builds the wrong thing | Vague task | Name files, symptom, what 'fixed' looks like | Your prompt or issue |
| Repeats the same error each session | Rule lives only in your head | AGENTS.md, CLAUDE.md or copilot-instructions.md | Instructions file |
| Ignores a rule you wrote in capitals | Rule has zero exceptions | Hook or deny rule | The tool, not the model |
| Touches files it should not | Too much access | Deny rules, sandbox, protected folders | Settings |
| Scope creep, refactors unrelated code | No defined end point | Acceptance criteria, review the diff | Review |
| Gets worse after corrections | Context full of failed attempts | Rewind, or clear and re-prompt | Session |
| Subtle bugs slip through | Only the author checked | Fresh-eyes review against the spec | Second reviewer or human |
An AI coding agent is the most productive junior you have ever worked with, and the most confident. It will rewrite six files in a minute, tell you everything passes, and be wrong about one small thing that costs you an afternoon. The fix is not to trust it less. It is to set it up so its mistakes get caught by something other than you.
This guide pulls together what the toolmakers themselves recommend: Anthropic's Claude Code best practices, GitHub's guide for its Copilot coding agent, and the AGENTS.md standard that many agents read. All read on 4 December 2026. These ideas work across tools; the names of the buttons change. We did not run a lab test of agents breaking things. We read the docs and we quote them.
Why agents make mistakes
Anthropic's guide boils it down to a couple of patterns. When a session goes wrong, it is "almost always" one of these:
- The agent built something different from what you had in mind, or rediscovers the same fact every session. It is "missing information it can't get from reading the repo."
- It said it was done and it was not, "usually because it had no way to check its own work."
And there is a third, common in long agent runs: tasks with no clear end point, where the agent keeps going, adds commits, and tidies code nobody asked it to touch.
Every fix below targets one of those three.
1. Give it a check that comes back pass or fail
This is the big one. Anthropic: "Claude stops when the work looks done. If it has nothing to run that tells it whether the work actually is done, 'looks done' is all it has to go on. In practice that makes you the test suite."
The check can be almost anything with a readable result: a test file, a build's exit code, a linter, a script that compares output with a saved example, or a browser screenshot next to the mockup. The guide's tip: if your repo already has one of these, "the single most useful line" in your instructions file is the command that runs it.
Then ask for evidence. "All tests pass" tells you very little. The command it ran and the output tells you a lot, and it is quicker to read than to rerun.
2. Scope the task before the agent starts
GitHub says its agent "provides better results when assigned clear, well-scoped tasks", with "a clear description of the problem" and "complete acceptance criteria on what a good solution looks like."
Anthropic gives a nice before-and-after:
- Instead of "fix the login bug", try: users report login fails after the session times out; look at token refresh in the auth folder, write a failing test that reproduces it, then fix it.
Name the file, describe the symptom, say what "fixed" looks like. If you have the error, the screenshot or the log, hand it over rather than describing it.
3. Pick tasks agents are good at
GitHub is unusually honest here. Good starting tasks: fixing bugs, changing user interface features, improving test coverage. Tasks to keep away from the agent:
- "Production-critical issues" and "incident response".
- "Tasks that require deep domain knowledge" and "tasks that involve substantial business logic".
- "Tasks lacking clear definition", meaning ambiguous or open-ended requirements.
- Tasks where you want to learn and build a deeper understanding yourself.
That last one is a good rule for life, not just code.
4. Write your rules down where the agent reads them
If the agent keeps rediscovering how your project builds, or keeps breaking the same convention, the rule lives only in your head. Put it in a file the agent loads every time:
- AGENTS.md, the open format. Its site calls it "a README for agents" and suggests sections for project overview, build and test commands, code style, testing instructions and security considerations. It lists support in a long line of tools, including OpenAI Codex, Cursor, GitHub Copilot's coding agent, Gemini CLI, VS Code, Windsurf, Zed and more.
- CLAUDE.md for Claude Code.
- .github/copilot-instructions.md for GitHub Copilot, which GitHub says also reads AGENTS.md, CLAUDE.md and GEMINI.md files.
Keep it short. Anthropic's warning: if you keep adding emphasis to a line and the agent still misses it, either the file has grown so long that the line gets lost, or the rule belongs somewhere stricter. Which brings us to the next fix.
5. Enforce the rules that can have no exceptions
This is the idea most people miss. Anthropic splits instructions into two kinds:
- Things the model reads and decides on: your prompt, the instructions file, skills. It "usually follows your commands", but there is "no guarantee".
- Things the tool enforces every time: hooks, deny rules, managed settings. These run "no matter what the model decided to do."
The rule of thumb from the guide: "If something has to happen every time, make it a hook, a deny rule, or a managed setting." Examples: never edit generated code in a certain folder, always run the formatter after a file changes, never read the secrets file. A hook can block edits to a protected folder; a deny rule can stop the agent reading your .env file in every permission mode.
But do not overdo it. Anthropic: "a hook is for a rule with zero exceptions", and if you find yourself with forty of them, "most are probably preferences" the agent could weigh on its own.
6. Limit what it can touch
Related, and worth its own line. An agent with full access to your machine and production credentials is one bad guess away from a very bad day. Use permission rules to block what it never needs, and a sandbox to limit file and network access at the operating-system level where your tool offers one. Anthropic notes that its automatic approval mode is a model making judgment calls, so "your 'never' rules belong in deny rules or hooks." Our AI coding agent security guide covers this in more depth.
7. Make it check its work before it can finish
You can ask nicely ("run the auth tests and keep going until they pass"), and that works for most tasks. For enforcement, Claude Code supports a Stop hook: a script that runs whenever the agent tries to finish, and sends it back to work if the check fails. On GitHub, the same job is done by CI and branch protection: nothing merges until the checks are green.
GitHub adds a practical tip: give its cloud agent a setup file (copilot-setup-steps.yml) that pre-installs your dependencies, so it can actually build and test its own changes. An agent that cannot run your tests cannot pass them.
8. Get a review from fresh eyes
The agent that wrote the code is the worst reviewer of it, because it is still convinced by its own reasoning. Anthropic recommends review by "someone who didn't write the code", for example a review in a fresh sub-session that never saw the conversation, and reviewing against your spec rather than hunting for style nits. Its warning is worth quoting: "A reviewer that's asked to find problems will always find something", so ask for gaps that affect correctness and skip style.
GitHub's version: review the diff on a branch before opening a pull request, and expect that "it's common for the pull request to need further work." When you leave feedback, batch it with "Start a review", because Copilot starts acting on comments as soon as each one lands.
9. Know when to stop correcting and start over
The last fix is about you. Anthropic: "Watch the first minute, press Esc the moment Claude drifts, and after two failed corrections run /clear and write a better prompt instead of a third." A third correction mostly adds to a conversation full of failed attempts that the agent keeps re-reading.
Claude Code also has a rewind menu that rolls the code, the conversation, or both back to an earlier prompt, which makes it cheap to try a bold approach and undo it. Note its limit: checkpoints cover files edited with the agent's own file tools, not changes made by shell commands, so keep using git as your real safety net.
A starter checklist
Before your next agent session:
- One test, build or lint command the agent can run, written in AGENTS.md or your tool's file.
- A task with a named file, a symptom and a definition of done.
- Secrets blocked with a deny rule, protected folders blocked with a hook.
- CI that must pass before merge.
- A review of the diff by someone, or something, that did not write it.
- Permission to yourself to clear and restart after two bad corrections.
Which agent makes the fewest mistakes?
Honestly, the setup matters more than the brand. A well-scoped task with a test to run beats a smarter model working blind. If you are still choosing, our best AI model for coding and Cursor vs Claude Code vs Codex pages compare the options, and Cursor rules vs skills explains how Cursor handles instructions. More on our AI tools hub.
Questions people ask
Why does my AI coding agent say it is done when it is not?
Usually because it had nothing to run that tells it whether the work is done. Anthropic's Claude Code guide says the agent stops when the work looks done. Give it a test, a build exit code or a linter, tell it to keep going until that passes, and ask for the command and its output as evidence.
How do I stop an AI agent from repeating the same mistake?
Write the fix down where the agent reads it every time: an AGENTS.md, CLAUDE.md or .github/copilot-instructions.md file in the repo. Keep it short, with commands, conventions and gotchas. If it keeps ignoring a line that must always apply, turn that line into a hook or a deny rule the tool enforces.
What is AGENTS.md?
AGENTS.md is an open, plain Markdown format described as a README for agents: project overview, build and test commands, code style, testing instructions and security notes. Its site lists support in tools including OpenAI Codex, Cursor, GitHub Copilot's coding agent, Gemini CLI, VS Code, Windsurf and Zed. It is stewarded under the Linux Foundation.
What tasks should I not give an AI coding agent?
GitHub's guide for its Copilot coding agent says to avoid production-critical issues, incident response, tasks needing deep domain knowledge or substantial business logic, and tasks with ambiguous or open-ended requirements. It suggests starting with bug fixes, user interface changes and test coverage, and keeping tasks you want to learn from for yourself.
Should I keep correcting the agent when it goes wrong?
Once or twice, then stop. Anthropic's advice is to press Esc the moment it drifts and, after two failed corrections, clear the session and write a better prompt that includes what you learned. A third correction mostly adds to a conversation already full of failed attempts the agent keeps re-reading.
Can I make an AI agent run tests before it finishes?
Yes. Asking in the prompt works most of the time. To enforce it, Claude Code supports a Stop hook that runs your script when the agent tries to finish and sends it back to work if the check fails. On GitHub, CI and branch protection play the same role before anything merges.
Sources
Every fact above comes from these pages. Prices change, so each one carries the date we read it.
- Claude Code docs: Best practices, checked 4 Dec 2026
- GitHub Docs: Best practices for using GitHub Copilot to work on tasks, checked 4 Dec 2026
- AGENTS.md: a simple, open format for guiding coding agents, checked 4 Dec 2026