AGENTS.md vs CLAUDE.md conflicts: one multi-tool repo in five contradicts itself, and how to check yours
Under default loading rules Claude Code and Codex each read their own file, so a contradiction lands between two people's sessions; the usual import puts both lines in one context with no rule for which wins. A study of 128 public repositories puts the rate near one in five, and each detector it tested found at most one of 23 held-out conflicts.
Contents
In one repository a CLAUDE.md forbids running the test script as uv run python test.py, and the same project’s Cursor rules give exactly that command as the example of how to run it. Read one at a time, both look like careful instructions. Two developers on different assistants can still get opposite advice for the same task.
That case is from Context Clash, a paper posted on November 30 and accepted at ACM SAC 2027, which estimates how often this happens on a probability sample of repositories: about one in five of those that keep files for two or more tools. The paper counts files. Where a conflict lands depends on loading rules. With Claude Code and Codex defaults, each tool reads its own file, so the contradiction sits between two people’s sessions. Add the @AGENTS.md import I recommended in September and both lines sit in one context, where nothing says which one wins. The three lightweight detectors the study tried found almost none of these conflicts, so the check is a read. Below is that read, cut down to a few commands and one script.
What did the Context Clash paper measure about AGENTS.md and CLAUDE.md?
Written conflicts between instruction files for different coding tools in the same repository. The design-weighted estimate is 20.83%: about one eligible repository in five has at least one.
“Eligible” is a narrow word here. The frame is active public GitHub projects in a frozen research dataset, and a repository counts only if it has readable, non-empty English instruction files for at least two tools: root AGENTS.md, CLAUDE.md (or .claude/CLAUDE.md), GEMINI.md (or .gemini/GEMINI.md), .github/copilot-instructions.md or .cursorrules. 516 repositories qualified; after three feasibility-check repositories were set aside, the study drew a stratified probability sample of 128 from the remaining 513, and two people read all 241 file pairs in them. The final count is 38 conflicting pairs in 28 repositories.
The definition is strict, which is what makes the number usable. A conflict needs the same subject, overlapping scope, and rules that “a competent agent cannot satisfy both.” A Claude-only section about Claude Code hooks has nothing to conflict with. Two files that give different commands for the same test suite may.
Across the five common tool pairs the estimates run from 9.66% (AGENTS.md and Cursor) to 21.77% (AGENTS.md and CLAUDE.md), with intervals wide enough that the paper says they give “little basis for ranking tool combinations.”
What do AGENTS.md and CLAUDE.md conflicts look like?
Commands and toolchains most often: 16 of 58 type mentions across the 38 conflicting pairs. Then style or APIs (11), polarity, where one file forbids what the other prescribes (8), where code belongs (7), versions and dependencies (6), validation and release (5), other (4), and permissions (1).
The paper’s Table 5 shows the shapes, shortened by the author:
Polarity "NEVER use: uv run python test.py" vs. the same command marked correct with "NO EXCEPTIONS"Validation "Docs-only … none by default" vs. "Run tests after changes: Always run the project's test suite"Toolchain "Run with yarn test-e2e" vs. "make test-e2e" for the same browser suiteToolchain Backend testing uses xUnit vs. "Write backend tests using TUnit with [Test] attributes"
None of these is subtle once both lines are on one screen. Three exploratory associations fit the picture of copies drifting apart, without proving it: longer files go with more conflicts (odds ratio 2.38 per standard deviation of log file length), so do more configured tools (1.87, “partly mechanical,” since every added tool adds file pairs), and so do lopsided commit counts between the files (1.35). The paper is explicit that a snapshot “cannot establish when or why the files diverged.”
Does an AGENTS.md vs CLAUDE.md conflict matter if each tool reads only one file?
Yes. The paper’s construct section puts it directly: “A team can receive conflicting guidance across assistants even when each assistant reads a single file.” With default settings, that is how Claude Code and Codex behave at the project root.
Claude Code’s default Project instructions setting, claude-md-or-agents-md, reads AGENTS.md only when there is no CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md in the working directory or above it. A repository with both root files gets CLAUDE.md alone, as I went through in Claude Code now reads AGENTS.md, and the default is a fallback. Codex walks from the project root down to the current directory, takes at most one of AGENTS.override.md, AGENTS.md or a configured fallback name per directory, and ignores names that are not on that list. So in a repo with an outdated CLAUDE.md and a current AGENTS.md, a Claude Code session is given the outdated commands and a Codex session the current ones, and neither sees the other file. That holds with no import, no override file and no setting changed. The paper did not observe which command anyone ran, or which files a session loaded; it measured the files present.
Making one tool read both files moves the conflict rather than removing it. With an @AGENTS.md import at the top of CLAUDE.md, or the claude-md-and-agents-md setting, both texts land in one context, and Anthropic’s docs say that when two rules contradict, Claude may pick either. Copilot’s cloud agent on GitHub.com can likewise combine repository-wide and path-specific instructions and read the nearest AGENTS.md. Either way the outcome is set by something you did not choose: which file exists on disk, or which of two contradicting lines the model picks. The paper names the missing piece in its advice to vendors: “Tool vendors can reduce replication by supporting explicit imports, precedence, and provenance.” Claude Code has the first. Precedence between two project files is what the September post found missing.
How do you find every AGENTS.md, CLAUDE.md and rules file in a repository?
List them from git: tracked, untracked, and the ones git ignores, because a personal CLAUDE.local.md is usually gitignored and still changes what one developer’s Claude Code loads.
On the throwaway repository it listed eight files, among them AGENTS.override.md, a .claude/rules/ file, a nested packages/My App/AGENTS.md and .cursor/rules/testing.mdc, and under the ignored heading the CLAUDE.local.md. Treat it as a starting inventory: a Codex fallback name or a Gemini context filename you configured yourself is not in the pattern. The nested and ignored files are the ones a root-level look misses. Codex picks up a nested AGENTS.md when you start it in that directory or below, and the Claude Code default stops discovering AGENTS.md once a CLAUDE.md exists in the working directory or above it.
Tools now write these files too. In Next.js 16.4.6, next dev adds a managed block to the project’s AGENTS.md, creating the file if needed, when it detects an AI coding agent. The agentRules option defaults to true, and the block tells the agent to read the docs bundled in node_modules/next/dist/docs/ before writing code. It is a reasonable instruction, but it is one more voice in a file you may think of as yours, and it reaches a Claude Code session only through the import, the both-files setting, a symlink, or the fallback conditions above (no CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md in the way). Setting agentRules: false does more than stop future writes: on the next next dev it removes the block, and deletes AGENTS.md if nothing else was in it.
How do you list the commands each AGENTS.md and CLAUDE.md gives?
Extract what conflicts most often (commands, tool and version names, and lines with never, always or must) and print it side by side. This script does only that. It decides nothing:
python
#!/usr/bin/env python3"""List what instruction files say about commands, versions and modal rules, side by side.Prints candidates for a human to read. It does not decide what is a conflict."""import re, sysfrom pathlib import PathTOOLS = r"(?:npm|npx|pnpm|yarn|bun|node|make|bash|python3?|uv|pip|poetry|pytest|tox|cargo|go|dotnet|mvn|gradle|\./gradlew|docker|ruff|eslint|prettier|tsc)" # extend for your stackCMD = re.compile(rf"^\s*(?:\$\s*)?({TOOLS}\b[^\n`]*)")INLINE = re.compile(r"`([^`\n]+)`")RUNTIME = re.compile(r"(?<![\w.])(node(?:\.js)?|python|go|java|ruby|rust|\.net)[ v]*(\d+(?:\.\d+)*)", re.I)FRAMEWORK = re.compile(r"\b(xunit|tunit|nunit|jest|vitest|mocha|pytest|unittest|playwright|cypress)\b", re.I)NEGATIVE = re.compile(r"\b(never|do not|don['’]t|avoid)\b", re.I)MODAL = re.compile(r"\b(never|always|must|do not|don['’]t)\b", re.I)TOPICS = ["e2e", "test", "lint", "format", "build", "dev", "install", "deploy", "migrat"]def facts(text): cmds, versions, modals = set(), set(), [] in_fence = False for n, line in enumerate(text.splitlines(), 1): if line.strip().startswith("```"): in_fence = not in_fence continue spans = [line] if in_fence else INLINE.findall(line) for s in spans: m = CMD.match(s) if m: clause = re.split(r"[;.]", line.split(s)[0])[-1] # text before the command, same clause neg = not in_fence and NEGATIVE.search(clause) cmds.add(m.group(1).strip() + (" (on a never/do-not line)" if neg else "")) for name, ver in RUNTIME.findall(line): versions.add(f"{name.lower()} {ver}") for name in FRAMEWORK.findall(line): versions.add(name.lower()) if not in_fence and MODAL.search(line): modals.append(f"{n}: {line.strip()}") return cmds, versions, modalsdef topic(cmd): return next((t for t in TOPICS if t in cmd.lower()), "other")files = [Path(p) for p in sys.argv[1:]]missing = [str(f) for f in files if not f.is_file()]if missing: print(f"not a file, skipped: {missing}")files = [f for f in files if f.is_file()]if len(files) < 2: print(f"only {len(files)} instruction file(s), nothing to compare") sys.exit(0)data = {f: facts(f.read_text(encoding="utf-8", errors="replace")) for f in files}print("== commands by topic (a topic with different commands is worth reading) ==")for t in TOPICS + ["other"]: per = {f: sorted(c for c in data[f][0] if topic(c) == t) for f in files} if sum(bool(v) for v in per.values()) < 2: continue flag = "DIFFERS" if len({tuple(v) for v in per.values() if v}) > 1 else "same" print(f"[{t}] {flag}") for f, v in per.items(): print(f" {f}: {v or '-'}")print("== tool and version mentions ==")for f in files: print(f" {f}: {sorted(data[f][1]) or '-'}")print("== modal lines (never/always/must/do not) ==")for f in files: for line in data[f][2]: print(f" {f}:{line}")
Save it as scripts/instr_diff.py and pass it two or more files. On the throwaway repository, whose AGENTS.md and CLAUDE.md carry four candidate pairs adapted from Table 5, it printed:
$ python3 scripts/instr_diff.py AGENTS.md CLAUDE.md== commands by topic (a topic with different commands is worth reading) ==[e2e] DIFFERS AGENTS.md: ['yarn test-e2e'] CLAUDE.md: ['make test-e2e'][test] DIFFERS AGENTS.md: ['uv run pytest -q'] CLAUDE.md: ['pytest -q', 'uv run pytest (on a never/do-not line)']== tool and version mentions == AGENTS.md: ['pytest', 'xunit'] CLAUDE.md: ['pytest', 'python 3.12', 'tunit']== modal lines (never/always/must/do not) == AGENTS.md:9: - Docs-only changes: do not run the test suite. CLAUDE.md:4: - NEVER use `uv run pytest`; activate the venv and call `pytest -q`. CLAUDE.md:7: - Run tests after changes: always run the project's test suite.
The e2e commands, the forbidden uv run and xUnit against TUnit show up as differences. The validation conflict does not: both lines appear under modal lines, but nothing pairs “do not run the test suite” for docs-only changes with “always run” after any change. You see it only by reading the two lines together. The script has other blind spots worth knowing before you trust its silence. It reads commands only from backticks and fenced blocks, so a command written as plain prose is invisible; a topic only one file mentions is not printed, which is why CLAUDE.md’s ruff format never appears; nested files are pooled with root files regardless of scope; and the polarity marker is a guess from the words before a command in the same clause. On a long real file, expect the modal section to run to many lines. Read its output as a list of places to look, then read both files in full anyway.
How do you decide whether AGENTS.md and CLAUDE.md conflict?
Name one concrete task both rules cover, then ask whether an agent could obey both on that task. If it cannot, it is a conflict. If the scopes are disjoint and no task falls under both, it is tool-specific guidance and stays.
yarn test-e2e in AGENTS.md and make test-e2e in CLAUDE.md conflict only if they describe the same suite and one excludes the other; if the Makefile target wraps the yarn script, they are two spellings of one action, and picking one spelling is tidying, not a fix. Different scopes can still overlap: a repository-wide “always run the tests” and a docs-only “do not run the tests” both cover a documentation change, and on that task they cannot both hold. The paper’s wording of the original pair, “none by default”, is softer, and an agent could satisfy both by running the tests anyway. That is the kind of line where the paper needed two readers and an adjudication. The test is the operational version of the distinction I drew in August between fragmentation and layering: the same question answered twice is a candidate conflict, different questions at different scopes are not.
For ordering a large review the paper has one encouraging number. An off-the-shelf NLI model scored shortlisted pairs of extracted statements, and the 37 highest-ranked of the 149 held-out file pairs contained 13 of the 23 held-out conflicts. That was found post hoc on a small test set; the paper calls it support for “triage but not automatic warnings.” It also leaves open whether an LLM judge given both whole files does better, because it never ran one. If you try one, count what it misses, not only what it finds.
How do you fix an AGENTS.md and CLAUDE.md conflict?
Pick one file as the source for shared rules, delete the duplicates from the others, and keep only tool-specific lines in the tool files. The paper’s wording for the maintenance side:
keep shared policy in one canonical source, generate thin tool-specificadapters where formats permit, assign ownership for the remaining copies,and review all affected views in the same pull request.
For Claude Code and Codex the thin adapter is a CLAUDE.md whose first line is @AGENTS.md, with Claude-only lines below it. I recommended that import in September for loading reasons. On its own it does not fix a conflict: with the import in place and the old commands still in CLAUDE.md, Claude Code gets both. The fix is the deletion the import makes possible. Once AGENTS.md loads through the import, every shared command left in CLAUDE.md is a duplicate and can go. A symlink from CLAUDE.md to AGENTS.md also works when there is nothing Claude-specific to keep, though Anthropic’s docs suggest the import on Windows. Each nested AGENTS.md from the inventory needs its own import next to it, or the both-files setting, which Claude Code accepts only in user settings, a --settings file or managed policy.
Commands meant to be identical for every tool belong in the shared file only. A command that really differs by tool, such as a setup step one client needs, stays in that tool’s file with a line saying why. For any client in your setup that still needs its own copy, name an owner and change all of them in the same pull request.
Should a CI check block commits when AGENTS.md and CLAUDE.md disagree?
No. Flag the change and let a person read it. Each of the study’s three screeners, at its frozen cutoff, found at most one of 23 held-out conflicts, and none had reached the 0.80 precision target on development data. The paper’s conclusion: “little basis for letting a screener block commits or rewrite files automatically.” What it suggests instead is a CI check that flags “changed commands, versions, paths, and modal language for review without declaring them conflicts.”
This version runs the listing when a pull request touches an instruction file, and never fails the build:
shell
#!/usr/bin/env bash# Advisory: lists what the instruction files say when a PR changes one. Never fails the build.# Needs bash 4.4+, GNU grep, full history (e.g. fetch-depth: 0) and BASE set to the target branch ref.PATTERN='(^|/)(AGENTS(\.override)?|CLAUDE|GEMINI)\.md$|(^|/)\.claude/rules/|(^|/)\.github/copilot-instructions\.md$|(^|/)\.github/instructions/.*\.instructions\.md$|(^|/)\.cursorrules$|(^|/)\.cursor/rules/'if [ -z "${BASE:-}" ] || ! git merge-base "$BASE" HEAD >/dev/null 2>&1; then echo "instruction-file check: no usable BASE ('${BASE:-}'), nothing inspected"; exit 0fiif ! diff=$(git -c core.quotePath=false diff --no-renames --name-only "$BASE"...HEAD); then echo "instruction-file check: git diff failed, nothing inspected"; exit 0fichanged=$(printf '%s\n' "$diff" | grep -iE "$PATTERN" || true)[ -z "$changed" ] && exit 0echo "Instruction files changed in this PR:"; echo "$changed"echo "Command candidates in the current instruction files:"mapfile -d '' files < <(git ls-files -z | grep -zE -i "$PATTERN" || true)python3 scripts/instr_diff.py "${files[@]}" || echo "instr_diff failed; read the files by hand"exit 0
I ran it under bash -eo pipefail, the way GitHub Actions runs a bash step, on a branch of the throwaway repository that changed .cursor/rules/testing.mdc and the AGENTS.md in a folder with a space in its name: it listed the changed files, then the comparison, and exited 0. On a branch that renamed AGENTS.md away it still fired, because --no-renames reports the old path; on a branch that touched no instruction file it printed nothing; with BASE empty or pointing at a ref that does not exist it said it inspected nothing instead of passing silently. It needs bash 4.4 or later for mapfile -d (I ran bash 5.2). On a clean CI checkout it compares the tracked files that match the pattern, so a gitignored CLAUDE.local.md is out of its reach by design. Where the output goes is up to your CI: the job log is enough if reviewers read it, a PR comment if they do not. It gives no verdict. Its use is that whoever changed one copy sees what the others say in the same pull request.
What can’t the Context Clash study tell you about AGENTS.md conflicts?
Whether a conflict changes what an agent does. The study measures “incompatible written rules” in a snapshot and says it “cannot establish which files a developer’s session loaded.” How often a written contradiction flips a command in practice is not measured.
The estimate has the usual sampling uncertainty: a 95% interval of 12.87% to 29.44%, with a one-sided lower bound of 14.01%, above the 10% threshold the study set in advance. The two readers agreed on 89.63% of pairs before adjudication (Cohen’s kappa 0.629). One of the two readers was the paper’s sole author, who also resolved the 25 disagreements. As a sensitivity check, each reader’s own labels give 17.30% and 21.88%, and the lower bound stays above 10% under either. The frame is public GitHub; private repositories, monorepos and configuration outside the repo “may have different rates.” And the detector results rest on too few positives to rank the methods. The inventory command and the read do not depend on any of these numbers.
01 / Discussion
No comment section here — all discussions happen on X.