← All posts

CLAUDE.md vs AGENTS.md: Differences and When to Use Each

CLAUDE.md is Claude Code's native instruction file; AGENTS.md is the open file format that Codex CLI and OpenCode read — and newer Claude Code versions read it too. The two do the same job: put your project's rules in front of the agent before the first prompt. The differences are about who reads which file, how multiple files stack, and what happens as your team and tooling change.

If you only want the short version: start with AGENTS.md, and add a thin CLAUDE.md that imports it if you need Claude-specific instructions. The rest of this post explains why, with the exact loading rules for each runtime.

CLAUDE.md vs AGENTS.md at a glance

CLAUDE.md AGENTS.md
Origin Anthropic, for Claude Code Open standard, started by OpenAI's Codex CLI
Read by Claude Code (always) Codex CLI, OpenCode, and Claude Code v2.1.277+
Typical location ./CLAUDE.md, ./.claude/CLAUDE.md, ~/.claude/CLAUDE.md ./AGENTS.md, nested directories, per-tool global file
Personal variant CLAUDE.local.md (gitignored) Global user file per runtime
Imports @path/to/file, relative, max 4 hops None — content is inlined
Size guidance Under 200 lines per file; files over 4 MiB skipped No spec cap; Codex truncates combined files at 32 KiB
Extra features Managed policy paths, a Project instructions setting that picks precedence Directory layering is the whole mechanism

Both are plain Markdown. Neither is a config format with types or validation — which is exactly why they're easy to maintain and easy to get wrong.

What each tool actually reads (compatibility)

This is where AGENTS.md vs CLAUDE.md stops being philosophical and becomes mechanical:

  • Claude Code reads CLAUDE.md first: the project file, ./.claude/CLAUDE.md, the user-wide ~/.claude/CLAUDE.md, a managed-policy file, and CLAUDE.local.md for your personal, gitignored notes. Since v2.1.277 it also reads AGENTS.md natively — but only when no CLAUDE.md (or CLAUDE.local.md) exists in the working directory or above. A Project instructions setting chooses between claude-md-or-agents-md (default), claude-md-and-agents-md, claude-md, and managed-only.
  • OpenCode (v2) reads AGENTS.md only. The CLAUDE.md fallback from v1 is gone — v2 does not read CLAUDE.md at all. It loads the global file, then every AGENTS.md from the workspace up to the project root, and picks up files below the workspace as the agent reads there.
  • Codex CLI reads AGENTS.md only: ~/.codex/AGENTS.md (with AGENTS.override.md winning where present), then at most one instruction file per directory, concatenated from the project root down to the working directory, stopping at 32 KiB in total.

The compatibility conclusion is blunt: a CLAUDE.md alone never reaches OpenCode or Codex. An AGENTS.md alone reaches all three today. That asymmetry drives every recommendation below.

Instruction hierarchy: how the files stack

Neither tool has a conflict-resolution system — layering order is the hierarchy, and it differs per runtime.

Claude Code loads the deepest chain at launch: ancestor directories from the root down, then your current directory's files on demand. The stack, from broadest to most specific, is managed policy → user ~/.claude/CLAUDE.md → project CLAUDE.md → subdirectory files → CLAUDE.local.md. @imports let one file point at another (relative to the importing file, maximum four hops), which is how a small CLAUDE.md can say @AGENTS.md and stay a pointer instead of a copy.

OpenCode loads global first, then workspace AGENTS.md files up to the root. Nested conflicts are not resolved at all — no precedence rules, no "last one wins." The documented practice is: broad guidance in the global file, scoped guidance in nested files, and no direct contradictions between them.

Codex CLI concatenates root-down with blank lines: global file, then one file per directory (AGENTS.override.md beats AGENTS.md, which beats configured fallback names). Later content lands lower in the combined document — within the 32 KiB budget, or it's cut.

The practical reading: your root file must be self-sufficient and non-overlapping, because all three runtimes will happily load several files at once and hand the model the whole pile.

When to use CLAUDE.md

Choose CLAUDE.md as your only file when:

  • Your team is Claude Code only and you're not planning to switch — Claude's file supports imports and has the richest loading hierarchy, and none of that is wasted.
  • You rely on Claude-specific features — @AGENTS.md-style imports, CLAUDE.local.md for personal notes, managed policies, or the Project instructions setting locking everyone to claude-md.
  • You inherit a large existing CLAUDE.md and have no multi-runtime need right now. It works; don't churn it for the principle.

Just accept the consequence: nothing in that file reaches a teammate who opens the project in Codex or OpenCode.

When to use AGENTS.md

Choose AGENTS.md as your only file when:

  • More than one tool touches the repo — even if it's just contributors using different CLIs. One file, every runtime.
  • You're starting a new project — there's no legacy to honor, and AGENTS.md is the format most likely to be read by whatever you adopt next.
  • You want the simplest possible maintenance story — one file, one diff, no import graph to reason about.

This is our default recommendation, and it's what the generator emits unless you ask otherwise. A full walkthrough of building one is in how to write a good AGENTS.md.

When to use both

The pattern that survives real teams:

markdown
# Project instructions

@AGENTS.md

## Claude Code specific

- Use the `/review` command before handing work back.
- Ask before running `/ship`; it touches the release branch.

CLAUDE.md stays a pointer plus genuine Claude-only notes; AGENTS.md holds every shared rule. Anthropic's docs recommend exactly this for sharing one file across tools, and it degrades gracefully: Claude reads both, Codex and OpenCode read the pointer's target.

Two alternatives, with caveats:

  • Symlink — ln -s AGENTS.md CLAUDE.md works and needs no discipline, but Windows checkouts and some editors handle symlinks poorly, and you can't add Claude-only notes.
  • Duplicate the content — this is how files drift. Two copies of every rule means two places to fix a typo and, eventually, two contradicting commands.

Avoid one more trap: imports don't work in reverse. @CLAUDE.md inside AGENTS.md helps nobody, because OpenCode and Codex don't process @imports at all — an AGENTS.md must contain its own content, full text.

Maintaining both without drift

  1. One source of truth. Every shared rule is written in AGENTS.md exactly once. CLAUDE.md never restates a rule — it points.
  2. Convert instead of rewriting. Paste a CLAUDE.md into the converter to get an AGENTS.md with a report of what changed — @imports get inlined, Claude-specific references flagged for manual review. Reverse direction it offers a pointer-first result.
  3. Keep both files short. Under 200 lines each; Codex's 32 KiB combined cap is the hard ceiling for anything layered.
  4. Test the stack, not the file. In a fresh session of each tool, ask what rules are loaded. Instructions are read at session start — editing the file mid-session changes nothing until you restart. Our troubleshooting guide has the two-minute checklist.
  5. Score them periodically. The checker grades structure, commands, clarity, safety, size, and portability — portability is precisely the axis where CLAUDE.md-only setups fail.

FAQ

Is AGENTS.md replacing CLAUDE.md?

Not inside Claude Code — CLAUDE.md remains the native, fully supported file with the richest feature set. AGENTS.md is replacing the proliferation of per-tool copies: it's the one file that reaches Codex, OpenCode, and current Claude Code alike.

Can Claude Code read AGENTS.md without a CLAUDE.md?

Yes. Since v2.1.277, if no CLAUDE.md or CLAUDE.local.md exists in the working directory or its ancestors, Claude reads AGENTS.md (and .claude/AGENTS.md) instead. You can also set Project instructions to claude-md-and-agents-md to load both files together.

Which should I put in Git — CLAUDE.md, AGENTS.md, or both?

Commit the shared rules: AGENTS.md, and CLAUDE.md too if it exists (it should only hold pointers and Claude-specific notes). Personal preferences belong in CLAUDE.local.md or your runtime's global user file — both are gitignored by convention.

Can I convert CLAUDE.md to AGENTS.md automatically?

Mostly. Content converts as a full copy; @import lines must be inlined (they mean nothing to OpenCode and Codex) and Claude-specific syntax flagged. The converter does this and shows you a change report instead of making you diff by eye.

Bottom line

AGENTS.md is the portability layer; CLAUDE.md is the Claude-native layer. Keep the truth in one file, let the other point at it, and verify with a fresh session rather than trusting that the file "should" load. If you're starting today: write AGENTS.md, generate it from a form if you'd rather not start blank, and score the result before you commit it.