AGENTS.md vs CLAUDE.md: AI Repo Rules Guide
AGENTS.md is an open, vendor-neutral repository instruction file supported across Codex, Cursor, Windsurf, Antigravity, Zed, and Aider, whereas CLAUDE.md is Anthropic Claude Code's native instruction file with @file import syntax.
You can author your repository rules once, audit instruction token overhead, and export synchronized files for all four major formats in the Seoffix AGENTS.md & Coding Agent Rules Generator.
Why Multi-Agent Teams Suffer From Instruction Drift
On a typical engineering team in 2026, backend engineers run Claude Code in the terminal, frontend developers work inside Cursor or VS Code with GitHub Copilot, and CI review bots run autonomous coding agents.
When each developer maintains a separate instruction file by hand—CLAUDE.md, AGENTS.md, .github/copilot-instructions.md, and .cursor/rules/*.mdc—test flags, forbidden directories, and architecture conventions drift out of sync within weeks.
Worse, poorly maintained instruction files accumulate thousands of lines of stale postmortems that silently tax every prompt turn and dilute instruction adherence.
Format Comparison: AGENTS.md vs. CLAUDE.md vs. Copilot vs. Cursor
Review how each coding harness discovers, scopes, and merges repository Markdown rules:
| Instruction File | Primary Ecosystems | Nested Directory Support? | Path Glob / Conditional Loading? | File Import Syntax |
|---|---|---|---|---|
AGENTS.md |
OpenAI Codex, Cursor, Antigravity, Windsurf, Zed, Roo/Cline, OpenCode | Yes — closest AGENTS.md to edited file takes precedence |
Via directory placement | Standard Markdown links (read on demand) |
CLAUDE.md |
Anthropic Claude Code CLI & IDE extensions | Yes — root + parent + subdirectory CLAUDE.md + .claude/rules/*.md |
Supported inside .claude/rules/ frontmatter paths: |
Native @path/to/file.md inline expansion |
.github/copilot-instructions.md |
GitHub Copilot Chat, IDE Agent, & GitHub PR Coding Agent | Scoped twins via .github/instructions/*.instructions.md |
Yes — applyTo: "src/api/**/*.ts" frontmatter |
Markdown relative links |
.cursor/rules/*.mdc |
Cursor IDE Agent & Composer | Modular per-rule files inside .cursor/rules/ |
Yes — alwaysApply, globs, or description-matched |
@file context references |
The Clean Single-Source Pattern (Zero Duplicate Maintenance)
You do not need to copy-paste 180 lines of Markdown across four different filenames every time a test script changes.
Treat root AGENTS.md as your single canonical source of truth in Git, and point tool-specific shims directly at it:
- Commit Canonical Rules in
/AGENTS.md: Keep build, test, typecheck, lint, directory ownership, and verification gates clean and concise (~800 to 2,000 tokens). - Bridge Claude Code in 1 Line: Create
/CLAUDE.mdcontaining@AGENTS.md(plus any optional Claude-only slash-command notes) so Claude Code expandsAGENTS.mdautomatically at session boot. - Scope Heavy Domain Rules by Directory or Glob: Move database migration rules into
packages/db/AGENTS.mdor.cursor/rules/database.mdc(globs: ["packages/db/**"]) so frontend UI turns never pay for SQL rules. - Generate Synchronized Exports When Needed: Use our AGENTS.md Generator & Exporter whenever initializing a repository that requires standalone
.github/copilot-instructions.mdfiles.
What Actually Belongs Inside a High-Signal AGENTS.md File
Empirical evaluations of coding agents consistently show that short, concrete, command-driven rule files outperform 5,000-word philosophical style guides.
Structure your root AGENTS.md around five verifiable operational blocks:
# Repository Engineering Rules (Acme Billing Monorepo)
## 1. Fast Verification Commands (Run Before Claiming Completion)
- Install workspace deps: `pnpm install --frozen-lockfile`
- Single-file unit test (preferred while iterating): `pnpm vitest run path/to/file.test.ts`
- Typecheck modified package: `pnpm --filter @acme/api typecheck`
- Lint check: `pnpm biome check --write`
## 2. Architecture & Directory Ownership
- `apps/api/`: Fastify REST handlers & Zod request schemas (stateless; no direct SQL).
- `packages/ledger/`: Double-entry Postgres queries via Drizzle; all money values use integer minor units (`cents`), never floats.
- `packages/ui/`: Design-token React primitives; never hardcode raw `#hex` colors.
## 3. Non-Negotiable Safety Invariants
- Never edit generated migrations under `packages/ledger/drizzle/` manually; run `pnpm db:generate`.
- All outbound webhook calls must pass through `safeFetchWithSsrfGuard()` in `packages/net/`.
- Never commit secrets or `.env.local` tokens; use `.env.example` placeholders.
## 4. Git & PR Hygiene
- Keep diffs scoped strictly to the requested task; do not reformat unrelated files. What to Delete From Your Instruction Files Immediately
Audit your existing AGENTS.md or CLAUDE.md and remove four common categories of context pollution:
- Formatting Rules Enforced by Prettier, Biome, Black, or Ruff: Never spend 400 prompt tokens telling an LLM to use 2 spaces and single quotes when a deterministic 50ms formatter fixes it automatically.
- Full Directory Tree Dumps: Agents discover files dynamically via ripgrep and glob tools; static file trees go stale after two pull requests and mislead agents toward deleted paths.
- Generic Advice ("Write Clean, Bug-Free SOLID Code"): Zero-information platitudes add zero signal while competing for attention with critical repo-specific traps (like integer cents vs floats).
- One-Off Historical Bug Narratives: Belong in commit messages, regression tests, or searchable docs—not in an always-loaded system prompt injected into every turn.
Monorepo Hierarchy: Root Rules vs. Nested Package AGENTS.md
Large polyglot monorepos—combining a TypeScript Next.js frontend, a Go or Python API tier, and Terraform infrastructure—break down when all three stacks share one monolithic root instruction file.
Modern coding agents resolve nested AGENTS.md and CLAUDE.md files hierarchically from the repository root down to the active working directory:
repo-root/
├── AGENTS.md # Global git hygiene, security invariants & workspace commands (~900 tokens)
├── CLAUDE.md # Single line: @AGENTS.md
├── .github/copilot-instructions.md # Exported workspace summary for GitHub PR reviews
├── apps/web/
│ └── AGENTS.md # Design tokens, Playwright tests & App Router conventions (~700 tokens)
└── services/payments/
└── AGENTS.md # Idempotency keys, integer minor units & webhook signature tests (~800 tokens)
With that layout, an agent fixing a CSS layout bug inside apps/web/ loads only global hygiene plus frontend design-token rules—never wasting context window attention on payment ledger SQL constraints.
Deterministic Hooks & Linters vs. Prompt Instructions
A golden rule of agentic software engineering is never asking an LLM politely in prose to enforce an invariant that a 20-millisecond script can guarantee with exit code 1.
| Engineering Requirement | Put in AGENTS.md? |
Enforce via Script / Hook / CI? | Recommended Implementation |
|---|---|---|---|
| Code indentation, quotes & import order | No (wastes tokens) | Yes — auto-fix on save/commit | Biome, Prettier, Ruff, gofmt, rustfmt |
| How to run targeted single-file tests | Yes (essential) | Yes — fast test runner | Exact CLI command + example file path in AGENTS.md |
Banning retired brand names or raw #hex colors |
1-line reminder | Yes — hard gate script | Custom AST/regex gate script referenced in verification section |
| Domain architecture & non-obvious module ownership | Yes (essential) | Optional boundary linter | Concise bullet map explaining which service owns state |
| Multi-step deployment or asset generation recipe | Link only | Executable skill script | On-demand SKILL.md loaded only when that task runs |
Frequently Asked Questions on AGENTS.md & CLAUDE.md
Does Cursor read AGENTS.md natively alongside .cursor/rules?
Yes. Current releases of Cursor read root and nested AGENTS.md files automatically while also honoring glob-scoped .cursor/rules/*.mdc files for path-specific instructions.
Should I commit personal editor preferences into repository CLAUDE.md?
No. Keep personal tone preferences, local keybindings, or private scratch paths inside user-level ~/.claude/CLAUDE.md or uncommitted CLAUDE.local.md (listed in .gitignore) so team repositories stay clean.
How often should teams prune AGENTS.md?
Audit instruction files alongside major architecture changes: delete rules for retired directories, verify every listed CLI command still exits 0, and re-check total token weight in our AGENTS.md Linter & Generator.
Can autonomous CI agents and PR reviewers use the same AGENTS.md file?
Yes. Headless pull-request review bots and cloud background coding agents read root and package-scoped AGENTS.md files automatically, applying identical test commands and architectural boundaries during automated code review.
Token Budgeting: Rules + Skills + MCP Schemas
Every always-on instruction file shares finite prompt space with your active MCP tool schemas and loaded skills.
If your root AGENTS.md consumes 6,000 tokens and six connected MCP servers inject another 18,000 tokens of tool schemas, your agent burns 24,000 tokens before reading a single source file!
- Keep always-loaded root
AGENTS.mdunder 1,500 to 2,500 tokens, measured in our LLM Context Window Calculator. - Move specialized multi-step procedures (such as release checklists, WebP asset pipelines, or security audits) into on-demand Agent Skills; explore production patterns in the Seoffix Agent Skills Hub and AI Agents Directory.
- Audit connected tool configs with the MCP JSON Config Validator so unused global MCP servers are disabled per project.
Generate & Lint AGENTS.md, CLAUDE.md & Cursor Rules
Open the free AGENTS.md & Coding Agent Rules Generator to build lean, token-budgeted instruction files from proven stack presets and export synchronized configs in one click.