
Engineering10 min read2,146 words
How to Write an AGENTS.md File for AI Coding Agents
AGENTS.md is a Markdown file that tells AI coding agents how to build, test and change your code. Which tools read it, what to put in it, and a full example.
Jishu Labs
AGENTS.md is a plain Markdown file in a repository that tells AI coding agents how to work on that code: the commands that build and test it, the conventions to follow, and the files they must not touch. The format's own site describes it as a README for agents.
A first draft is quick. A file that every tool on the team loads, that agents follow, and that stays true after the next refactor takes more care. This guide covers which agents read it as of November 2026, what to put in it, length, nesting and upkeep, with a full example.
What is an AGENTS.md file?
An AGENTS.md file is an open Markdown format for giving coding agents the context a new engineer would need on day one: setup and test commands, code style, testing rules and boundaries. It sits beside README.md, which stays written for people. The agents.md site says the format is used by over 60,000 open-source projects.
The format has no required fields, and agents.md says it is now stewarded by the Agentic AI Foundation under the Linux Foundation. Any heading works. What matters is that the content is specific, current and short enough to be read in full before every task.
Which AI coding agents read AGENTS.md?
As of November 2026, OpenAI Codex, Cursor, Claude Code and several GitHub Copilot features read AGENTS.md, each with its own rules for precedence and nesting. Gemini CLI reads GEMINI.md by default and loads AGENTS.md only when you add it to its settings. The agents.md site lists more than 20 tools that support the format.
| Tool | Reads AGENTS.md | Its own file | Worth knowing |
|---|---|---|---|
| OpenAI Codex | Yes | AGENTS.override.md, which wins in the same directory | Reads from the project root down to the current directory, one file per directory, and stops adding files at 32 KiB combined by default |
| Claude Code | Yes, from v2.1.277 | CLAUDE.md | By default only when no CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md exists in the working directory or above it |
| GitHub Copilot | Yes: cloud agent, Copilot CLI, code review on GitHub.com, Chat in VS Code | .github/copilot-instructions.md and .github/instructions/ | Copilot Chat in Visual Studio and JetBrains IDEs does not use agent instructions |
| Cursor | Yes, root and subdirectories | .cursor/rules (.mdc files) | Nested files combine with their parents; the more specific instruction wins |
| Gemini CLI | Only when configured | GEMINI.md | Add AGENTS.md to context.fileName in settings.json |
The agents.md list also names Jules, Aider, Zed, Warp, Junie, Devin and Windsurf. Support is not always automatic: the agents.md FAQ tells Aider users to add read: AGENTS.md to .aider.conf.yml. Confirm the file loads; in Claude Code, /memory lists its path once read.
How do you keep one instruction file for every tool?
Make AGENTS.md the single source and point every other tool at it. Codex, Cursor and Copilot read it directly. For Claude Code, either keep no CLAUDE.md at all, or keep a CLAUDE.md whose first line is an @AGENTS.md import followed only by Claude-specific notes. For Gemini CLI, list AGENTS.md in context.fileName.
repo/
AGENTS.md the canonical instructions every tool reads
CLAUDE.md line 1: @AGENTS.md, then Claude-only notes (optional)
.gemini/settings.json { "context": { "fileName": ["AGENTS.md", "GEMINI.md"] } }
apps/api/AGENTS.md only what differs inside apps/api
Anthropic's documentation says an @AGENTS.md import never makes Claude read the file twice, so the import is safe to keep now that native support exists. A CLAUDE.md symlinked to AGENTS.md also works, but Git checks a committed symlink out as a plain text file unless core.symlinks is enabled, which bites anyone cloning on Windows.
One trap is easy to miss. In Claude Code, a personal CLAUDE.local.md counts as a CLAUDE.md, so creating one quietly stops Claude from reading AGENTS.md. If anyone keeps local notes, set the Project instructions option to claude-md-and-agents-md or use the import.
What should go in an AGENTS.md file?
Put in AGENTS.md what an agent cannot work out quickly from the code and gets wrong without being told: exact commands, conventions a linter does not enforce, how to test, where the boundaries are, and how a change should be submitted. Leave out anything a tool already enforces and anything that is not yet true.
- Commands, verbatim. Install, build, typecheck, lint, the full test suite and a single test file. The agents.md FAQ says agents try to run the checks you list and fix failures before finishing.
- A short map. Which directory holds what, in three to six lines.
- Conventions the linter cannot see. Money in integer cents, dates in UTC, one error helper. Write each rule so it can be checked: Anthropic's guidance prefers "Run npm test before committing" to "Test your changes".
- Testing rules. Where tests live, which test a bug fix adds, and what to do when an existing test fails.
- Boundaries. Generated code, applied migrations, vendored code, lockfiles and CI configuration: which are off limits and which need a person's approval.
- Pull request rules. Branch names, commit format and what the description must contain.
- Security notes. Which data is sensitive and what must never be written to a log.
Leave out formatting rules, which the formatter already enforces; OpenAI's Codex guide gives the same advice for review rules and says to leave formatting and lint checks to CI. Secrets never go in the file. Neither do plans, because an agent reads every sentence as a description of the code as it is today.
AGENTS.md is guidance, not a guardrail
Agents read the file as context and can still ignore it. Anthropic's documentation states that instruction files are not enforced configuration and points to hooks for actions that must be blocked. Enforce hard limits with branch protection, CODEOWNERS, CI checks and each agent's permission settings, and use AGENTS.md to explain them.
How long should an AGENTS.md file be?
An AGENTS.md file should be short enough to be read in full on every task: under about 200 lines for the root file is a sound target, the same limit Anthropic recommends for CLAUDE.md. Length has a direct cost, because every line is loaded into the agent's context window before it reads a single source file.
Vendor documentation makes the cost concrete. Codex stops adding instruction files once their combined size reaches 32 KiB by default, adding them from the project root downward, so an oversized root file can crowd out the more specific nested files. Anthropic notes that longer files reduce adherence, and Cursor's rules guide suggests keeping each rule under 500 lines.
Every line competes with the code and the task for the same window, which is the core context engineering problem. When the root file keeps growing, move package rules into nested files and long procedures into documents the file points to by path.
How do nested AGENTS.md files work in a monorepo?
In a monorepo, put repository-wide rules in a root AGENTS.md and a short AGENTS.md in each package for that package's commands and conventions. The rule published on agents.md is that the file closest to the edited code wins, and an explicit instruction typed in the chat overrides every file.
Tools apply that rule differently. Codex joins files from the root down, so closer files come later and override earlier guidance. Cursor combines nested files with their parents, the more specific instruction winning. Claude Code loads a subdirectory's AGENTS.md when it reads a file there, if that directory has no CLAUDE.md of its own. Per agents.md, OpenAI's main repository had 88 AGENTS.md files at the time of writing.
Write nested files as differences, not copies. A package file that repeats the root rules doubles their context cost, and the copies drift apart the first time someone edits only one.
How do you keep AGENTS.md accurate as the code changes?
Keep AGENTS.md accurate by treating it as code: it lives in the repository, changes in the same pull request as the command, directory or convention it describes, has an owner, and gets checked. A file that names a deleted script is worse than no file, because the agent trusts it and spends a run discovering the error.
- Add a line to the pull request template: "Changed a command, path or convention? Update AGENTS.md here."
- Give the file an owner in CODEOWNERS so every change to it gets a reviewer.
- Run the listed commands in CI or on a schedule, so a renamed script fails a build instead of an agent's task.
- When an agent makes the same mistake twice, add one line that prevents it, the trigger Anthropic gives for CLAUDE.md.
- Prune the file each quarter. In Claude Code v2.1.283 or later, `/doctor prompt-audit` flags references to files or commands that do not exist, in CLAUDE.md and AGENTS.md alike.
A current AGENTS.md also orients new engineers quickly, which matters most in code nobody wrote by hand; see onboarding onto an AI-generated codebase.
What does a complete AGENTS.md file look like?
A complete root AGENTS.md for a typical web monorepo fits on one screen. The example below is illustrative, written for a TypeScript invoicing app with a Next.js front end, an API package and a shared database package. Replace every command and path with your own, and run each command once before you commit the file.
# AGENTS.md
## Project overview
Invoicing SaaS. `apps/web` is the Next.js front end, `apps/api` is the HTTP API,
`packages/db` holds the Postgres schema and migrations, `packages/shared` holds
helpers used by both apps. Node 22, pnpm workspaces.
## Commands
- Install: `pnpm install --frozen-lockfile`
- Run the web app: `pnpm --filter web dev` (http://localhost:3000)
- Typecheck everything: `pnpm -r typecheck`
- Lint everything: `pnpm -r lint`
- All tests: `pnpm -r test`
- One test file: `pnpm --filter api test -- src/invoices/totals.test.ts`
- Integration tests need Postgres: `docker compose up -d db`
- A task is done only when typecheck, lint and the tests of every package
you touched pass.
## Conventions
- TypeScript strict mode. No `any`; use `unknown` and narrow it.
- Money is integer cents (`amountCents`), never floating point.
- Store dates in UTC. Format them only in the UI, with `formatDate()` from
`packages/shared/src/dates.ts`.
- Validate every API input with a Zod schema in `apps/api/src/schemas/`.
- Search `packages/shared` before writing a new helper.
## Testing
- Tests sit next to the code: `totals.ts` -> `totals.test.ts`.
- Every bug fix adds a test that fails without the fix.
- Never weaken or delete an existing assertion to make a test pass.
Stop and explain the failure instead.
## Boundaries
- Never edit a migration in `packages/db/migrations/` that is already on
`main`. Add a new migration.
- Never edit generated files in `apps/web/src/gql/`. Run `pnpm codegen`.
- Ask before adding a dependency, changing CI configuration or touching
`apps/api/src/billing/`.
- Never commit `.env*` files or write secrets, tokens or customer emails
to logs.
## Pull requests
- Branch names: `feat/<short-name>` or `fix/<short-name>`.
- Titles follow Conventional Commits: `fix(api): round tax per line item`.
- The description says what changed, why, and how it was tested.
A nested file for the API package then adds only what differs from the root file:
# apps/api/AGENTS.md
- Run the API alone: `pnpm --filter api dev` (port 4000).
- Route handlers live in `src/routes/<resource>.ts` and return errors
through `httpError()` from `src/http/errors.ts`.
- Database access goes through the repositories in `src/repositories/`.
No SQL in route handlers.
- Billing code in `src/billing/` needs a human reviewer. Propose the change
in the pull request description instead of making it.
AGENTS.md tells an agent how to work in the codebase, not what to build; that belongs in the spec for each change, as the post on spec-driven development argues. Shivo, the AI Spec & PRD Generator from Jishu Labs, covers that step: "Turn a paragraph into a complete PRD, technical design, or API spec, with built-in checks for ambiguity, testability, and completeness."
Frequently Asked Questions
Is AGENTS.md the same as README.md?
No. README.md is written for people who use or contribute to the project. AGENTS.md holds the operational detail an agent needs on every task: exact commands, conventions and boundaries. Keep both, and link between them instead of copying text.
Does Claude Code read AGENTS.md?
Yes, from Claude Code v2.1.277, but by default only when there is no CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md in the working directory or above it. To use both, set Project instructions to claude-md-and-agents-md, or start CLAUDE.md with an @AGENTS.md import.
Should AGENTS.md be committed to the repository?
Yes. Its value comes from being shared and reviewed. Personal preferences belong in uncommitted files, such as a global ~/.codex/AGENTS.md for Codex or a gitignored CLAUDE.local.md for Claude Code, remembering that CLAUDE.local.md stops Claude Code reading AGENTS.md under the default setting.
Can an AI agent write the AGENTS.md file?
It can draft one from the repository, which is a reasonable start. Then cut it to what an agent cannot infer, run every command it lists and check every path. A file that describes the code as it should be, rather than as it is, misleads every agent that reads it.
References
- AGENTS.md — AGENTS.md (Agentic AI Foundation, Linux Foundation)
- How Claude remembers your project — Anthropic, Claude Code documentation
- Custom instructions with AGENTS.md — OpenAI, Codex documentation
- Support for different types of custom instructions — GitHub Docs
- Rules — Cursor documentation
- Provide context with GEMINI.md files — Google, Gemini CLI documentation
About Jishu Labs
Jishu Labs is a software development company founded in 2016. We build custom software, AI/ML systems, and full-stack web and mobile applications for clients, and we make eight AI tools for software teams.




