AI Engineering

AGENTS.md vs CLAUDE.md: Which One Your Repo Needs

AGENTS.md vs CLAUDE.md explained: which file Codex, Claude Code and Copilot read, how to share one set of rules with @AGENTS.md, and the size limits that bite.

AI Engineering AGENTS.md CLAUDE.md Claude Code Codex AI Coding Agents
Developer reviewing project rules for AI coding agents on a laptop at a home desk
AI Engineering Practical engineering guide

AGENTS.md vs CLAUDE.md is a question every team hits once it uses more than one AI coding agent. Codex wants an AGENTS.md. Claude Code wants a CLAUDE.md. GitHub Copilot reads AGENTS.md too, but in its own way. Write both by hand and they drift apart within a week.

The repository behind this website runs on a single AGENTS.md, and both Claude Code and Codex work from it every day. In this guide I explain what each file is, how each agent finds it, the setup I recommend for sharing one set of rules, and what I learned when my own AGENTS.md grew far past the size limits. Everything here was checked against the official Claude Code memory docs and the Codex AGENTS.md docs in November 2026.

AGENTS.md vs CLAUDE.md: the short answer

Both files do the same job. They are plain Markdown files in your repository that tell an AI coding agent how your project works: which commands to run, which rules to follow and what it must never do. Think of them as a README written for an agent instead of a person.

The difference is who reads them. AGENTS.md is an open format that many tools agreed on. CLAUDE.md is Claude Code's own file, and Claude Code gives it priority.

AGENTS.mdCLAUDE.md
What it isOpen format shared by many agentsClaude Code's own instruction file
Read byCodex, GitHub Copilot's coding agent, Cursor, Gemini CLI and othersClaude Code
Where it livesRepo root, plus optional files in subfoldersRepo root or .claude/, plus your home folder and subfolders
Imports other filesNoYes, with @path, up to four hops deep
Size guidanceCodex reads up to 32 KiB by defaultTarget under 200 lines per file

So the honest answer to "which one should I write?" is: write AGENTS.md for your rules, and add a tiny CLAUDE.md only if you need one. I explain when you need it below.

How each coding agent finds its instructions

The rules for finding these files are different for every agent, and that is where most of the confusion comes from. Here is how the three agents I use actually load them.

Codex

Codex builds its instructions from several files. It first checks your Codex home folder (~/.codex) for a global AGENTS.override.md or AGENTS.md. Then it walks from the project root down to the folder you are working in, and picks up at most one file per folder: AGENTS.override.md if it exists, otherwise AGENTS.md.

It joins these files from top to bottom, so a file closer to your code comes later and wins when two rules disagree. It stops adding files once the total reaches 32 KiB, which is the default value of the project_doc_max_bytes setting. If your rules are longer, you can raise it in ~/.codex/config.toml:

# ~/.codex/config.toml
project_doc_max_bytes = 65536

Codex can also read other file names through the project_doc_fallback_filenames setting, but I would not rely on that for team rules. A setting on your laptop does nothing for the next person who clones the repo.

Claude Code

Claude Code loads CLAUDE.md from several places: your home folder (~/.claude/CLAUDE.md), the project (./CLAUDE.md or ./.claude/CLAUDE.md), a personal CLAUDE.local.md, and rule files in .claude/rules/. CLAUDE.md files in subfolders load when Claude starts working in that folder.

Since version 2.1.277, Claude Code also reads AGENTS.md, but with a catch. By default it reads AGENTS.md only when there is no CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md in your working folder or any folder above it. You can change this with the Project instructions setting in /config. The value claude-md-and-agents-md loads both files, but it is a personal setting, so it does not travel with the repository either.

Developer comparing two instruction files side by side on a laptop to keep AI coding agent rules in sync
Two agents, two file names: the goal is one set of rules that both of them load.

GitHub Copilot and the rest

GitHub Copilot's coding agent reads AGENTS.md files anywhere in the repository, and the nearest one in the folder tree takes precedence. Cursor, Gemini CLI, Aider and many other tools are listed on agents.md as supporting the format. In practice, AGENTS.md is the file that the most tools agree on, which is exactly why it should hold your rules.

The setup I recommend: one AGENTS.md and a thin CLAUDE.md

Keep every shared rule in AGENTS.md. Then, if you need a CLAUDE.md, make its first line an import of AGENTS.md. This is also what the Claude Code docs recommend:

@AGENTS.md

## Claude Code only
- Use plan mode for changes that touch more than three files.
- Run the test suite before you say a task is done.

Claude Code replaces @AGENTS.md with the full file when the session starts, then reads the Claude-only notes below it. Codex and Copilot ignore CLAUDE.md and read AGENTS.md directly. One file to edit, every agent in sync.

When you can skip CLAUDE.md completely

If nobody on the project has a CLAUDE.md, you do not need one. Claude Code falls back to AGENTS.md on its own. That is how my own repository works today: there is no CLAUDE.md, and Claude Code loads AGENTS.md through that fallback.

The trap is that the fallback switches off silently. The moment someone adds a CLAUDE.md, even an almost empty one, Claude Code stops reading AGENTS.md and nothing warns you. Running /init is the most common way this happens, because it generates a starting CLAUDE.md, and by default it does not read your AGENTS.md first. If you run /init, add @AGENTS.md to the top of the file it creates.

Why I use an import instead of a symlink

Many guides suggest making CLAUDE.md a symlink to AGENTS.md. It works on macOS and Linux, but I would avoid it. I work on Windows, where symlinks need Administrator rights or Developer Mode, and Git checks them out as plain text files unless core.symlinks is turned on. The Claude Code docs also note that its Edit and Write tools refuse to write through a symlink. A one-line import has none of these problems.

If you want to start from a clean file, my free AGENTS.md Generator and Checker builds an AGENTS.md for common stacks and a matching CLAUDE.md that imports it. It runs in your browser and uploads nothing.

What I learned from a 321-line AGENTS.md

The AGENTS.md in this website's repository started in July 2026 with a few notes about the build step and the blog pipeline. Today it is 321 lines and about 54 KB. That is well over Claude Code's 200-line guidance and well over the 32 KiB that Codex reads by default. I let it grow because every agent session added "one more note", and almost none of them removed anything.

Software developer trimming a long list of project rules in a notebook next to a laptop
Most of a long instruction file is history. The rules that matter fit on one page.

Here is what that taught me.

Specific rules work, general advice does not

The rules that saved me most often are boring and exact:

  • "Rebuild the CSS after any class change." Tailwind is precompiled on this site, and an agent that forgets to rebuild ships a page where the new classes have no styling.
  • "Never push without an explicit yes." Pushing to main deploys to production, so this one line keeps every agent from going live on its own.
  • "Keep draft branch names short." A long SEO slug once became a preview branch name, and the preview hostname broke because it was too long for DNS. Nobody would guess that rule, so it has to be written down.

Compare those with a line like "write clean, maintainable code". Every agent already tries to do that, so the line costs context and changes nothing.

History belongs somewhere else

A big part of my file is a record of what happened: which post went live on which day, which bug was fixed in which commit. Agents need some of that context, but not on every task. My plan is to keep AGENTS.md for rules and commands, and move the history into a separate handoff file that an agent reads only when it needs it. If you use Claude Code, the .claude/rules/ folder is another way to split rules that only apply to some files.

Treat it as a public file

AGENTS.md is committed to your repository. My site's repository is mirrored to a public GitHub repo, so anything in that file is public. Never put API keys, tokens, client names or private notes in it. Write where a secret lives ("keys are in Netlify environment variables"), never the secret itself. The checker in my tool flags lines that look like leaked keys for exactly this reason.

Check what your agent actually loaded

Do not assume an agent read your file. In Claude Code, run /context all and look at the list under Memory files. In Codex, ask it to summarize the current instructions, and it should list the files it loaded in order. If a rule is missing, it is usually a file name, a folder or a size limit problem, not the agent ignoring you.

My recommendation

Write one AGENTS.md at the root of your repository with your real commands and your most important rules, and keep it short. Add a CLAUDE.md only when you need Claude-only notes, and make @AGENTS.md its first line. Review the file every few weeks and remove anything that is history rather than a rule. If you are choosing between agents in the first place, my comparison of Claude Code and Codex covers how they differ in daily work.

I build SaaS products with AI coding agents every day, and setting them up so they follow a team's real rules is part of that work. If you want help with your project, get in touch, or see how I build AI SaaS products.

Keep reading

Explore all articles

AI Engineering

Claude Code vs Codex: Which AI Coding Agent Fits Real SaaS Work?

Read guide

AI Engineering

How to Build an MCP Server: Node.js Build, Test and Publish

Read guide

AI Engineering

MCP Server Authentication: OAuth 2.1 for SaaS in Node.js

Read guide