Back to Blog

Explainers

CLAUDE.md vs AGENTS.md: Context Architecture and Token Budgets

By · Published · Updated · 10 min read

A shared AGENTS.md feeds Claude Code through a CLAUDE.md import, plus Codex and Cursor, above Claude Code's always loaded and on demand context layers.
Keep shared rules in AGENTS.md, let CLAUDE.md import it, and keep only must have rules in the always loaded layer.

CLAUDE.md and AGENTS.md are both plain Markdown instruction files that a coding agent reads before it touches your code. CLAUDE.md is the native Claude Code format, with managed, user, project and local layers, @path imports and path-scoped rules. AGENTS.md is the open, tool-neutral format described at agents.md, now stewarded by the Agentic AI Foundation under the Linux Foundation and supported by OpenAI Codex, Cursor, Gemini CLI, GitHub Copilot coding agent and others.

This article covers the decision that follows: which file owns which rules, how each tool resolves precedence in a monorepo, what the always-loaded layer costs per session and per subagent, and how to keep one source of truth across Claude Code, Codex and Cursor. For the wider multi-client workspace topology, read One Engine, Many Clients.

What does CLAUDE.md control that AGENTS.md does not?

The Claude Code memory docs list four scopes in load order: a managed policy file deployed by IT that claudeMdExcludes cannot skip, your user file at ~/.claude/CLAUDE.md, the project file at ./CLAUDE.md or ./.claude/CLAUDE.md, and a personal CLAUDE.local.md kept out of git. CLAUDE.md can import files with @path, resolved relative to the importing file and recursive to four hops; imports outside the working directory need a one-time approval. Files in .claude/rules/ can carry a paths glob so they load only when Claude touches a matching file, and block-level HTML comments are stripped before injection.

AGENTS.md is deliberately simpler: no required fields, the nearest file in the tree takes precedence, and explicit chat prompts override everything. Codex and Cursor each layer their own discovery rules on top, summarized below.

What the Claude Code docs say about AGENTS.md support. Reading AGENTS.md directly requires v2.1.277 or later. Under the default Project instructions value, claude-md-or-agents-md, Claude reads AGENTS.md only when there is no CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md in the working directory or above it; the user file, managed file and .claude/rules/ do not count. Claude never reads AGENTS.local.md, AGENTS.override.md or anything under .agents/. The other values are claude-md-and-agents-md, claude-md and managed-only. The trap: adding a personal CLAUDE.local.md silently switches Claude away from your AGENTS.md.

Sources: Claude Code memory and subagent docs, the OpenAI Codex AGENTS.md guide and the Cursor rules docs, read November 24, 2026. "Not covered" means the vendor page does not say.
DimensionCLAUDE.md in Claude CodeAGENTS.md in OpenAI CodexAGENTS.md and rules in Cursor
Scope layersManaged, user, project, local (CLAUDE.local.md)Global file in ~/.codex, then at most one file per directory from project root to working directoryTeam, Project (.cursor/rules) and User Rules, plus root and nested AGENTS.md
DiscoveryWorking directory and ancestors at launch; subdirectory files on demandProject root down to the working directory onlyNested AGENTS.md applies in its directory and children
Conflict precedenceConcatenated, not overridden; closer files read last; on a contradiction Claude may pick eitherConcatenated root down; closer files appear later and overrideTeam beats Project beats User; the more specific AGENTS.md wins
Import syntax@path, recursive to four hopsNone documented; extra names via project_doc_fallback_filenames@ references are read when needed, not inlined
Conditional loadingpaths globs in .claude/rules/; skills on demandDirectory placement only.mdc frontmatter: alwaysApply, globs, description
Subagent inheritanceNon-fork subagents load the full hierarchy; Explore, Plan and web-fetch skip itNot coveredNot covered
Size ceilingTarget under 200 lines per file; files over 4 MiB skippedproject_doc_max_bytes, 32 KiB by defaultKeep rules under 500 lines

How much context budget do nested instruction files consume per subagent?

There is no universal number, because the cost is whatever your files contain. What is documented is the multiplier. Per the subagent docs, every non-fork subagent starts with every level of the CLAUDE.md hierarchy the main conversation loads, including rules, CLAUDE.local.md, managed files and any AGENTS.md read as project instructions. The built-in Explore, Plan and web-fetch agents skip it, a custom agent can opt out with omitClaudeMd: true, and a fork inherits the parent conversation instead.

@path imports do not reduce cost, because imported files load with the file that imports them. The always-loaded layer is therefore a per-spawn tax: paid once in the main session and again in each subagent.

A reproducible way to measure your own stack

  1. Start a fresh session from your usual launch directory and run /context all. The Memory files list shows each file loaded at launch.
  2. Measure each listed file, plus every @path import target, with wc -m.
  3. For tokens, send the concatenated text to the free token counting endpoint with the model you run. Anthropic calls the result an estimate and notes that Claude 4.7 and later use a newer tokenizer producing roughly 30 percent more tokens for the same text, so never reuse older counts.
  4. Repeat from every launch directory: a session started in a package loads that file plus every ancestor, while one started at the root loads only the root file at launch.
  5. Multiply by the non-fork subagents a typical task spawns, excluding Explore and Plan, and record the result with the date and Claude Code version.

The same steps as commands. Run the first line inside Claude Code and the rest in a shell:

# 1. Inside Claude Code: list what loaded at launch
/context all

# 2. Characters per file (add every @path import target)
wc -m ~/.claude/CLAUDE.md CLAUDE.md .claude/rules/*.md AGENTS.md

# 3. Token estimate for the concatenated stack (free endpoint, estimate only)
cat ~/.claude/CLAUDE.md CLAUDE.md .claude/rules/*.md AGENTS.md \
  | jq -Rs '{model: "claude-opus-5-5", messages: [{role: "user", content: .}]}' \
  | curl -s https://api.anthropic.com/v1/messages/count_tokens \
      -H "x-api-key: $ANTHROPIC_API_KEY" \
      -H "anthropic-version: 2026-10-21" \
      -H "content-type: application/json" \
      -d @- | jq .input_tokens

Worked example: the instruction tax at 1, 5 and 15 subagents

Illustrative example, not a measurement. Assumptions: an untrimmed stack of 20,000 characters (user file, root project file, two unscoped rules files and an imported AGENTS.md) and a trimmed stack of 8,000 characters after package material moves into path-scoped rules and skills. The conversion uses 4 characters per token, a planning heuristic only; replace it with your step 3 count. That yields 5,000 and 2,000 tokens per load.

Illustrative arithmetic from the stated assumptions. Instruction tokens loaded across all context windows = (1 + N) x stack size for N non-fork subagents. Built-in Explore and Plan skip CLAUDE.md. Billing also depends on prompt caching and model rates.
ScenarioUntrimmed stack (assumed 5,000 tokens)Trimmed stack (assumed 2,000 tokens)If every helper is Explore or Plan
Main session only5,0002,000Same as the stack column
Main plus 1 subagent10,0004,000Main session only: 5,000 or 2,000
Main plus 5 subagents30,00012,000Main session only: 5,000 or 2,000
Main plus 15 subagents80,00032,000Main session only: 5,000 or 2,000

The gap grows linearly with fan-out: here the trim removes 48,000 instruction tokens at 15 subagents. Whether they bill at full or cached-read rates depends on prompt caching, covered in the Claude 5.5 routing and caching guide. The larger cost is often adherence: the memory docs warn that longer files reduce adherence and that Claude may resolve contradictions arbitrarily.

To run the same arithmetic on your own file, paste it into the CLAUDE.md token budget checker. It applies the 4-characters-per-token heuristic at 1, 5 and 15 loads and flags duplicate lines, empty headings and sections that could move to path-scoped rules.

Compaction matters too. The context window docs say the project-root CLAUDE.md and unscoped rules are re-injected after compaction, while nested files and path-scoped rules reload only on demand. Root content is what you pay for most often and the only instruction text guaranteed to survive, so reserve it for rules that must never drop out. How compaction decides what else survives, and how to budget a long session around it, is the subject of Context Engineering for Long-Horizon Agents.

In a monorepo, the large codebase guide recommends a short root file plus one file per package, and claudeMdExcludes in .claude/settings.local.json for packages you never touch. On-demand files have their own per-file limit (40,000 characters on a 200K context window); past it, Claude receives only the start of the file.

How do teams sync rules across Claude Code, Codex and Cursor without duplication?

Make AGENTS.md canonical. Codex and Cursor read it natively, and Claude Code documents a pattern that works under any Project instructions setting: a CLAUDE.md beside the AGENTS.md whose first line is @AGENTS.md, followed by Claude-only guidance. Claude reads the import first, and the docs state the import never makes Claude read AGENTS.md twice. It also covers sessions where direct support is unavailable, such as versions before v2.1.277.

A symlink (ln -s AGENTS.md CLAUDE.md) works when there is no Claude-specific content, with two documented caveats: Claude Code Edit and Write tools refuse to write through a symlink, and on Windows Git checks a committed symlink out as a one-line text file unless core.symlinks is enabled. Mixed-OS teams should use the import.

@AGENTS.md

## Claude Code only
- Use plan mode for changes under src/billing/.
- Package conventions live in .claude/rules/ with paths globs.

Then design around the places where the tools diverge:

  • Codex stops adding files once the combined chain reaches 32 KiB by default, so a long root AGENTS.md can push nested files out.
  • Codex honors AGENTS.override.md; Claude Code does not read it, so a Codex-only fix is invisible to Claude.
  • Cursor scopes rules with .mdc frontmatter; Claude Code uses paths in .claude/rules/. Generate both from one source rather than copying by hand.
  • Claude Code /import appends a one-time copy of AGENTS.md. A copy drifts; an import does not.

A canonical manifest and a pre-commit check

Design recommendation. Keep one small manifest that tags each rule as all tools, Claude only, or path-scoped, and generate AGENTS.md, the CLAUDE.md wrappers, .claude/rules/ and .cursor/rules/*.mdc from it. Enforce the invariants in a pre-commit hook such as the illustrative script below, and pair it with /doctor prompt-audit (v2.1.283 or later), which reports conflicting or outdated instructions without editing anything.

#!/usr/bin/env bash
# Illustrative pre-commit check for instruction-file drift and size.
set -euo pipefail
fail=0
# 1. A CLAUDE.md next to an AGENTS.md must import it on line 1.
for a in $(git ls-files '*AGENTS.md'); do
  c="$(dirname "$a")/CLAUDE.md"
  if [ -f "$c" ] && [ "$(head -n1 "$c")" != "@AGENTS.md" ]; then
    echo "$c does not start with @AGENTS.md"; fail=1
  fi
done
# 2. Claude Code guidance: keep each CLAUDE.md under 200 lines.
for c in $(git ls-files '*CLAUDE.md'); do
  n=$(wc -l < "$c" | tr -d ' ')
  [ "$n" -lt 200 ] || { echo "$c has $n lines"; fail=1; }
done
# 3. Codex default project_doc_max_bytes is 32 KiB per chain.
#    Conservative: sums every AGENTS.md, not one root-to-cwd chain.
total=$(git ls-files '*AGENTS.md' | xargs cat | wc -c | tr -d ' ')
[ "$total" -le 32768 ] || { echo "AGENTS.md total $total bytes"; fail=1; }
exit $fail

What belongs in always-loaded files versus on-demand skills?

The memory docs give the core rule: CLAUDE.md holds facts Claude needs in every session, such as build commands, conventions and layout. A multi-step procedure, or guidance for one part of the codebase, belongs in a skill or a path-scoped rule. The skills docs explain why: a skill description sits in the listing every turn, but the body loads only when invoked. The listing budget scales at 1% of the context window, and each entry is capped at 1,536 characters.

Anything that must happen every time is not an instruction at all. CLAUDE.md is context, not enforced configuration, so use a hook or a permissions.deny rule for hard limits.

Placement rules derived from the Claude Code memory, skills and large codebase docs, read November 24, 2026.
Instruction typeWhere it belongsWhen it costs context
Cross-tool invariants: build and test commands, commit conventionsAGENTS.md, imported by CLAUDE.mdEvery session and every non-fork subagent
Claude-only guardrailsCLAUDE.md, below the importEvery session and every non-fork subagent
Conventions for one package or file typeNested CLAUDE.md, or .claude/rules/ with pathsOnly after Claude touches a matching file
Procedures and long reference materialA skill: SKILL.md plus supporting filesDescription every turn; body only when invoked
Rules that must always holdA hook or permissions.denyNone as instructions; the client enforces them
Organization policyManaged CLAUDE.md plus managed settingsEvery session on the machine

What should an engineering lead standardize first?

  1. Run /context all from every common launch directory and record the stack size.
  2. Make AGENTS.md canonical if any team uses Codex or Cursor.
  3. Convert each CLAUDE.md into an @AGENTS.md wrapper with Claude-only additions below it.
  4. Move package conventions into nested files or path-scoped rules, and procedures into skills.
  5. Install the pre-commit check, and revisit the files after major model releases.
  6. Re-measure and record the decision. The MCP vs CLI decision record gives an ADR template and covers the tool-definition share of the same startup budget.

For identity boundaries across teams, read Multi-Tenant Claude Code Architecture. Test the pattern on one repository, document the before and after numbers, then roll it out.

Primary sources

Frequently Asked Questions

Does Claude Code read AGENTS.md?

Yes, from v2.1.277. By default Claude Code reads AGENTS.md only when there is no CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md in your working directory or any directory above it. You can change that with the Project instructions setting in /config, for example to read both files. Older versions, or sessions with the built-in AGENTS.md plugin disabled, read CLAUDE.md only, so a CLAUDE.md that imports @AGENTS.md is the most portable setup.

Should CLAUDE.md be a symlink to AGENTS.md or an import?

Prefer the import. A CLAUDE.md whose first line is @AGENTS.md lets you add Claude-only guidance below it, never makes Claude read AGENTS.md twice, and works on every operating system. A symlink is fine when you have no Claude-specific content and nobody clones on Windows, but the Claude Code Edit and Write tools refuse to write through it, and Git checks a committed symlink out on Windows as a plain text file unless core.symlinks is enabled.

How long should a root CLAUDE.md or AGENTS.md be?

Claude Code documentation targets under 200 lines per CLAUDE.md file and warns that longer files reduce adherence. Codex stops adding AGENTS.md files once the combined chain reaches 32 KiB by default, and Cursor recommends keeping rules under 500 lines. Apply the strictest limit among the tools your team uses, then measure the real stack with /context all and the token counting endpoint instead of guessing.

Do Claude Code subagents inherit CLAUDE.md and AGENTS.md?

Non-fork subagents load the same CLAUDE.md hierarchy as the main session, including user and project files, rules, CLAUDE.local.md, managed policy and any AGENTS.md read as project instructions. The built-in Explore, Plan and web-fetch agents skip it, and a custom agent can opt out with omitClaudeMd. Forks inherit the parent conversation instead. Auto memory from the main session is not loaded into subagents.

Add ClaudeSkillsGuide as a preferred source on Google