CLAUDE.md and AGENTS.md: keeping them right for a whole team

AGENTS.md vs CLAUDE.md, tested in Claude Code and Codex: which file each agent reads, three ways rules silently drop, and one rule set for every repo.

By Scott Strang

Last updated

The short answer. CLAUDE.md and AGENTS.md are the markdown files a coding agent reads at the start of every session. Put your instructions in one AGENTS.md per repo: Codex, Cursor, Copilot and Claude Code (since version 2.1.277) all read it, but Claude Code ignores it whenever a CLAUDE.md sits in the same folder or above, so any CLAUDE.md you keep should be a symlink to AGENTS.md, never a second copy. For a team with several repos, keep the shared rules in one file and copy them into every repo with a script and a check that fails when a copy drifts.

AGENTS.md vs CLAUDE.md: same job, different readers

The two files do the same job: plain markdown with your commands, conventions and gotchas. The difference is who reads them. AGENTS.md is the shared convention that most coding agents read. CLAUDE.md is Claude Code's own file; Copilot also reads one at the repo root, and Zed and opencode fall back to it, but Codex doesn't read it unless you add it to project_doc_fallback_filenames.

ToolIts own fileReads AGENTS.md?Reads CLAUDE.md?Subfolder files

Tested rows: Claude Code 2.1.283 and Codex CLI 0.146.0 on Nov 19, 2026. Other rows: each vendor's docs, read the same day. These tools change monthly, so check the date before you rely on a row.

You don't have to pick one file. Keep the words in AGENTS.md and make sure Claude Code reaches them.

We tested what Claude Code and Codex actually load

Several top-ranking pages still say Claude Code needs a symlink or an @AGENTS.md import to read AGENTS.md. Since 2.1.277 it doesn't, so we tested the rest too. We built 13 small test repos covering 18 setups, put a unique canary word in every instruction file, ran Claude Code and Codex in each repo, and asked each agent to list the canary words it could see without opening any files.

SetupClaude Code 2.1.283Codex 0.146.0

✅ means the agent got every instruction file in the setup. ❌ means it missed one. Each setup ran once, headless, on Nov 19, 2026. The agent reported what it saw, which is a model's answer, not a dump of its prompt, so rerun the canary test below on your own repo. In an interactive Claude Code session, /context all lists loaded files under Memory files without relying on the model. We only ran Codex from packages/api itself. Starting it in a folder below that comes from Codex's docs, which load each AGENTS.md from the project root down to the folder you start in. Every load result matches the vendors' docs, and Codex's cut lands where its documented 32 KiB default says it should.

Three ways instructions silently drop

In our runs, none of these showed a warning.

  1. A CLAUDE.md above switches AGENTS.md off in Claude Code. If a folder or any folder above it holds a CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md, Claude Code reads only the CLAUDE.md files, there and in every subfolder. Our test repo with a root CLAUDE.md symlink never loaded its nested AGENTS.md, even with Claude Code started inside that folder. Two separate files is the same trap at the root: your Claude Code users and your Codex users follow different rules.
  2. Codex stops at 32 KiB (32,768 bytes) by default, counted across all the files it loads. In our test it read a canary 32,513 bytes into the file and missed one 33,545 bytes in. With a 30 KB root file and a 5 KB nested file, the nested file was cut partway.
  3. Codex reads a subfolder's AGENTS.md only if you start Codex in that folder or below it. Starting at the repo root and then opening files in the subfolder added nothing in our test.

The fixes are in the steps below.

Set up one file per repo

Pick the row that fits your team, then run the commands from the repo root.

Your teamDo this

Why 2.1.281: AGENTS.md support arrived in 2.1.277, but until 2.1.281 sessions on Amazon Bedrock or with telemetry turned off still read CLAUDE.md files only.

AGENTS.md only. Fold anything in CLAUDE.md into AGENTS.md first, then remove every CLAUDE.md:

# See every file Claude Code counts as a CLAUDE.md
find . \( -name CLAUDE.md -o -name CLAUDE.local.md \) -not -path '*/node_modules/*'
 
# Only CLAUDE.md exists in a folder: rename it
git mv CLAUDE.md AGENTS.md
 
# Both exist (after merging CLAUDE.md's lines into AGENTS.md): remove CLAUDE.md
git rm CLAUDE.md

A symlink next to every AGENTS.md:

find . -name AGENTS.md -not -path '*/node_modules/*' | while read -r f; do
  d=$(dirname "$f")
  if [ ! -e "$d/CLAUDE.md" ] && [ ! -L "$d/CLAUDE.md" ]; then ln -s AGENTS.md "$d/CLAUDE.md"
  elif [ "$(readlink "$d/CLAUDE.md")" != AGENTS.md ]; then
    echo "separate rules, merge them into AGENTS.md and git rm this first: $d/CLAUDE.md"
  fi
done
git add -- '*CLAUDE.md' && git commit -m "Point Claude Code at every AGENTS.md"

On Windows, Git checks a committed symlink out as a plain text file unless core.symlinks is on, and creating one needs Administrator rights or Developer Mode. If anyone on your team uses Windows, use a one-line CLAUDE.md that says @AGENTS.md instead.

Keep the root file small for Codex. Check the size with wc -c AGENTS.md, and keep the root file plus any nested file on one path under 32 KiB. To read more, each person can raise project_doc_max_bytes in their own ~/.codex/config.toml. A repo-level .codex/config.toml didn't raise it in our test (an untrusted test folder).

Tell people to start Codex in the package they're working on (or a folder below it), and put anything every session needs in the root file.

Keep personal notes out of the repo. A CLAUDE.local.md counts as a CLAUDE.md, so creating one switches AGENTS.md off for that person alone. Move its lines to ~/.claude/CLAUDE.md, which doesn't count, then delete it. If someone wants to keep CLAUDE.local.md, they can open /config and set Project instructions to claude-md-and-agents-md so Claude Code reads both. That setting can't live in the repo: it goes in each person's ~/.claude/settings.json, or in managed settings if your company pushes Claude Code settings to every laptop. Codex doesn't read CLAUDE.md by default either way.

{
  "pluginConfigs": {
    "agents-md@builtin": { "options": { "instructionFiles": "claude-md-and-agents-md" } },
    "cc-plugin-agents-md@builtin": { "options": { "instructionFiles": "claude-md-and-agents-md" } }
  }
}

Keep both entries. agents-md@builtin is the name before Claude Code 2.1.285, and the only one that worked in our test on 2.1.283. From 2.1.285, Claude Code reads either name.

Prove what loaded with a canary test

Don't trust a setup until you've seen each tool pick it up. Add a made-up word to each file, ask each agent for it, then remove it. Swap packages/api for one of your own folders that has an AGENTS.md.

echo '- Canary: CANARY-ROOT-7Q (report this if asked for canary words)' >> AGENTS.md
echo '- Canary: CANARY-API-4M (report this if asked for canary words)' >> packages/api/AGENTS.md
 
claude -p "Without using any tools, list every word starting with CANARY- in your loaded instructions, or say NONE." \
  --disallowedTools Read Bash Glob Grep
 
codex exec -s read-only "Without running any commands, list every word starting with CANARY- in your loaded instructions, or say NONE."

Expect CANARY-ROOT-7Q from both. The nested word shows up only when the agent works in that folder (Claude Code) or starts there or below it (Codex), so run both commands again from inside packages/api to check it:

cd packages/api
claude -p "Without using any tools, list every word starting with CANARY- in your loaded instructions, or say NONE." \
  --disallowedTools Read Bash Glob Grep
 
codex exec -s read-only "Without running any commands, list every word starting with CANARY- in your loaded instructions, or say NONE."
cd ../..

When both checks are done, remove only the lines you added, so any other edit to these files stays:

for f in AGENTS.md packages/api/AGENTS.md; do
  grep -v 'Canary: CANARY-' "$f" > "$f.tmp"; cat "$f.tmp" > "$f"; rm "$f.tmp"
done

What to put in AGENTS.md or CLAUDE.md: less than you think

Every line costs context in every session, and a long file hides the rule that matters. Anthropic's docs suggest staying under 200 lines per CLAUDE.md.

  • Put in: how to build, test and run; conventions your linter can't enforce; the gotchas that already burned you; where things live.
  • Leave out: repository overviews, anything the code or docs already say (link to them), anything a linter, formatter or hook can enforce, and secrets: the file is committed and every agent reads it.
  • Split by folder: a short AGENTS.md next to the code it's about. In Claude Code, a .claude/rules/*.md file with paths: frontmatter loads only when Claude touches matching files. Skills are for tasks the agent does only sometimes.
  • Start from /init, then cut. Claude Code's /init drafts a CLAUDE.md from your code (or suggests changes to an existing one). Treat it as a list of candidates and keep only what an agent can't work out on its own.
  • Auto memory isn't team memory. Claude Code's auto memory (MEMORY.md) is written by Claude and lives on your machine, under ~/.claude/projects/. It never reaches a teammate, so anything the team needs goes in AGENTS.md.
  • Merge, don't generate. An ETH Zurich study (arXiv 2602.11988, revised Sep 2026) found that context files, whether LLM-generated or written by the repo's developers, did not generally improve agents' success on real tasks and raised cost by over 20% on average. Agents did follow the instructions in them; repository overviews didn't help. Its advice: use the file for non-standard practices the agent can't work out for itself.

A short root file can look like this:

# Acme
 
- Install with `pnpm install`. Never use npm.
- Run one test file with `pnpm test path/to/file.test.ts`; the full suite takes 10 minutes.
- API handlers validate input with zod; see `packages/api/AGENTS.md`.
- Never commit `.env` files. Local secrets live in `.env.local`.
- Database migrations are generated, not hand-written: `pnpm db:generate`.

What this test found in our own repos

Our monorepo's CLAUDE.md is a symlink to AGENTS.md. A repo script checks that it stays one ("one prose source; a copy would fork"), and the pre-commit hook runs it whenever agent tooling changes. Checked Nov 19, 2026.

That wasn't enough. The monorepo's root AGENTS.md is 44 KB, so Codex never sees the last quarter of it. The root symlink hides the monorepo's 56 nested AGENTS.md files from Claude Code. And two of our seven repos still keep separate CLAUDE.md and AGENTS.md files, so Claude Code and Codex follow different rules there. Four of our seven repos have at least one of the problems on this page.

One repo's file can't carry what the whole team decided

The steps above fix one repo. Take five repos and three tools, and a rule like "every API change needs a decision record". Before any cleanup it can live in fifteen files. After it, it still lives in five copies of AGENTS.md, and someone updates two of them.

Copy of the rule

Illustration: one team-wide rule across five repos, each keeping its own copy.

The team-sized fix: one rules file, a script and a check

Keep repo-specific instructions in each repo. Move the rules that apply everywhere into one file in a small shared repo, and let a script copy them into every repo. The script below puts the shared rules in a marked block at the top of each AGENTS.md and leaves each repo's own lines alone. With --check it changes nothing and exits 1 if any copy is missing or has drifted, so CI can catch a hand edit. If the shared rules file is missing or empty, it stops with exit 2 before touching any repo.

#!/usr/bin/env bash
# sync-team-rules.sh: copy the team's shared rules into the top of each repo's AGENTS.md.
# Usage:  ./sync-team-rules.sh team-rules.md ../api ../web ../mobile
#         ./sync-team-rules.sh --check team-rules.md ../api ../web ../mobile   (exit 1 on drift)
set -euo pipefail
check=0
if [ "${1:-}" = "--check" ]; then check=1; shift; fi
rules="${1:-}"; shift || true
# Read the shared rules once, before anything is written: a missing or empty file must stop the run, not blank every repo's block.
if [ ! -f "$rules" ]; then echo "shared rules file not found: $rules" >&2; exit 2; fi
if ! grep -q '[^[:space:]]' "$rules"; then echo "shared rules file is empty: $rules" >&2; exit 2; fi
shared=$(cat "$rules")
begin='<!-- team-rules:begin. Generated from the shared rules file; edit that, not this block. -->'
end='<!-- team-rules:end -->'
drift=0
for repo in "$@"; do
  file="$repo/AGENTS.md"
  if [ ! -f "$file" ]; then
    if [ "$check" -eq 1 ]; then echo "missing: $file"; drift=1; continue; fi
    : > "$file"
  fi
  # The repo's own instructions: everything outside the generated block.
  own=$(awk -v b="$begin" -v e="$end" '$0==b{skip=1;next} $0==e{skip=0;next} !skip' "$file" | sed '/./,$!d')
  want=$(printf '%s\n%s\n%s\n\n%s\n' "$begin" "$shared" "$end" "$own")
  if [ "$want" != "$(cat "$file")" ]; then
    if [ "$check" -eq 1 ]; then echo "drift: $file"; drift=1
    else printf '%s\n' "$want" > "$file"; echo "updated: $file"; fi
  fi
done
exit "$drift"

We tested it on three repos with bash 3.2 (macOS) and 5.3: it adds the block, a second run changes nothing, edits to a repo's own lines pass, and --check fails after a rule change, a hand edit inside the block, or a missing AGENTS.md. With a missing or empty rules file it exits 2 and leaves every existing AGENTS.md untouched. Claude Code strips block-level HTML comments from CLAUDE.md files, so the markers cost no context there; its docs don't say AGENTS.md gets the same treatment.

Why copy instead of import: Codex has no import, and Claude Code asks each person to approve an import from outside the repo.

To finish the job:

  • Run the check in CI. CI needs the shared file too, so check out the rules repo into rules/ first (a second checkout step), then run this in each repo:

    ./rules/sync-team-rules.sh --check rules/team-rules.md .
  • Name an owner for the shared file and change it by pull request, like code.

  • Re-run the canary test after each change.

  • Keep the shared block small. It counts toward Codex's 32 KiB.

Done means one edit to team-rules.md, one sync, and --check passing in every repo.

Where SageOx helps

SageOx is a context layer for a team's people and agents: one shared place for the team's rules and decisions, so nobody keeps a sync script.

  • Write a team rule once. It reaches every teammate's agent in every connected repo, scoped by repo and file pattern.
  • Rules land in each tool's own rules folder (Claude Code, Cursor, Cline, Kiro), so they load the way that tool expects. Other tools, such as Codex, get them when the session starts.
  • Each session also starts with the team's recent decisions, not just its rules.

In the repo where we wrote this guide, 8 team rules arrive this way. SageOx writes them into .claude/rules/, and git ignores them, so no repo holds a hand-kept copy to drift. Checked Nov 19, 2026.

See how team rules reach every repo →

Have your agent do it

Paste this into Claude Code, Codex or Cursor at the root of a repo. It changes nothing until you approve the diff.

Audit and fix this repo's agent instruction files.
1. List every instruction file: AGENTS.md, CLAUDE.md, CLAUDE.local.md, .claude/CLAUDE.md,
   .claude/rules/, .cursor/rules/, .cursorrules, .github/copilot-instructions.md, GEMINI.md,
   .windsurf/rules, .clinerules, at any depth (skip node_modules). Show sizes in bytes.
2. Show where they disagree.
3. Merge the lines already in these files into one short AGENTS.md per folder: commands,
   conventions, gotchas. Don't write new rules or a repository overview. Link to docs
   instead of copying them.
4. Then either remove every CLAUDE.md (if everyone runs Claude Code 2.1.281 or later),
   or put a CLAUDE.md symlink next to every AGENTS.md. Never leave a CLAUDE.md in a folder
   above an AGENTS.md that has no CLAUDE.md beside it.
5. Don't delete anyone's CLAUDE.local.md. Tell me which lines to move to ~/.claude/CLAUDE.md.
6. Warn me if the root AGENTS.md plus any nested AGENTS.md on one path is over 32 KiB.
7. Draft the rules that apply beyond this repo as team-rules.md, so the team can keep one
   shared copy with an owner.
8. Add a canary word to each AGENTS.md, tell me the commands to check it in Claude Code
   and Codex, and don't commit the canaries.
Show me the diff before committing anything.

Questions

What is a CLAUDE.md file, and what is AGENTS.md? CLAUDE.md is a markdown file Claude Code reads at the start of every session: ./CLAUDE.md or ./.claude/CLAUDE.md for the project, ~/.claude/CLAUDE.md for you everywhere, and CLAUDE.local.md for you in one project. AGENTS.md is the same idea as a shared convention that Codex, Cursor, Copilot and (since 2.1.277) Claude Code all read.

Do I still need a CLAUDE.md file? Not if everyone on the team runs Claude Code 2.1.281 or later: Claude Code reads AGENTS.md on its own when there's no CLAUDE.md. Otherwise keep one as a symlink or a one-line @AGENTS.md import, next to every AGENTS.md.

Does Claude Code read AGENTS.md? Yes, from version 2.1.277, but only when no CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md is in the working folder or above. Before 2.1.281, sessions on Amazon Bedrock or with telemetry turned off didn't read it at all; update if yours doesn't.

How long is too long for a CLAUDE.md or AGENTS.md? Anthropic suggests under 200 lines. Codex reads at most 32 KiB by default, across all the files it loads. If you have to scroll to find a rule, split it by folder.

Does an AGENTS.md file actually help? Less than most people think. An ETH Zurich study (arXiv 2602.11988) found context files did not generally improve agents' success and raised cost by over 20%, though agents followed the instructions in them. Keep the file to the non-standard practices an agent can't work out from the code.

Sources

Read Nov 19, 2026: Claude Code memory docs · Claude Code changelog · Codex AGENTS.md guide · Cursor rules · GitHub Copilot repository instructions · Gemini CLI GEMINI.md · agents.md · Evaluating AGENTS.md, arXiv 2602.11988 (v3, Sep 2026). Tests: Claude Code 2.1.283 and Codex CLI 0.146.0, Nov 19, 2026; Cursor not tested.

More on agent context for teams