How to Fix AI Coding Agents Ignoring Your Instructions
When an AI coding agent ignores your instructions, one of five things is wrong: the file isn't where the tool looks, a discovery rule keeps it from loading, a second file contradicts it, the rules are too long or too vague to follow, or the session started before you saved the edit. Almost every report of "my agent doesn't follow AGENTS.md" resolves to one of those five — none of them is "the model is broken."
The fixes are mechanical. Work down this list in order; each check takes under a minute.
The 30-second diagnostic
| Symptom | Most likely cause | Fix |
|---|---|---|
| Agent has no idea the file exists | Wrong location or wrong filename | Cause 1 |
| It knows of the file but not its contents | Discovery rule or stale session | Cause 2 |
| It follows some rules, breaks others | Two loaded files disagree | Cause 3 |
| It follows the first rules, forgets the rest | File too long or rules too vague | Cause 4 |
| It followed the rules yesterday, not today | Session predates your edit | Cause 5 |
The probe question works for every row: start a fresh session and ask, "What project instructions are loaded, and what commands would you run before calling a change done?" Vague answer means the file isn't in context. Confident wrong answer means something else is in context.
Cause 1: the file is not where the tool looks
The most common cause by far — often a file created in the wrong directory, or with the wrong casing.
| Tool | Where it looks |
|---|---|
| Claude Code | ./CLAUDE.md, ./.claude/CLAUDE.md, ~/.claude/CLAUDE.md, CLAUDE.local.md; and since v2.1.277, ./AGENTS.md / ./.claude/AGENTS.md only when no CLAUDE.md exists in the working directory or above |
| OpenCode | AGENTS.md at the project root and in nested directories, plus ~/.config/opencode/AGENTS.md |
| Codex CLI | ~/.codex/AGENTS.md, then at most one AGENTS.md (or AGENTS.override.md) per directory, from the root down to your working directory |
Checklist:
- Start the agent from the repository root, not from a subdirectory. Discovery is anchored to where the session starts — a session opened in
src/may never see the root file's directory tree the way you expect. - Exact name, exact case.
AGENTS.md, all caps.agents.md,Agents.md,AGENTS.MD, andAGENTS.md.txtare invisible to literal matchers — and agit config core.ignorecasemismatch on macOS is a classic way to end up with two differently-cased files in history. - Don't confuse the layers. A file at
~/AGENTS.mdisn't the project file;.claude/AGENTS.mdis Claude-specific, not OpenCode's; Codex won't read anything above the repo except its own global file. - Check it's actually tracked.
git ls-files AGENTS.md— an untracked file works on your machine and vanishes for every teammate and CI runner.
Cause 2: a discovery rule keeps it out
Even in the right place, documented loading rules can keep a file out of context:
- Claude Code: a
CLAUDE.mdshadowsAGENTS.md. This is the #1 surprise. Claude readsCLAUDE.mdfirst; theAGENTS.mdfallback fires only when noCLAUDE.mdorCLAUDE.local.mdexists in the working directory or above. If you wrote rules inAGENTS.mdwhile a three-lineCLAUDE.mdsits next to it, Claude is reading the wrong file. Fix: delete the staleCLAUDE.md, merge it intoAGENTS.md, or set Project instructions toclaude-md-and-agents-mdso both load — then make sure they don't conflict (Cause 3). - Claude Code: version floor. Versions before v2.1.277 cannot read
AGENTS.mdat all. Ifclaude --versionsays otherwise, upgrade, or put the rules inCLAUDE.md. - OpenCode: it loads global → workspace, and nested files below the workspace only once the agent reads into that directory. Rules in
src/billing/AGENTS.mdwon't influence work happening insrc/ui/. Also remember v2 does not fall back toCLAUDE.md— aCLAUDE.md-only project has no instructions in OpenCode, full stop. - Codex CLI: one file per directory, then a hard budget.
AGENTS.override.mdbeatsAGENTS.mdin the same directory (check that an override isn't quietly empty), and concatenated instructions stop atproject_doc_max_bytes— 32 KiB by default, silently truncated. A root file plus several nested ones can eat the whole budget before the file you care about loads. - Timing: instructions load at session start. Ancestors load at launch; subdirectory files load on demand when the agent reads there. Editing the file mid-session changes nothing until the session restarts.
Cause 3: two files contradict each other
All three runtimes will happily load several instruction files at once and hand the model the whole pile. If CLAUDE.md says npm test and AGENTS.md says npm run test:unit, you haven't given the agent two chances to comply — you've given it ambiguity, and it will pick one. Users experience that as "ignoring my instructions."
Signs this is your cause: the agent follows rules you wrote recently but breaks rules you wrote earlier (or vice versa), or behavior differs between tools.
Fixes, best first:
- One source of truth. Shared rules live in
AGENTS.mdexactly once; anyCLAUDE.mdbecomes a pointer (@AGENTS.md) plus Claude-only notes. The converter rebuilds one file from the other and reports every change, so you're not diffing by eye. - Purge stale duplicates. Old
CLAUDE.local.md, a forgottenAGENTS.override.md, leftoverCONTRIBUTING.mdin the instructions config — each is a second voice. Check what's actually loaded, not what's supposed to be. - Mind the layering. Broad rules at the root, scoped rules in nested files, and never two versions of the same rule at different depths: OpenCode does not resolve nested conflicts, Codex just concatenates them.
Cause 4: the file is too long or too vague
"Following instructions" is easier when there are few, checkable ones.
- Size. Codex truncates combined instructions at 32 KiB, silently — you will never see an error. Claude Code skips files over 4 MiB and recommends under 200 lines; past roughly 150 lines, rules start getting skimmed. Cut to session-wide essentials and push area detail into nested files that load only where they apply.
- Vagueness. "Write clean, maintainable code" cannot be followed or violated — it's a vibe. Every rule needs a checkable form:
npm run lint && npx tsc --noEmitinstead of "make sure it passes," "no default exports" instead of "use consistent exports," "query by role in tests" instead of "test properly." - Missing definition of done. The most-skipped line in any file. An explicit "run lint, typecheck, and tests before calling the task done" measurably changes what the agent does before handing work back.
- Contradictory absolutes. "Always validate input" next to "keep handlers thin" leaves the agent guessing who validates. Name the layer.
The checker scores exactly these dimensions — structure, commands, clarity, safety, size, portability — and each finding comes with the concrete rewrite. It's the fastest way to find the line that's costing you compliance.
Cause 5: the session loaded an older version
The unglamorous one: instructions are read when the session starts. You fixed the file; the conversation you're staring at still runs the old copy.
- Restart the session, then re-ask the probe question.
- Watch for on-demand layers. Claude loads subdirectory files when you start working in that directory; OpenCode discovers files below the workspace as the agent reads. "It didn't apply until I asked it to open
src/billing/" is normal behavior, not a bug. - Check for two worktrees / two checkouts. The agent may be running in a clone where your edit never landed.
- Check the tool's own view.
opencode debug configlists the configuration sources OpenCode will load — if your file isn't in that output, no amount of restarting helps.
The fix checklist
- Fresh session, from the repo root, ask the probe question.
- Confirm filename, casing, and tracked status (
git ls-files AGENTS.md). - Confirm your version supports the file (Claude ≥ v2.1.277 for
AGENTS.md). - Inventory every file that could load:
CLAUDE.md,CLAUDE.local.md,AGENTS.override.md, nestedAGENTS.md, global user files. Delete or merge the ones you forgot. - Cut the file under ~150 lines; rewrite adjectives as checkable rules.
- Add the definition-of-done sentence with your exact commands.
- Restart and re-ask the probe. Still wrong → score the file and fix what it flags.
- Repeat the probe in each tool you use — compliance is per-runtime.
FAQ
Why does Claude Code ignore my AGENTS.md?
Either your Claude Code is older than v2.1.277 (that version introduced AGENTS.md support), or a CLAUDE.md / CLAUDE.local.md exists in the working directory or above — in which case Claude reads that instead, by design. Merge, delete it, or set Project instructions to claude-md-and-agents-md.
Why does my agent follow AGENTS.md in one tool but not another?
Each runtime has its own discovery rules: OpenCode v2 reads AGENTS.md only (never CLAUDE.md), Codex layers one file per directory with a 32 KiB total cap, Claude prioritizes CLAUDE.md. A file that satisfies one doesn't guarantee the others — compare the locations table in Cause 1 against each tool.
Does where I put AGENTS.md matter?
Yes: root of the repository, next to package.json. Subdirectory files are a layer, not a replacement — the root file is what every session loads regardless of which directory you work in.
Why does the agent follow instructions at the start but drop them later?
Two usual reasons: the conversation has grown past the point where the model attends to a very long file — cut it below ~150 lines — or rules are phrased once instead of tied to a trigger ("before you run migrations, always…"). Instructions phrased as when-then rules near the action hold up better than rules stated once at the top.
Bottom line
Read your instruction file the way your agent does: it either loaded, or it didn't; it's either unambiguous, or it isn't. Verify discovery first, resolve conflicts second, shrink and sharpen third — in that order, because each fix assumes the one before it. If you'd rather rebuild than debug, generate a fresh, correctly structured file from a short form — and keep the checker bookmarked for the next time compliance slips.