Skip to content

CLAUDE.md and AGENTS.md: where each is read and how to keep one copy

On this page

CLAUDE.md is the instruction file Claude Code loads at the start of every session. AGENTS.md is the open format that Codex, Cursor, Gemini CLI, GitHub Copilot’s coding agent and many other agents read for the same purpose. Claude Code now reads AGENTS.md too, but only when the repository has no CLAUDE.md, so most projects can keep one AGENTS.md and add a two-line CLAUDE.md that imports it when Claude needs something extra.

Checked as of November 2026 against the Claude Code memory documentation, agents.md and OpenAI’s Codex AGENTS.md guide.

CLAUDE.md vs AGENTS.md at a glance

CLAUDE.mdAGENTS.md
Read byClaude CodeCodex, Cursor, Copilot’s coding agent, Jules, Zed, Warp, Devin and others; Claude Code when no CLAUDE.md exists
Personal file for all projects~/.claude/CLAUDE.mdCodex: ~/.codex/AGENTS.md
Uncommitted personal fileCLAUDE.local.mdNo standard equivalent
Nested directoriesSubdirectory files load when Claude works in that directorySupported; the closest file to the edited code wins
Imports@path/to/file, up to four hopsNot part of the format
Size guidanceUnder 200 lines per fileCodex stops adding files at 32 KiB combined by default

Where Claude Code reads CLAUDE.md from

Claude Code looks in four places, loaded from broadest to most specific:

ScopeLocationShared with
Managed policy/Library/Application Support/ClaudeCode/CLAUDE.md (macOS), /etc/claude-code/CLAUDE.md (Linux and WSL), C:\Program Files\ClaudeCode\CLAUDE.md (Windows)Everyone on the machine
User~/.claude/CLAUDE.mdYou, in every project
Project./CLAUDE.md or ./.claude/CLAUDE.mdThe team, through Git
Local./CLAUDE.local.md (add it to .gitignore)You, in this project

Files don’t override each other. Claude Code concatenates everything it finds in the working directory and every directory above it, ordered from the filesystem root down, so the instructions closest to where you launched are read last. Within a directory, CLAUDE.local.md comes after CLAUDE.md.

Files in subdirectories below the working directory load on demand: a packages/api/CLAUDE.md enters context once Claude reads, writes or edits a file under packages/api/. In a monorepo where other teams’ files get picked up, the claudeMdExcludes setting skips them by glob. To see what actually loaded, run /context all and check Memory files.

Block-level HTML comments in a CLAUDE.md are stripped before the content reaches the model, which makes them a free place for maintainer notes.

Imports with @

A CLAUDE.md can pull in other files with @path anywhere in the text:

markdown
See @README.md for the project overview and @package.json for scripts.

## Git workflow
- Branching and release rules: @docs/git-instructions.md

Relative paths resolve from the file that contains the import, not from the working directory, and imports can nest four hops deep. A path wrapped in backticks stays literal. The first time a project file imports something outside the working directory, such as @~/.claude/my-notes.md, Claude Code asks you to approve it.

Imports organize a long file; they don’t shrink it. The memory docs are explicit that imported files load together with the CLAUDE.md that references them, so they cost the same context.

What AGENTS.md is and which tools read it

AGENTS.md describes itself as a README for agents: plain Markdown with no required fields, holding the build steps, tests and conventions an agent needs. It came out of OpenAI Codex, Amp, Google’s Jules, Cursor and Factory, and is now stewarded by the Agentic AI Foundation under the Linux Foundation. The site lists Codex, Cursor, VS Code, Gemini CLI, Copilot’s coding agent, Zed, Warp, Devin, Junie, Windsurf, Aider and goose among the tools that use it.

Support differs in the details:

  • Codex builds an instruction chain at startup. It reads ~/.codex/AGENTS.md (or AGENTS.override.md), then walks from the Git root down to the working directory, taking at most one file per directory and preferring AGENTS.override.md over AGENTS.md. Files are concatenated root first, and it stops adding them once the total reaches project_doc_max_bytes, 32 KiB by default.
  • Cursor reads AGENTS.md in the project root and in subdirectories, applying nested files to work in that directory, with the more specific file taking precedence. It has no frontmatter, so it can’t be scoped by glob the way .cursor/rules/*.mdc files can.
  • Gemini CLI and Aider need a setting: "context": { "fileName": "AGENTS.md" } in .gemini/settings.json, or read: AGENTS.md in .aider.conf.yml, per the agents.md FAQ.

The agents.md rule for conflicts is short: the closest AGENTS.md to the edited file wins, and explicit chat prompts override everything.

Does Claude Code read AGENTS.md

Yes, since Claude Code v2.1.277, through a built-in plugin. The default behavior depends on what else is in the repository:

Your repository hasClaude Code reads
AGENTS.md, and no CLAUDE.md or CLAUDE.local.md in the working directory or aboveAGENTS.md
AGENTS.md and a CLAUDE.md or CLAUDE.local.mdCLAUDE.md files only
A CLAUDE.md that imports AGENTS.mdCLAUDE.md, with AGENTS.md included through the import

Your ~/.claude/CLAUDE.md, the managed CLAUDE.md and .claude/rules/ files don’t count for that check; they load alongside AGENTS.md. A CLAUDE.local.md does count, which catches people out: adding one for your own notes silently stops Claude reading the shared AGENTS.md. To change the default, open /config and set Project instructions to claude-md-and-agents-md (both, CLAUDE.md first in each directory), claude-md, or managed-only.

Claude Code doesn’t read AGENTS.override.md, AGENTS.local.md or anything under .agents/. Older versions, and sessions where the built-in plugin is disabled, read CLAUDE.md only.

Keep one source of truth

Pick one of these and stick to it.

AGENTS.md only

If nobody needs Claude-specific instructions and everyone runs a current Claude Code, a single AGENTS.md is enough. In an interactive session Claude Code prints a line such as no CLAUDE.md found; AGENTS.md loaded when it picks the file up.

A CLAUDE.md that imports AGENTS.md

This works on every version and leaves room for Claude-only lines. Claude reads the imported file first, then the rest:

markdown
@AGENTS.md

## Claude Code
Use plan mode for changes under `src/billing/`.

Keeping the import never loads AGENTS.md twice, whichever Project instructions value is set.

If there’s nothing Claude-specific:

Shell
ln -s AGENTS.md CLAUDE.md

Two caveats from the docs. Claude’s Edit and Write tools refuse to write through a symlink and point Claude at AGENTS.md instead. And on Windows, Git checks a committed symlink out as a one-line text file unless core.symlinks is enabled, so a teammate on Windows gets a CLAUDE.md that contains only the path. Use the import there.

Codex reading CLAUDE.md

If the repository already has a good CLAUDE.md and you want Codex to read it, Codex can treat it as a fallback name:

TOML
# ~/.codex/config.toml
project_doc_fallback_filenames = ["CLAUDE.md"]

Codex checks fallbacks only when a directory has no AGENTS.md, and the setting is per user, so every Codex user on the team needs it. Renaming to AGENTS.md is usually simpler.

What belongs in the file

Anthropic’s best practices give a two-question test before writing anything down: could the agent find this by reading the code, and would it actually go and look? If both answers are yes, leave it out. What survives tends to be:

  • Commands, exactly as typed. The test command for one package, the lint fix command, how to run the dev server, which ones need a database.
  • Conventions the code doesn’t show. “New endpoints go in src/api/handlers/”, “use the Result type, not exceptions, in core/”.
  • Boundaries. Directories that are generated, files nobody should edit by hand, changes that need a human first.
  • Decisions made outside the repository. Why a dependency is pinned, which service is being retired.

A working example:

markdown
# Agent instructions

## Commands
- Install: `pnpm install`
- Test one package: `pnpm --filter @acme/api test`
- Lint and fix: `pnpm lint --fix`
- Integration tests need `DATABASE_URL`; use `docker compose up db` first.

## Conventions
- API handlers live in `src/api/handlers/`, one file per route.
- Use `zod` schemas from `src/schemas/` for all request validation.

## Boundaries
- Never edit `src/generated/`; run `pnpm codegen` instead.
- Ask before adding a dependency or writing a migration.

Write instructions you could check: “Run pnpm test before committing” works better than “test your changes”.

What to leave out

Secrets

The project file is committed, and every instruction file is sent to the model provider with each session. API keys belong in environment variables or a secrets manager. For MCP servers, Claude Code expands ${VAR} in a project .mcp.json, so the file can reference a token without containing it.

Long documentation

Link to it or move it. Claude Code has path-scoped rules in .claude/rules/ that load only when Claude touches matching files, and skills for multi-step procedures that load when relevant. An imported 2,000-line architecture document still costs 2,000 lines of context.

Anything a tool already enforces

If the formatter fixes indentation, the agent doesn’t need to be told about it.

Permissions

Both files are context, not configuration. The Claude Code docs say so plainly: settings rules are enforced by the client regardless of what Claude decides, while CLAUDE.md instructions shape behavior and aren’t an enforcement layer. “Never run terraform apply” in prose is a request. This is a rule:

JSON
{
  "permissions": {
    "deny": ["Bash(terraform apply *)", "Read(./.env)"]
  }
}

The Claude Code permissions guide covers allow, ask and deny rules and how they merge across files, and Claude Code hooks covers checks that must run every time. Other agents have their own equivalents; Codex, for instance, sets approval per MCP server and per tool in config.toml, as the MCP allowlist guide shows.

Keep them short

Anthropic recommends under 200 lines per CLAUDE.md, because longer files cost context and reduce adherence. Codex is stricter in a different way: once the combined size of its instruction chain reaches 32 KiB, later files aren’t added at all. The file nearest your working directory comes last, so it’s the one that gets cut.

Contradictions are the other failure. If the root file says “use Jest” and a nested one says “use Vitest”, the memory docs say Claude may pick either. Claude Code’s /doctor prompt-audit command checks CLAUDE.md, CLAUDE.local.md and AGENTS.md files for outdated instructions, references to missing files and conflicts, and proposes edits without applying them.

The same split applies to MCP access. An instruction file can tell an agent to prefer the read-only tools of a server; it can’t stop the agent calling the write tools. Toolstile, a managed MCP gateway for remote MCP servers, holds that decision outside the repository: each agent gets Allow, Require approval or Block per tool, checked on every call. Permissions describes how those rules combine.