Writing an AGENTS.md that coding agents actually follow
One instruction file now works across Codex, Cursor, Copilot, Antigravity and Claude Code, but each discovers it differently. A recipe for a file that holds up.
Key figures
- 5
- Major agents compared
- 32 KiB
- Codex default instruction budget
AGENTS.md started as a convention and is now a format maintained by the Agentic AI Foundation under the Linux Foundation. Its pitch is simple: a README for agents, holding the build steps, test commands and conventions that would clutter a human-facing README. By late 2026 it is read by most mainstream coding agents, which makes it the cheapest way to get consistent behaviour across a team that uses different tools. This tutorial writes a good file, scales it to a monorepo, connects it to tool-specific formats and tests that agents actually use it. All behaviour below was checked against vendor documentation in November 2026.
Who reads it, and how
| Tool | How it finds AGENTS.md | Tool-specific format |
|---|---|---|
| OpenAI Codex | Concatenates one file per directory from repo root to working directory; AGENTS.override.md wins | ~/.codex/AGENTS.md (global) |
| Claude Code | Reads it only when no CLAUDE.md or CLAUDE.local.md exists (v2.1.277+) | CLAUDE.md, .claude/rules/ |
| Cursor | Root and subdirectories; more specific files take precedence | .cursor/rules/*.mdc |
| GitHub Copilot | Anywhere in the repo; nearest file wins | .github/copilot-instructions.md, *.instructions.md |
| Google Antigravity | Workspace folder and parents up to repo root | .agents/rules/*.md |
The format has no required fields. It is plain Markdown, and explicit instructions in the chat still override it.
1. Write the core file
Lead with what an agent cannot infer by reading the code: exact commands, invariants and boundaries.
# AGENTS.md
## Project
Invoice service: TypeScript (Node 22), Fastify, Postgres 16 via Drizzle.
Domain logic lives in src/billing/; HTTP handlers in src/routes/.
## Commands
- Install: pnpm install
- Test one file: pnpm vitest run path/to/file.test.ts
- Before committing: pnpm lint && pnpm typecheck && pnpm test
## Conventions
- Money is integer cents (type Cents). Never use floats for amounts.
- Every new endpoint needs a zod schema in src/schemas/ and a test in tests/api/.
- Never edit files in src/db/migrations/; generate a new one with pnpm db:generate.
## Boundaries
- Do not read or print .env files or secrets.
- Ask before adding a dependency or changing CI configuration.
## Pull requests
- Title: [area] short imperative summary
- Paste the output summary of the pre-commit check into the description.A few rules make the difference between a file agents follow and one they ignore:
- Runnable over descriptive. "Run
pnpm vitest run <file>" beats "we use Vitest". Agents copy commands literally. - Specific over generic. Every line costs context on every request. Cut anything a competent engineer would do anyway.
- Give the reason for surprising rules. "Integer cents, because float rounding broke invoices" helps the model generalise to cases you did not list.
- State boundaries plainly. Explicit "ask before" and "never" lines are far easier for agents to honour than implied norms.
2. Scale to a monorepo
Add an AGENTS.md per package for local commands and conventions, and keep the root file to repo-wide rules. How the layers combine varies: Codex concatenates root-to-leaf, so the root text is always present and nearer files are read last; Copilot and Cursor give precedence to the nearest file. Write the root so it is true everywhere, and let package files add detail rather than contradict it.
One exception: Antigravity does not load rule files from folders below the workspace you opened, so either open the agent in the package directory or keep critical rules at the root.
3. Bridge to tool-specific files
Do not maintain parallel copies; they drift within weeks. Instead:
# Claude Code: import the shared file, then add Claude-only notes below it
printf '@AGENTS.md\n\n## Claude Code\nUse the reviewer subagent before committing.\n' > CLAUDE.md
# Or, if you need nothing tool-specific, a symlink is enough
ln -s AGENTS.md CLAUDE.mdUse the tool-specific formats only for what AGENTS.md cannot express, mainly file-scoped rules: Cursor's .mdc files with globs, Copilot's .github/instructions/*.instructions.md with an applyTo pattern, Claude Code's .claude/rules/ with paths, and Antigravity's .agents/rules/ with a trigger.
4. Test that agents use it
Treat the file like code and verify it:
- Load check. Ask each agent to summarise the repository instructions it was given. Claude Code also prints a line naming the
AGENTS.mdit loaded when noCLAUDE.mdexists. - Canary task. Ask for a small change that should trigger your rules, such as "add a GET /invoices/:id endpoint", and check for the zod schema, the test and integer cents.
- Review in pull requests. Changes to instruction files alter every agent's behaviour, so require review, especially on contributions from outside the team.
Pitfalls and next steps
- Size budgets. Codex stops adding files after 32 KiB by default; Anthropic suggests keeping each
CLAUDE.mdunder 200 lines; Antigravity shares a 20,000-token budget across always-on rules. - Accidental shadowing. In Claude Code, adding a personal
CLAUDE.local.mdstops it readingAGENTS.md. The explicit import avoids this. - Stale commands. A renamed script turns your file into misinformation. Run the listed commands in CI occasionally.
- Secrets and injection. Instruction files are committed and sent to model providers, so never put credentials in them. Treat an AGENTS.md in an unfamiliar repository as untrusted input.
To start, write the root file in under an hour, run the canary task in two different agents, and fix whatever they got wrong by adding a line, not a paragraph.
Researched and drafted with AI assistance under editorial review. Report errors to support@aiseeker.dev.
Sources
This report synthesises the sources below. Primary sources are marked.
- [1]AGENTS.md
Agentic AI Foundation2026.11.28Primary
- [2]Custom instructions with AGENTS.md
OpenAI (Codex docs)2026.11.28Primary
- [3]How Claude remembers your project
Anthropic (Claude Code Docs)2026.11.28Primary
- [4]Rules
Cursor Docs2026.11.28Primary
- [5]Adding repository custom instructions for GitHub Copilot
GitHub Docs2026.11.28Primary
- [6]Rules
Google Antigravity Docs2026.11.28Primary