Who Wins When CLAUDE.md, AGENTS.md, and Skills Clash? 160 Runs Compute the Answer
When CLAUDE.md, AGENTS.md, and Skills Conflict, Whose Instructions Win? A Practical Test of Claude Code and Codex Instruction Priority
A single repository now commonly carries five or six sources of instructions: CLAUDE.md, AGENTS.md, personal CLAUDE.local.md, same-named files in subdirectories, .claude/rules/, plus on-demand loaded skills. When they disagree, which one does the agent obey? The two vendors' documentation gives different answers.
Codex's docs define a merge order; Claude Code's docs say all files are concatenated into context and don't override each other, explicitly stating "if two instructions contradict each other, Claude may pick one arbitrarily."
A dev.to post from November 21 reported a test concluding that "a skill I never invoked overruled my CLAUDE.md anyway," running each case once.
This article first compares the loading rules of both tools, then runs 27 sets of conflicts with Claude Code 2.1.330 (Opus 5.5) and Codex 0.171.0 (GPT-6.2 Sol), totaling 160 runs. Main results:
- When CLAUDE.md and AGENTS.md are in the same directory, each tool reads only its own file; the other does not enter context.
- Additional requirements given in the user prompt are followed first by both sides, 5/5 each.
- The biggest divergence appears when skills and project instructions conflict. Codex followed AGENTS.md in all 25 runs; Claude Code depends on the scenario: 10/10 followed CLAUDE.md when the skill auto-triggered, 5/5 followed the skill when the user explicitly invoked it, and 9/10 followed the skill when exactly reproducing that dev.to post's setup.
- When Codex's AGENTS.md total exceeds 32 KiB, it gets truncated; rules written at the end failed to enter context in all 5 runs.
What's more notable in this data is that the two tools' priorities come from different sources. Codex's order is written into its documentation and system prompt: AGENTS.md files merge along the directory chain, injected as user messages, and the system prompt states that skills defer to user instructions. That matches the 25 skill conflicts where the skill never won once.
Claude Code only defines loading; conflicts are left to the model, so results follow the wording. In the same skill vs. CLAUDE.md conflict, when written as a project commit convention, 10/10 followed CLAUDE.md; when swapped to the dev.to post's wording, 9/10 followed the skill. In 15 conflicts between CLAUDE.md and .claude/rules/, 11 followed rules and 4 followed CLAUDE.md.
The conclusion: in Claude Code, there is no reliable precedence among multiple instruction sources; conflicts can only be resolved at the file level. In Codex, precedence is predictable; the caveat is whether rules get loaded at all.
The Two Tools' Loading Rules
Claude Code: All files concatenated into context, conflicts left to the model
At startup, Claude Code walks from the filesystem root to the startup directory, loading every CLAUDE.md and CLAUDE.local.md at each level, plus user-level ~/.claude/CLAUDE.md, ~/.claude/rules/, and .claude/rules/*.md files in the project that don't have a paths field. The docs say "concatenated into context rather than overriding each other," with files closer to the startup directory placed later.
Two other file types load on demand:
- CLAUDE.md in a subdirectory loads when Claude reads or writes files in that directory.
- Rules with a
pathsfield load when Claude encounters a matching file.
AGENTS.md has been directly readable since v2.1.277, but by default it's all-or-nothing: if any of CLAUDE.md, .claude/CLAUDE.md, or CLAUDE.local.md exists in the working directory or above, AGENTS.md is not read.
The docs specifically warn that CLAUDE.local.md counts: adding a CLAUDE.local.md to a repo that depends on AGENTS.md means Claude stops reading AGENTS.md. To read both, set Project instructions to claude-md-and-agents-md in /config.
Skills normally have only name and description in context. After invocation, the SKILL.md body enters the conversation as a message and remains there.
Session logs reveal the different injection methods:
- CLAUDE.md content sits in the first user message's system-reminder, prefixed with "IMPORTANT: These instructions OVERRIDE any default behavior and you MUST follow them exactly as written."
- Skill body arrives as a normal message starting with "Base directory for this skill."
When importing via @AGENTS.md, the docs say "Claude reads the imported file first, then the rest." But in 2.1.330 session logs, the imported AGENTS.md appears as a separate block placed after the CLAUDE.md body.
For conflicts, the docs define no priority; they only recommend periodic cleanup and provide /doctor prompt-audit (since v2.1.283) to check for contradictory files.
Codex: A single chain from root to startup directory
At startup, Codex builds an instruction chain:
- Global: one of
~/.codex/'s AGENTS.override.md or AGENTS.md, whichever exists. - Project: from the project root (usually the Git root) to the startup directory, taking one file per level in order: AGENTS.override.md, AGENTS.md, then any fallback filenames configured in
project_doc_fallback_filenames. - Concatenated from root to current directory. Docs: "Files closer to your current directory override earlier guidance because they appear later in the combined prompt."
- Total size is capped by
project_doc_max_bytes, default 32 KiB; files beyond that are not added.
Once built, the chain doesn't change. Docs: "Codex stops searching once it reaches your current directory"—files in subdirectories below the startup dir are not on the chain. CLAUDE.md is also not read by default.
Skill lists (name, description, path) occupy at most 2% of context by default; only after selecting a skill is its SKILL.md body read.
In rollout session logs, the entire AGENTS.md chain is assembled into one user-role message titled "# AGENTS.md instructions for ". The system prompt's "Using skills" section reads: "The user's instructions take precedence over guidelines provided in a skill."
Experimental Design
Each instruction source writes the same commit convention, differing only in the ticket number. For example, CLAUDE.md requires the first line to start with [CM-101], AGENTS.md with [AG-202]. The task is uniformly "read calc.py first, then write a commit message for the add function"—the ticket number in the first line reveals which source the agent followed.
Configuration:
- Versions and models: Claude Code 2.1.330 + claude-opus-5-5, Codex 0.171.0 + gpt-6.2-sol, both with default reasoning settings, run headless via
claude -pandcodex exec. - Isolation: both sides load no personal config. For Claude Code, only project and local settings sources are enabled,
claudeMdExcludesexcludes instruction files under~/.claude, auto memory is off, MCP not loaded, and Bash, Edit, Write are disabled. NoteclaudeMdExcludesrequires absolute paths; writing~/.claude/**doesn't work, and user-level rules still load. Codex reads no config.toml and no rules, hooks and plugins off, running in a read-only sandbox. - Test repo: created fresh for each run,
git init, placed in a location with no instruction files in any parent directory. - Load evidence: Claude Code uses the project-level InstructionsLoaded hook to log every loaded file and reason; AGENTS.md doesn't trigger this hook, so it's checked from session logs instead. Codex checks the AGENTS.md message text in the rollout.
- Repetitions: 5 runs per condition. Conditions with inconsistent results or opposite to existing conclusions are increased to 10–15 runs.
Claude Code's 90 runs cost roughly $5.40 at API prices, median 11 seconds per run; Codex's 70 runs cost median 19 seconds per run.
Limitations: only one model and default reasoning strength per tool, tasks are single-turn and short, and rules are all the same kind of formatting requirement. Different models, longer sessions, or more complex rules may change results.
Measured Results
Same-directory CLAUDE.md and AGENTS.md: each tool reads its own
With both files present, Claude Code followed CLAUDE.md 5/5; session logs show only CLAUDE.md was injected. In one run the model used Read on AGENTS.md on its own because the attached git status exposed the filename, but it still followed CLAUDE.md.
Swapping to CLAUDE.local.md plus AGENTS.md gave the same: 5/5 followed CLAUDE.local.md, AGENTS.md not injected, and no mention of its being skipped in the session log. With only AGENTS.md, 5/5 followed AGENTS.md.
The officially recommended shared pattern is to put a line @AGENTS.md in CLAUDE.md, with Claude-specific additions below. This test made them conflict:
- Import line at the top and specific convention after: 5/5 followed CLAUDE.md's own rule.
- Specific convention first and import line at the end: also 5/5.
As noted, the imported AGENTS.md actually sits later in context, so this isn't "whatever appears later wins." In the import-at-the-end group, 3 runs explained the choice, all saying "CLAUDE.md is marked as Claude Code-specific."
On Codex side:
- AGENTS.md and CLAUDE.md coexist: 5/5 followed AGENTS.md.
- Only CLAUDE.md: all 5 runs used no ticket number; CLAUDE.md was not read.
- After setting
project_doc_fallback_filenames = ["CLAUDE.md"]: 5/5 followed CLAUDE.md. - AGENTS.override.md and AGENTS.md coexist: 5/5 followed override.
Subdirectory files: Codex only applies them when launched from that subdirectory
When launching from a subdirectory, both tools gave subdirectory files priority, 5/5 each. In Codex's rollout, both root and subdirectory files entered context, with the subdirectory one later.
When launching from the root but the task modifies code in a subdirectory, the two diverged:
- Claude Code: all 5 runs loaded
sub/CLAUDE.mdon demand while readingsub/calc.py; the hook loggednested_traversalas the reason, and 5/5 followed the subdirectory rule. - Codex: rollout shows only root AGENTS.md; 4/5 followed the root. In 2 runs the model itself searched for the subdirectory AGENTS.md (
test -f sub/AGENTS.md,rg --files -g AGENTS.md), and in one of those it followed the subdirectory rule.
Skills vs. project instructions: Codex always follows AGENTS.md; Claude Code depends on wording
Codex followed AGENTS.md in all four skill-conflict groups, 25 runs total:
- Description match, auto-trigger: the model read SKILL.md in all 10 runs, 10/10 followed AGENTS.md.
- AGENTS.md explicitly states "this file takes precedence over any skill": 5/5.
- User explicitly invokes via
$commit-msg: 5/5 followed AGENTS.md. - Exact reproduction of the dev.to post's magic-word setup: 5/5 followed AGENTS.md.
This matches the injection method described earlier: AGENTS.md is a user message, and the system prompt says skills defer to user instructions.
Claude Code's results change with wording:
- Description match, auto-trigger: all 10 runs invoked the skill, 10/10 followed CLAUDE.md, 6 of them explained the conflict at the end. One said verbatim: "I used CLAUDE.md's
[CM-101]because it's marked as a project rule that must be followed." - CLAUDE.md explicitly says it takes precedence over skills: 5/5 followed CLAUDE.md, none mentioned the conflict.
- User invokes via
/commit-msg: 5/5 followed the skill, with the note "this uses the skill invoked for this call." - Exact reproduction of the dev.to post: 9/10 followed the skill.
So the dev.to post's result reproduces under its exact setup but fails under a project-convention style. The two setups differ: that post's skill description was "Use this when asked to state the magic word," nearly matching the question word for word, and its CLAUDE.md had only one line with no project context. In one reproduction run, the model's reason was "it's the more specific instruction for this request."
User prompt: highest priority on both sides
When CLAUDE.md or AGENTS.md contains a ticket number and the prompt also says "this run's ticket number is [UP-505]," both tools followed the prompt 5/5. Codex's system prompt also carries a related line: "The user's instruction, whether implied from the task or explicitly stated, must take precedence over any guidelines provided in skills or external files."
CLAUDE.md vs .claude/rules: equal-level conflict, outcome not fixed
Both CLAUDE.md and .claude/rules/commit.md load at startup; session logs put CLAUDE.md first and rules after. 15 runs: 11 followed rules, 4 followed CLAUDE.md, and 10 explicitly mentioned the conflict.
The runs following rules generally gave the same reason: "that file is dedicated to commit conventions." One added: "that's just my judgment; the conventions don't say which takes priority."
This is exactly what "may pick one arbitrarily" from the docs looks like. Codex has no equivalent mechanism: its rules govern command execution policy, not instruction text.
File size: Codex truncates at 32 KiB
Using the same 36 KB file as both CLAUDE.md and AGENTS.md, with the rule at the end:
- Claude Code: loads fully, 5/5 followed the rule.
- Codex: the project instruction in the rollout truncated at 32 KiB, the last line stopping mid-sentence, the tail rule never entered context, and none of the 5 runs used the ticket number.
codex exec --json gives the warning: "Loaded only 32768 of 36280 bytes from …/AGENTS.md … Trim your project instructions to fit the budget. If you need to keep them all, increase project_doc_max_bytes."
Another group pushed the root AGENTS.md to 33 KB (rule at the top), put a conflicting rule in subdirectory AGENTS.md, and launched from the subdirectory. The root file truncates, the subdirectory file never loads, and 5/5 followed the root. This time the warning read: "Skipped project instructions … starting at …/sub/AGENTS.md because the 32768-byte budget was exhausted."
In other words, Codex's "closer files take priority" has a precondition: preceding files must not have used up the 32 KiB budget.
Usage Recommendations
Enforce hard constraints with hooks and permissions
Claude Code docs are blunt: "Claude treats CLAUDE.md files and auto memory as context. They aren't enforced configuration." To block an operation, use PreToolUse hooks or permission rules. Codex's counterparts are sandbox, approvals, and rules. Instruction files are only appropriate for writing "how we want the agent to behave" conventions.
When sharing a repo across both tools, write conventions once
Put conventions in AGENTS.md, and let CLAUDE.md contain just @AGENTS.md plus Claude-specific additions. In this test, when those additions conflicted with AGENTS.md, the specific addition won 10/10, so the result is predictable.
Don't write the same convention in both CLAUDE.md and AGENTS.md. Since each tool reads only its own file, updating one side while forgetting the other makes the two tools follow different rules.
For repos that depend on AGENTS.md, don't put personal settings in CLAUDE.local.md; if you must, set Project instructions to claude-md-and-agents-md.
Subdirectory rules depend on launch location
Claude Code loads a subdirectory's CLAUDE.md when it reads files there, regardless of where you launched. Codex only loads the segment from root to startup directory: to make a subdirectory rule effective, launch from that subdirectory, or state in the root AGENTS.md that "code under sub/ follows xxx rule."
Don't put project conventions in skills
Skills are for steps, templates, and scripts, not for repeating project conventions. Once the two disagree, Claude Code's outcome depends on whether the skill is auto-triggered or explicitly invoked, while Codex always follows AGENTS.md.
When a skill's rules genuinely need to override project conventions: Claude Code lets you invoke the skill explicitly; Codex doesn't even honor that—you have to change AGENTS.md.
Control file size and audit conflicts regularly
- Codex: keep the total AGENTS.md chain under 32 KiB. Exceeding it truncates and skips later files; raise
project_doc_max_bytesif truly needed. - Claude Code: no such cap, but the docs suggest "target under 200 lines per CLAUDE.md file."
- Conflicts between CLAUDE.md and
.claude/rules/can be checked with/doctor prompt-audit.
One-off requirements go straight into the prompt
For requirements that only apply to a single task, write them directly in the prompt. Both tools follow them 5/5 with no file changes needed.
Reference Links
- Claude Code docs, How Claude remembers your project: https://code.claude.com/docs/en/memory
- Claude Code docs, Skills: https://code.claude.com/docs/en/skills
- Claude Code docs, Hooks reference (InstructionsLoaded): https://code.claude.com/docs/en/hooks
- Codex docs, Custom instructions with AGENTS.md: https://developers.openai.com/codex/guides/agents-md
- Codex docs, Build skills: https://developers.openai.com/codex/skills
- Enjoy Kumawat, A Skill I Never Invoked Overruled My CLAUDE.md Anyway (2026-11-21): https://dev.to/enjoy_kumawat/a-skill-i-never-invoked-overruled-my-claudemd-anyway-144c
Top 1 from juejin.cn, machine-translated. The original thread is authoritative.
The most valuable conclusion from this set of real-world tests, I think, is that in Claude Code there is no dependable priority — you can only resolve conflicts at the file level. When I implement it myself, I follow this: 1) Agree to write only one file. Put cross-tool general conventions in AGENTS.md, and have CLAUDE.md contain just one line @AGENTS.md plus Claude-specific additions (e.g., hooks, permission preferences). Don't write separate versions on both sides — you'll eventually miss updates. 2) Don't put hard constraints in md and rely on the model's self-discipline; hand them to hooks and permissions. md is just context, not enforced behavior — the docs say this plainly. Things like 'don't modify migration files' or 'must run tests before committing' I implement as hook interceptors. 3) Watch out for the CLAUDE.local.md pitfall. In a repo that depends on AGENTS.md, if you casually add a local file, Claude stops reading AGENTS.md entirely, without any error. Either don't put personal config there, or set Project instructions to read both. 4) Don't let files get too long. Codex has a 32 KiB truncation — rules at the end are as good as absent; Claude Code has no such limit, but I still keep it under 200 lines. Break rules up by paths and trigger them, which is easier to debug than one big file where rules fight each other. One-off requirements can just go directly into the current prompt — both tools prioritize that above everything, more stable than editing files.