AGENTS.md: one rules file for every coding agent (2026)
Stop keeping CLAUDE.md, .cursorrules, copilot-instructions.md and GEMINI.md in sync by hand. Put your rules in AGENTS.md once. Codex, Cursor, GitHub Copilot and Antigravity read it as-is. Claude Code reads it through a one-line @AGENTS.md import, and Gemini CLI needs one setting. Below: a support table checked against each vendor's docs, a copy-paste AGENTS.md, and a free script that fails CI when the files drift apart.
Free below. Want a finished AGENTS.md, CLAUDE.md and six Cursor rules for a whole project? App Builder Agent Pack ($19). Building on Next.js + Supabase + Stripe? Stack kit ($9). Or all 5 premium packs for $29.
The setup
your-repo/ ├── AGENTS.md # the one source of truth (all agents) ├── CLAUDE.md # 1 line: @AGENTS.md (+ Claude-only notes) ├── .gemini/settings.json # only if you use Gemini CLI ├── .cursor/rules/*.mdc # optional: file-scoped rules only, no copies └── packages/api/AGENTS.md # optional: nested rules for one folder
Who reads AGENTS.md (checked 2026-10-24)
| Agent | Support | What to do |
|---|---|---|
| OpenAI Codex | Native | Reads AGENTS.md from the repo root down to your current folder, plus ~/.codex/AGENTS.md. AGENTS.override.md in a folder replaces that folder's file. Stops at 32 KiB combined by default (project_doc_max_bytes). docs |
| Cursor | Native | Reads AGENTS.md in the project root and in subfolders (nested files combine, more specific wins). Use .cursor/rules/*.mdc only for file-scoped extras. A file @-mention inside a rule is not inlined, so don't try to 'import' AGENTS.md from a rule. docs |
| GitHub Copilot | Native | Copilot reads AGENTS.md files anywhere in the repo; the nearest one in the directory tree takes precedence. It also reads .github/copilot-instructions.md, and instruction files are additive, so don't repeat or contradict AGENTS.md there. In VS Code, the chat.useAgentsMdFile setting is on by default. docs |
| Claude Code | Partly native | Since v2.1.277 (Sept 2026) it reads AGENTS.md, but by default only when there is no CLAUDE.md or CLAUDE.local.md. The reliable setup: a CLAUDE.md whose first line is @AGENTS.md, with any Claude-only notes below it. Or set Project instructions to claude-md-and-agents-md in /config. docs |
| Gemini CLI | Setting | Reads GEMINI.md by default. Add AGENTS.md to context.fileName in .gemini/settings.json. docs |
| Google Antigravity (IDE and CLI) | Native | Reads AGENTS.md and GEMINI.md at the workspace root and in subfolders. (For free-tier and Google One users, Gemini CLI was replaced by Antigravity CLI in June 2026.) docs |
| Aider | Setting | Add read: AGENTS.md to .aider.conf.yml. docs |
| Windsurf, Zed, Amp, Jules, Devin, Factory, opencode, goose, Warp, Roo Code, Kilo Code and others | Listed | Listed as AGENTS.md-compatible on agents.md. We didn't check each tool's docs, so confirm in yours. docs |
Tools change fast. Every row links to the vendor doc we checked, so confirm in your version.
1. AGENTS.md (the source of truth)
Raw markdown with every file: /guides/agents-md.md. Save this as AGENTS.md in your repo root and replace every {{placeholder}}.
# AGENTS.md
## Project
- What this is: {{one sentence, e.g. "Next.js 15 app for booking dog walks"}}
- Stack: {{language, framework, database, hosting}}
- Package manager: {{npm / pnpm / bun / uv}}. Never switch it.
## Commands
- Install: {{pnpm install}}
- Dev server: {{pnpm dev}}
- Tests: {{pnpm test}} (single file: {{pnpm test path/to/file}})
- Lint and types: {{pnpm lint && pnpm typecheck}}
- Build: {{pnpm build}}
## Layout
- {{src/app/}}: routes and pages
- {{src/lib/}}: shared logic, no UI
- {{tests/}}: tests mirror the src/ tree
- Do not edit: {{generated/, migrations already applied, vendor/}}
## How to work
1. For anything bigger than a one-line fix, write a short plan first and wait for my OK.
2. Make one small change at a time, then run the tests and lint before moving on.
3. Match the existing style in the file you are editing. Don't reformat unrelated code.
4. Don't add a new dependency without asking. Prefer what's already installed.
5. If something is unclear, ask one question instead of guessing.
## Code rules
- {{TypeScript strict, no `any`}}
- {{Errors: throw typed errors, never swallow them}}
- {{Secrets come from env vars; never hard-code keys or commit .env}}
## Definition of done
Before you say a task is done, list each claim (tests pass, bug fixed, feature works)
and mark it VERIFIED with the exact command and its real output, or FAILED, or NOT RUN.
Never say "all tests pass" unless you ran them in this session and quote the result.
Don't skip, delete, or weaken a test to make it pass.
## Gotchas
- {{e.g. "The dev DB resets on every `pnpm dev`; seed with `pnpm seed`"}}
- {{e.g. "Auth is mocked in tests via tests/setup.ts"}}
2. CLAUDE.md (one line, plus Claude-only notes)
@AGENTS.md
## Claude Code only
- {{e.g. Use plan mode for changes under src/billing/}}
The @AGENTS.md line pulls the whole file in. It must not be inside backticks or a code block, because Claude Code skips imports there.
3. Gemini CLI: .gemini/settings.json
{
"context": { "fileName": ["AGENTS.md", "GEMINI.md"] }
}Aider: read: AGENTS.md in .aider.conf.yml. Codex, Cursor, Copilot and Antigravity need nothing extra.
4. Keep them in sync: check_agents_md.sh (free)
A short, read-only POSIX shell script. Run it from the repo root or as a CI step. It exits 1 if AGENTS.md is missing, if CLAUDE.md doesn't import it, if Gemini's settings don't list it, or if AGENTS.md is over Codex's 32 KiB default. It also flags duplicate sources. We ran it on 7 test repos under sh and dash (log in the raw markdown).
Download: curl -o check_agents_md.sh https://agentpromptsatoz.com/guides/agents-md/check_agents_md.sh.txt (read it first), then sh check_agents_md.sh. In GitHub Actions, add a step: - run: sh check_agents_md.sh
#!/usr/bin/env sh
# check_agents_md.sh - fail if your agent rules files have drifted apart.
# Free from https://agentpromptsatoz.com/guides/agents-md/ . Read-only; changes nothing.
# Usage: sh check_agents_md.sh (run from the repo root, locally or in CI)
fail=0
say(){ printf '%s\n' "$1"; }
if [ ! -s AGENTS.md ]; then say "FAIL: AGENTS.md is missing or empty (it is the single source of truth)"; exit 1; fi
say "ok: AGENTS.md found"
size=$(wc -c < AGENTS.md | tr -d ' ')
if [ "$size" -gt 32768 ]; then say "FAIL: AGENTS.md is $size bytes; Codex stops reading at 32 KiB by default"; fail=1; else say "ok: AGENTS.md is $size bytes (Codex default cap is 32768)"; fi
for f in CLAUDE.md .claude/CLAUDE.md; do
[ -e "$f" ] || continue
if [ -L "$f" ]; then say "ok: $f is a symlink to $(readlink "$f")"; continue; fi
if grep -Eq '^[[:space:]]*@(\./)?AGENTS\.md[[:space:]]*$' "$f"; then say "ok: $f imports @AGENTS.md"
else say "FAIL: $f exists but does not import AGENTS.md. Claude Code reads CLAUDE.md instead of AGENTS.md when both exist; add a line: @AGENTS.md"; fail=1; fi
done
if [ -f .gemini/settings.json ]; then
if grep -q 'AGENTS.md' .gemini/settings.json; then say "ok: .gemini/settings.json lists AGENTS.md"; else say "FAIL: .gemini/settings.json does not list AGENTS.md in context.fileName"; fail=1; fi
fi
if [ -f .github/copilot-instructions.md ]; then
n=$(grep -c '' .github/copilot-instructions.md | tr -d ' ')
say "note: .github/copilot-instructions.md also exists ($n lines). Copilot adds it on top of AGENTS.md, so keep it Copilot-only and don't repeat or contradict AGENTS.md"
fi
for f in .cursorrules; do [ -f "$f" ] && say "note: legacy $f found; move it into AGENTS.md or .cursor/rules/*.mdc"; done
[ $fail = 0 ] && say "PASS: one source of truth" || say "FAILED: fix the lines above"
exit $fail
Migrating from an existing setup
- Have a CLAUDE.md? Move its shared rules into AGENTS.md. Replace CLAUDE.md with
@AGENTS.mdplus anything Claude-only. - Have .cursorrules or .cursor/rules? Move the always-on rules into AGENTS.md. Keep only file-scoped .mdc rules (with globs). Our Cursor rules guide shows the four rule types.
- Have .github/copilot-instructions.md? Move the shared parts to AGENTS.md. Copilot reads both and adds them together, so keep only Copilot-specific lines there, or delete it.
- Have GEMINI.md? Move the content to AGENTS.md and add the settings.json above. Or keep GEMINI.md and list both names.
Tips
- Write AGENTS.md once, then delete the copies. Two files with the same rules will drift within a month.
- Put the exact install, test, lint and build commands first. Every agent follows them literally.
- Keep tool-specific notes out of AGENTS.md. Claude-only lines go under the import in CLAUDE.md.
- Check with each tool after setup: /memory or /context in Claude Code, the References list in Copilot, 'Summarize the current instructions' in Codex.
- Add one line to AGENTS.md whenever any agent makes the same mistake twice.
FAQ
Does Claude Code read AGENTS.md now?
Yes, since Claude Code v2.1.277 (September 2026), but by default only when your project has no CLAUDE.md or CLAUDE.local.md. If you have, or might later add, a CLAUDE.md, put @AGENTS.md on its first line. Anthropic's docs say keeping that import never makes Claude read AGENTS.md twice. You can also set Project instructions to claude-md-and-agents-md in /config to load both.
AGENTS.md vs CLAUDE.md: which should be the source of truth?
AGENTS.md. Codex, Cursor, GitHub Copilot, Antigravity and many others read it natively. Claude Code reads it directly or through a one-line @AGENTS.md import. If you keep the real rules in CLAUDE.md instead, every non-Claude agent misses them.
Should I use a symlink (ln -s AGENTS.md CLAUDE.md) instead of the import?
It works, with two catches from Anthropic's docs. Claude's Edit and Write tools won't write through a symlink. And on Windows, Git checks a committed symlink out as a one-line text file unless core.symlinks is enabled. The @AGENTS.md import works everywhere and still leaves room for Claude-only notes.
Do I still need .cursor/rules or .github/copilot-instructions.md?
Not for shared rules. Cursor and Copilot both read AGENTS.md. Use .cursor/rules/*.mdc or .github/instructions/*.instructions.md only for file-scoped extras, such as test-file rules. Copilot adds copilot-instructions.md on top of AGENTS.md, so anything you put in both will drift.
How long can AGENTS.md be?
Codex stops adding instruction files after 32 KiB combined by default. Claude's docs suggest under 200 lines per file. Keep the root file to one screen (commands, layout, how to work, definition of done) and move folder-specific rules into nested AGENTS.md files.
How do nested AGENTS.md files work?
Put another AGENTS.md inside a package or folder. Codex, Cursor and Copilot all apply the nearest file. Codex and Cursor combine it with the parent files, with the closer file winning. Claude Code loads a subfolder's AGENTS.md when it reads a file there, if that folder has no CLAUDE.md.
How do I stop the files drifting apart?
Run the free check_agents_md.sh below in CI. It fails if CLAUDE.md doesn't import AGENTS.md, if Gemini's settings don't list it, or if AGENTS.md is over Codex's 32 KiB default. It also flags a copilot-instructions.md or legacy .cursorrules that may duplicate it.
Skip the setup: App Builder Agent Pack
A finished AGENTS.md and CLAUDE.md plus six Cursor rules files (core, planning, frontend, backend/API, testing, git hygiene), with a verify-before-done working agreement already in them, and a plan-then-build workflow: spec, plan, small verified builds, self-review and a handoff note. Plain text you own, with a PDF guide.
Get the App Builder pack: $19 Or all 5 premium packs for $29Next.js + Supabase + Stripe?
The stack kit's AGENTS.md is the source of truth, with a thin CLAUDE.md that imports it, scoped Cursor rules for RLS and Stripe webhooks, and a 13-point read-only pre-deploy audit.
Free lite version Get the full kit: $9