AGENTS.md is the smallest lever that changes the biggest outcomes: a single file that tells AI agents how to behave in your repo. No skills to configure, no complex setup—just markdown that agents read automatically.
Here are some excellent guides:
Vercel’s internal evals found that a tight AGENTS.md beats skills on formatting reliability and error rates. The lesson: keep rules boring and explicit, then let the model do the work. AGENTS.md beats skills and are easier to work with, and agent adherence is high
Quick Start (5 Minutes)
New to AGENTS.md? Start here. This is all you need to get value immediately.
Step 1: Copy This Template
| |
Step 2: Customize for Your Stack
- Replace
bun testwith your actual test command - Replace
src/with your actual source directory - Add or remove rules based on your team’s needs
Step 3: Save and Commit
| |
Done. Agents will now read this file automatically at the start of each session.
Who This Guide Is For
- Just starting out? Use the quick template above, then stop. Come back when you need more.
- Working on a specific stack? Jump to templates by use case for Python, TypeScript, or documentation projects.
- Managing a monorepo? See hierarchical loading for multi-package setups.
- Using multiple AI tools? Check multi-tool setup to avoid maintaining separate files.
- Want to understand why this works? Read the evidence-based deep dive.
Why AGENTS.md Works
AI agents start every session cold. They don’t know your stack, your conventions, or what “clean code” means to your team. AGENTS.md is their onboarding document—loaded automatically before the first prompt.
What changes when you add AGENTS.md:
- Agents stop guessing at test commands
- Dependencies aren’t added without discussion
- Code style stays consistent
- You stop repeating the same instructions
Size matters. Codex has a default cap (around 64KB). Claude Code loads your full CLAUDE.md into every session. Factory.ai recommends ≤150 lines—long files bury the signal. Small and specific beats long and generic.
AGENTS.md vs CLAUDE.md
| AGENTS.md | CLAUDE.md | |
|---|---|---|
| Used by | OpenAI Codex, Cursor, OpenCode, Zed | Claude Code only |
| Format | Markdown (YAML frontmatter optional) | Markdown only |
| Location | Repo root, subdirectories, ~/.codex/ | Repo root, subdirectories, ~/.claude/ |
| Overrides | AGENTS.override.md per-folder | Nested CLAUDE.md in subdirectories |
| Loading | Merges root → subdirectory | Hierarchical: global → root → subdirectory |
The practical difference: Almost nothing. Both are markdown files with the same purpose. The naming is vendor-specific—OpenAI uses AGENTS.md, Anthropic uses CLAUDE.md. Content-wise, they’re interchangeable.
Multi-tool strategy:
- Use
AGENTS.mdas your canonical source - Symlink
CLAUDE.md→AGENTS.mdfor Claude CodeLn -s AGENTS.md CLAUDE.md - Most teams don’t need both
nested AGENTS.md
├── AGENTS.md ├── CLAUDE.md -> AGENTS.md # optional symlink for compatibility ├── content/ │ ├── AGENTS.md │ └── posts/ ├── scripts/ │ ├── AGENTS.md │ └── build/ └── apps/ ├── AGENTS.md └── web/ ├── AGENTS.md └── src/
Each agent can get their own instructions to adhere to. This saves on context rot, token expenditure, and helps with organization.
Templates by Use Case
General / Documentation Projects
Best for: Static sites, documentation, content repositories
| |
Why this works: Documentation projects need consistency more than code style. The focus is on accuracy, link integrity, and workflow rules.
Python Projects
Best for: Django, Flask, FastAPI, data science, scripts
| |
Key differences from general template:
- Specific Python tooling (pytest, ruff/black, mypy)
- Type hints and docstring requirements
- Test coverage rules
- Package structure conventions
TypeScript / Node.js Projects
Best for: React, Next.js, Express, Node APIs
| |
Key differences from Python:
- TypeScript-specific (strict mode, no
any) - bun/pnpm/yarn workflow
- Build step required (dist/ folder)
- ESLint + Prettier integration
- Security check for secrets
Common Mistakes to Avoid
Learn from others’ failures. These are the top issues that make AGENTS.md ineffective:
❌ Writing a Manual Instead of Guardrails
| |
✅ Be concise:
| |
❌ Including Sensitive Data
| |
Security note: Agents read AGENTS.md before every task. Never commit secrets. Use environment variables instead.
❌ Conflicting Instructions Across Files
- Root says “use single quotes”
- Subdirectory says “use double quotes”
- Result: Agent confusion, inconsistent output
Fix: Root file has global rules, subdirectories only document what’s different.
❌ Outdated Information
- Commands that no longer exist
- Dependencies you’ve removed
- Old file paths
Fix: Treat AGENTS.md like code. Review it when your workflow changes.
❌ One Giant File
- Factory.ai recommends ≤150 lines
- Move long docs to separate files, link to them with
@docs/architecture.md
Hierarchical Loading (Monorepos)
Both Codex and Claude Code support nested configuration files. The closest file to the working directory takes precedence.
Example monorepo structure:
my-project/
├── AGENTS.md # Global rules
├── package.json
├── apps/
│ ├── web/
│ │ ├── AGENTS.md # Web-specific overrides
│ │ └── src/
│ └── api/
│ ├── AGENTS.md # API-specific overrides
│ └── src/
└── packages/
└── shared/
└── src/
Root AGENTS.md (shared rules):
| |
apps/web/AGENTS.md (specific rules):
| |
How it merges: Agents read the root first, then override with subdirectory rules. Don’t repeat global rules—only document what’s different.
Multi-Tool Setup
Using multiple AI tools? You have options:
Option 1: Single source (recommended)
| |
Option 2: Tool-specific files Keep separate files if your teams use different tools:
AGENTS.md— OpenAI Codex rulesCLAUDE.md— Claude Code rules (can reference same content)
Option 3: Progressive disclosure
| |
Agents load @file references when needed, keeping your main file small.
Advanced Patterns
Use these only after you’ve mastered the basics.
Global Configuration
Claude Code:
| |
OpenAI Codex:
| |
Global files apply to all projects, repo-specific files override them.
Override Files (Codex Only)
Codex supports AGENTS.override.md for temporary deviations:
| |
Verification Checklist
Before relying on your AGENTS.md:
- File is under 150 lines
- Commands actually work (test them)
- File paths match your repo structure
- No secrets or sensitive data
- Rules don’t conflict with each other
- Links to extended docs use
@filesyntax - Last reviewed date is recent
References
- Vercel: AGENTS.md vs Skills evaluation — Evidence that tight AGENTS.md beats skills
- OpenAI Codex: AGENTS.md documentation — Official spec and merging behavior
- Anthropic: CLAUDE.md best practices — Claude Code specific guidance
- Factory.ai AGENTS.md guide — Templates and size recommendations
- agents.md community — Cross-tool standardization effort
Related links
- /posts/agents-md-practical-guide/ — Evidence-based deep dive on what works
- /tools/codex/ — OpenAI Codex setup and workflow
- /compare/codex-vs-claude-vs-cursor/ — Tool comparison
- /agents/ — AI agent ecosystem overview