How to stop an AI coding agent from over-engineering
Paste minimal-scope stop-rules, fence allowed files, and reject diffs that invent extras the request never asked for.
Published here · 9 sources · Resume reading
Part 1 of 2 in the Guide the agent series. Part 2 is constraints that keep coding agents small.
To stop an AI coding agent from over-engineering, ask for only the requested change, name the files it may touch, and reject diffs that add files, abstractions, or error handling nobody asked for. Anthropic documents this overengineering for Claude Opus 4.5 and 4.6 [1]. OpenAI's docs favor short AGENTS.md files and small, focused diffs [7] [8].
Paste a minimal-scope stop block
Anthropic's Overeagerness guidance tells the model to make only the changes directly requested: no unrequested features or refactors, no docs for untouched code, no speculative error handling, no helpers for one-time ops, and no design for hypothetical futures. It also asks for cleanup of temporary scripts after the task [1]. For Claude Opus 5, the prompting page separately warns about unrequested steps and says to deliver what was asked, then stop short of actions beyond the request [2]. Read the prompting page for the model you actually run, because the advice differs by model [1] [2].
Put the same idea in the project memory file your tool actually reads (CLAUDE.md or AGENTS.md). Claude Code docs say keep CLAUDE.md short (target under about 200 lines) and path-scoped [5] [6]. Codex docs say a short accurate AGENTS.md beats a long vague one, and that you should add rules after repeated mistakes [7] [9]. Anthropic's 2024-12-19 agents guide still starts with the simplest workable solution before adding complexity [3]. Their 2025-11-26 note on long-running agents says agents tended to try to do too much at once [4].
A generic done definition you can paste (replace the lint line with your repo's real commands):
Done means: (1) only the requested behavior changed, (2) no new files unless required,
(3) project lint/tests for touched paths pass: <paste repo commands>,
(4) if you want extra work, ask in one line and wait.Compare a small diff with a bloated one
This synthetic git demo is not a claim about any vendor model. It only shows how file touch counts look when a one-line edit stays in one file versus when extra modules appear.
Warning: the seed commit needs a Git identity. If git config user.email prints nothing, run git config --global user.email "[email protected]" and git config --global user.name "Your Name" first.
rm -rf /tmp/scope-demo && mkdir /tmp/scope-demo && cd /tmp/scope-demo && git init -q
echo 'def add(a,b): return a+b' > app.py && git add app.py && git commit -q -m seed
echo 'def add(a,b): return a+b # sum' > app.py
git diff --stat
mkdir -p lib/config && echo interface > lib/config/opts.py && echo helper > lib/utils.py
git add -A && git diff --cached --statYou should see a one-file app.py change first, then a staged set that also adds lib/config/opts.py and lib/utils.py. Prefer the first shape unless the request required the extras.
Audit the diff before you merge
Print a reviewer checklist after every agent patch:
python3 - <<'PY'
checks = [
"Did the agent create files not required by the request?",
"Did it add abstractions or config flags nobody asked for?",
"Did it edit files outside the stated paths?",
"Did it add error handling for impossible cases?",
"Did existing project tests/lint run for touched paths?",
]
for i, c in enumerate(checks, 1):
print(f"{i}. {c}")
print("Fail any -> revise before merge.")
PYYou should see five numbered checks, then the fail line. OpenAI's apply_patch guidance already pushes minimal targeted edits; keep that pressure in review and in the prompt [8].
If you still need the definition of the agent loop itself, start with what is an AI agent. For the earlier "workflow before agent" cut, see choose an AI workflow before building an agent and five rules for building an AI agent that works.
Paste the done definition into your AGENTS.md or CLAUDE.md before the next agent task.
Send this to the friend who asked their agent for one fix and got a whole new framework.


Keep this guide
Filed under AI agents, Claude Code
Questions about this guide
Which Claude models does Anthropic call out for overengineering?
The prompting best practices Overeagerness section names Claude Opus 4.5 and Claude Opus 4.6. Check the live page for the model you use; do not assume every later model inherits the same paragraph.
Should I remove all verification to keep diffs small?
No. Opus 5 prompting targets redundant verification and unrequested expansion. Keep the project's real lint and tests for touched paths.
How long should CLAUDE.md or AGENTS.md be?
Claude Code docs target under about 200 lines for CLAUDE.md. OpenAI Codex guidance prefers short accurate AGENTS.md files over long vague rule dumps.
Sources
- Anthropic: Prompting Claude Opus 5, accessed 2026-11-12platform.claude.com
- Anthropic: Building effective agents (2024-12-19)anthropic.com
- Claude Code best practices, accessed 2026-11-12code.claude.com
- Claude Code: CLAUDE.md, accessed 2026-11-12code.claude.com
- OpenAI Codex best practices, accessed 2026-11-12learn.chatgpt.com
- OpenAI: apply_patch guide, accessed 2026-11-12developers.openai.com
- OpenAI: AGENTS.md guide, accessed 2026-11-12learn.chatgpt.com