← All posts

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, and AGENTS.md.txt are invisible to literal matchers — and a git config core.ignorecase mismatch 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.md isn't the project file; .claude/AGENTS.md is 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.md shadows AGENTS.md. This is the #1 surprise. Claude reads CLAUDE.md first; the AGENTS.md fallback fires only when no CLAUDE.md or CLAUDE.local.md exists in the working directory or above. If you wrote rules in AGENTS.md while a three-line CLAUDE.md sits next to it, Claude is reading the wrong file. Fix: delete the stale CLAUDE.md, merge it into AGENTS.md, or set Project instructions to claude-md-and-agents-md so both load — then make sure they don't conflict (Cause 3).
  • Claude Code: version floor. Versions before v2.1.277 cannot read AGENTS.md at all. If claude --version says otherwise, upgrade, or put the rules in CLAUDE.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.md won't influence work happening in src/ui/. Also remember v2 does not fall back to CLAUDE.md — a CLAUDE.md-only project has no instructions in OpenCode, full stop.
  • Codex CLI: one file per directory, then a hard budget. AGENTS.override.md beats AGENTS.md in the same directory (check that an override isn't quietly empty), and concatenated instructions stop at project_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:

  1. One source of truth. Shared rules live in AGENTS.md exactly once; any CLAUDE.md becomes 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.
  2. Purge stale duplicates. Old CLAUDE.local.md, a forgotten AGENTS.override.md, leftover CONTRIBUTING.md in the instructions config — each is a second voice. Check what's actually loaded, not what's supposed to be.
  3. 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 --noEmit instead 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 config lists the configuration sources OpenCode will load — if your file isn't in that output, no amount of restarting helps.

The fix checklist

  1. Fresh session, from the repo root, ask the probe question.
  2. Confirm filename, casing, and tracked status (git ls-files AGENTS.md).
  3. Confirm your version supports the file (Claude ≥ v2.1.277 for AGENTS.md).
  4. Inventory every file that could load: CLAUDE.md, CLAUDE.local.md, AGENTS.override.md, nested AGENTS.md, global user files. Delete or merge the ones you forgot.
  5. Cut the file under ~150 lines; rewrite adjectives as checkable rules.
  6. Add the definition-of-done sentence with your exact commands.
  7. Restart and re-ask the probe. Still wrong → score the file and fix what it flags.
  8. 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.