跪拜 Guibai
← All articles
AI Programming · Claude

Who Wins When CLAUDE.md, AGENTS.md, and Skills Clash? 160 Runs Compute the Answer

By ZzT ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

For anyone running both Claude Code and Codex in the same repository, the measured behavior means duplicated rules will silently drift because each tool only loads its own file. And since Claude Code does not define precedence, an unchanging repo can produce different behavior run to run, so anything that must be enforced belongs in hooks or permissions, not in an instruction file.

Summary

Running 27 conflict scenarios 160 times across Claude Code 2.1.330 and Codex 0.171.0, the test pits CLAUDE.md against AGENTS.md, skills, subdirectory rules, and user prompts. The most consistent result: when both CLAUDE.md and AGENTS.md sit in the same directory, each tool reads only its own file; the other never enters context. User instructions in the prompt override both, 5/5 in each tool.

The big divergence appears when skill rules clash with project instructions. Codex followed AGENTS.md in all 25 skill-conflict runs, regardless of how the skill was triggered. Claude Code's outcome depends on the setup: auto-triggered skills lost to CLAUDE.md 10/10, user-invoked skills won 5/5, and the exact configuration from the dev.to post reproduced 9/10 in favor of the skill. Claude Code also showed no fixed precedence between CLAUDE.md and `.claude/rules/`—11 of 15 runs followed rules, 4 followed CLAUDE.md.

Codex introduces a hard size limit: the AGENTS.md chain is truncated at 32 KiB (`project_doc_max_bytes`), so rules at the end of large files never reach the model. Claude Code has no such cap. The practical consequence: if you share a repo across both tools, you can't rely on either reading the other's conventions, and Claude Code's arbitrary conflict resolution means you must eliminate contradictions at the file level.

Takeaways
— When CLAUDE.md and AGENTS.md coexist in the same directory, Claude Code reads only CLAUDE.md and Codex reads only AGENTS.md; the other file never enters context.
— Explicit user instructions in the prompt override both project instruction files, replicating 5/5 in each tool.
— Codex followed AGENTS.md in all 25 skill-conflict runs, whether the skill auto-triggered, was explicitly invoked, or the AGENTS.md declared precedence.
— Claude Code's skill conflicts resolved by scenario: auto-triggered skills lost to CLAUDE.md 10/10, user-invoked skills won 5/5, and the dev.to setup reproduced 9/10 in favor of the skill.
— Claude Code's conflicts between CLAUDE.md and `.claude/rules/` produced 11 rule wins and 4 CLAUDE.md wins across 15 runs, with no documented precedence.
— Codex truncates the combined AGENTS.md chain at 32 KiB (default `project_doc_max_bytes`), so rules at the end of large files are silently ignored; the warning appears only in `codex exec --json`.
— To share conventions across both tools, put them once in AGENTS.md and have CLAUDE.md import it via `@AGENTS.md`; duplicated conventions drift because each tool reads only its own file.
— Claude Code's `/doctor prompt-audit` (v2.1.283+) checks instruction files for contradictions, but it does not resolve them.
Conclusions

The two tools' instruction handling reflects different design philosophies: Codex defines a strict precedence order in its system prompt, while Claude Code deliberately omits one, pushing conflict resolution onto the model—so behavior is not deterministic across runs or wording.

The benchmark's ability to reproduce the dev.to claim only under its exact setup shows how sensitive Claude Code is to instruction phrasing; a single-line CLAUDE.md and a skill description that echoes the prompt shift the outcome.

The 32 KiB truncation in Codex is an easy-to-miss failure mode; teams with large or many AGENTS.md files will silently lose tail rules unless they raise `project_doc_max_bytes`.

Claude Code's explicit admission in documentation that it "may pick one arbitrarily" turned out to be literal: the model gave differing rationales in 10 of 15 rule conflicts, indicating that instruction files are advisory context, not enforced configuration.

Concepts & terms
project_doc_max_bytes
Codex config option that caps the total size of project instruction files (the AGENTS.md chain) injected into context. Defaults to 32 KiB; when exceeded, later files are skipped and the current file is truncated, so rules at the end never reach the model.
InstructionsLoaded hook
A Claude Code hook that fires when instruction files are loaded, allowing developers to log which files were loaded and why. It was used in this benchmark to verify that CLAUDE.md and .claude/rules/ entered context, though AGENTS.md does not trigger this hook.
From the discussion
Featured comments
大脚码农

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.

See top comments, translated →
Source: juejin.cn ↗ Google Translate ↗ Backup ↗