deniz.in

Markets

Weather

Loading weather

· via dev.to (home feed)

Conflicting CLAUDE.md files have no winner in Claude Code, unlike Codex and Cursor

A dev.to comparison finds Claude Code concatenates every CLAUDE.md it finds and lets the model pick arbitrarily when rules conflict, while Codex and Cursor define precedence that is only a hint to the model.

Conflicting CLAUDE.md files have no winner in Claude Code, unlike Codex and Cursor

Claude Code concatenates everything and picks arbitrarily

A hands-on comparison published on dev.to spells out a gap that surprises many Claude Code users: the tool has no precedence order at all when instruction files disagree. Everything it finds — managed instructions, the user-level file at ~/.claude/CLAUDE.md, every CLAUDE.md and CLAUDE.local.md from the filesystem root down to the working directory, plus .claude/rules/ — is concatenated into context. Nothing overrides anything. Anthropic's documentation, quoted in the post, states that when two instructions contradict each other "Claude may pick one arbitrarily."

The question originally came from a Claude Code GitHub issue asking how CLAUDE.md discovery works. A maintainer replied that all the files are included at launch, so "you need to take care to not include conflicting instructions." According to the dev.to article, that is still the answer, and the docs now document the details.

AGENTS.md handling adds a wrinkle. By default, Claude Code reads AGENTS.md only when no CLAUDE.md or CLAUDE.local.md exists in the working directory or above it. Create either file and AGENTS.md is skipped entirely, unless you import it or enable the claude-md-and-agents-md mode. A consequence worth noting: a personal CLAUDE.local.md does not "correct" a shared CLAUDE.md — it sits beside it — and it can also silently stop Claude Code from reading AGENTS.md in a repo that relies on it.

Codex and Cursor define a winner

The same comparison finds that both rivals do have an ordering. Codex loads a global ~/.codex/AGENTS.md (or AGENTS.override.md), then one file per directory from the project root to the working directory, up to 32 KiB by default. Because closer files appear later in context, they override earlier guidance; anything past the size cap is not loaded at all.

Cursor merges Team Rules, project rules in .cursor/rules/*.mdc, User Rules, and root plus nested AGENTS.md files. Earlier sources win: Team beats Project beats User, and for nested AGENTS.md files the more specific one wins.

The AGENTS.md convention itself puts it concisely: the closest AGENTS.md to the edited file wins, and explicit chat prompts override everything.

Why "closest wins" is still not a guarantee

Even where precedence exists, the post argues, it is a hint rather than a mechanism. Every tool puts both versions of a rule into one prompt; precedence just means one comes later or is labelled as more specific, and the model still sees both and decides. Claude Code delivers CLAUDE.md as a user message after the system prompt, and Anthropic says there is no guarantee of strict compliance, "especially for vague or conflicting instructions."

Built-in agent guidance can compete with your rules too — your commit conventions may clash with the agent's own defaults, and Claude Code can disable its built-in git instructions via includeGitInstructions so only yours remain. Anthropic also recommends keeping each CLAUDE.md under 200 lines, since longer files reduce adherence and a conflict buried deep in a long file is easy for anyone to miss.

How to remove conflicts instead of hoping

The practical advice from the post:

  • Audit what actually loads. Run /context in Claude Code and read the Memory files list; in Cursor, check which rules are always on versus glob-attached; for Codex, walk the directories from the repo root to where you start it.
  • Give each rule exactly one home. Repo-wide facts go in the root file, package conventions in a nested or path-scoped rule, personal preferences in the user file.
  • Delete rather than override. Narrow a root rule (for example, "use pnpm, except in legacy/, see legacy/AGENTS.md") instead of stacking a contradiction on top.
  • Move must-never-fail rules out of markdown into hooks, linters or CI checks. No precedence order makes prose enforceable.
  • Re-check after big refactors. Claude Code's /doctor prompt-audit (v2.1.283+) reports files that contradict each other, and the post's authors also offer Clogmeter, a free browser-based checker that flags duplicate and conflicting rules along with their token cost.

Why it matters

CLAUDE.md and AGENTS.md files have become the de facto configuration layer for agentic coding, yet their semantics differ sharply between tools. A developer who assumes "nearest file wins" — true in Codex and Cursor, only advisory even there, and false in Claude Code — can have build commands, commit conventions or safety rules silently ignored. The reliable strategy is structural: keep each rule in exactly one place, keep files short, and enforce anything critical outside the prompt.

  • #claude-code
  • #ai-agents
  • #developer-tools
  • #agentic-coding
  • #llm

Related posts