A coding agent starts every session without the knowledge your team carries around: which command runs the tests, which branch is protected, what must never be deployed by hand.
AGENTS.md is where that knowledge goes. It is a plain Markdown file in the repository that coding agents read before they work.
The file is easy to create and easy to get wrong. A long essay about code quality gives an agent little to act on. A short list of commands, boundaries and checks gives it a lot.
This article explains how the major tools load AGENTS.md, what belongs in it, what to leave out, and which rules need more than a sentence in a text file.
What AGENTS.md is, and what it is not
The AGENTS.md site describes the format as a README for agents. A README explains a project to people. AGENTS.md holds the extra, more operational detail an agent needs: build and test commands, conventions and constraints.
There is no schema. The file is ordinary Markdown with whatever headings suit the project. The format is now stewarded by the Agentic AI Foundation under the Linux Foundation. The site lists support in OpenAI Codex, GitHub Copilot’s coding agent, Google’s Jules and Gemini CLI, Cursor, Zed, Warp, Aider and many others.
Two limits matter from the start.
- It is context, not configuration. Claude Code’s documentation says instruction files are treated as context and are not enforced configuration. An agent can misread or ignore a rule.
- The user’s prompt wins. The AGENTS.md FAQ states that explicit instructions in the chat override the file.
So AGENTS.md sets good defaults. It does not replace permissions, branch protection or review.
How tools load it
All tools that support the format read an AGENTS.md at the repository root. They differ in how they handle more than one file and how much they read.
| Tool | What it reads |
|---|---|
| OpenAI Codex | A global file in the Codex home folder, then one file per directory from the project root down to the current directory. Later files override earlier ones. An AGENTS.override.md takes priority in its folder. Reading stops at a combined size limit, 32 KiB by default. |
| GitHub Copilot | One or more AGENTS.md files anywhere in the repository. The nearest one in the directory tree takes precedence. |
| Claude Code | Primarily CLAUDE.md. Its documentation recommends a CLAUDE.md that imports the shared file with the line @AGENTS.md, followed by any Claude-specific notes, and describes when it reads AGENTS.md directly. |
Two practical consequences follow.
First, keep one source of truth. If a tool needs its own file name, make that file import or point to AGENTS.md instead of copying it. Two copies drift apart.
Second, size matters. Codex stops reading at its limit, and Claude Code’s documentation suggests keeping each instruction file under 200 lines because longer files use more context and reduce adherence. A rule on line 400 may never be read.
Nested files in a monorepo
The AGENTS.md site recommends one file per package in a large monorepo. The agent reads the nearest file, so a package can state its own test command without crowding the root file.
Use the root file for rules that apply everywhere: branching, deployment, secrets. Use package files for local commands and conventions. Do not restate root rules in each package. A changed rule should need one edit.
What to include
The site’s suggested sections are a good start: project overview, build and test commands, code style, testing instructions, security considerations and pull request guidelines. In practice, four kinds of content carry most of the value.
- Commands that actually run. The exact install, build, test and lint commands, with any required environment or version. The AGENTS.md site notes that agents will try to run the listed checks and fix failures before finishing. A wrong command wastes that effort.
- Boundaries. What the agent must not touch or do: protected branches, production deployment, generated files, migrations, secrets.
- A definition of done. What must be true before the agent reports completion: which checks pass, what goes in the pull request description, what needs a human.
- Project-specific traps. Things a capable newcomer would get wrong: a cache that needs a version bump, a folder that is built and never edited, a test suite that needs a local service.
A short overview of the project’s structure helps too, but link to the README for detail instead of copying it.
Write rules an agent can check
An agent follows a rule more reliably when it can tell whether the rule was met. Claude Code’s documentation gives the same advice: write instructions concrete enough to verify, such as “Run npm test before committing” instead of “Test your changes.”
Compare the two columns. The left one sounds responsible. Only the right one can be acted on.
| Vague | Checkable |
|---|---|
| Write clean code. | Run npm run lint; it must exit without errors. |
| Be careful with the database. | Never edit an existing migration. Add a new one in db/migrations/. |
| Don’t break production. | Never run a deploy command. Production deploys only from main through CI. |
| Keep changes focused. | Change only files the task needs. List any other file in the pull request with a reason. |
| Make sure it works. | Before reporting done, run npm test and paste the summary line into the pull request. |
Open each vague rule below and decide what a checkable version would say before reading the suggestion.
“Follow our coding standards.”
Name the tool that encodes the standard and the command that runs it, for example: “Formatting is enforced by Prettier. Run npm run format before committing.” If no tool encodes it, list the two or three conventions that matter most.
“Ask before doing anything risky.”
Define risky as a list: deleting files outside the task, changing dependencies, editing CI configuration, touching authentication code. “Stop and ask before any of these” is a rule an agent can apply.
“Keep the docs updated.”
Say which doc tracks what: “When you add an environment variable, add it to .env.example with a comment.” A specific trigger and a specific file make the rule checkable.
When a rule has a reason that is not obvious, add it in one short clause. “Never edit dist/; it is rebuilt on every deploy” helps an agent handle cases the rule did not foresee.
What to leave out
Every line competes for attention. These usually cost more than they add:
- Plans and history. Old proposals and decision logs belong in their own documents with a clear status. In an instruction file they read as current orders. Outdated documentation can send an assistant backwards.
- Secrets. No keys, tokens or passwords. The file is committed and read by tools. Say where secrets come from instead, such as an environment variable name.
- What a linter already enforces. If a formatter decides indentation, one line saying “run the formatter” replaces a page of style rules.
- General advice. “Write tests” and “use meaningful names” describe any project. Keep what is specific to this one.
- Contradictions. Claude Code’s documentation warns that when instructions conflict, an agent may pick one arbitrarily. Read the whole file before adding a rule.
A starter template
The template below follows the structure above. Replace every placeholder with your project’s real commands. Delete any section you cannot fill with something specific.
# AGENTS.md
## Project
One or two sentences on what this repository is. See README.md for detail.
## Setup and checks
- Install: `npm ci` (Node 22 or newer)
- Build: `npm run build`
- Test: `npm test`
- Lint: `npm run lint`
## Boundaries
- Never push to `main`. Work on a new branch from the latest `origin/main`.
- Never deploy. Production deploys only from `main` through CI.
- Never edit `dist/` or other generated files.
- Never commit secrets. Configuration comes from environment variables listed in `.env.example`.
- Stop and ask before changing dependencies, CI configuration or authentication code.
## Conventions
- Two or three project-specific rules that a newcomer would get wrong.
## Definition of done
- Build, test and lint pass. Paste their summary lines into the pull request.
- The pull request lists every changed file that the task did not obviously need.
- Report what was verified and what was not. A check that did not run is not a pass.The rules in this site’s own repository look much like the boundaries section: start from the latest main on a new branch, open a pull request instead of pushing to main, never deploy by hand, and run two named checks after editing a page. They are short because each one names an action.
Enforce the rules that matter
Because AGENTS.md is context, treat every rule with a serious consequence as a request that also needs a control.
| Rule in AGENTS.md | Control that enforces it |
|---|---|
Never push to main | Branch protection that requires a pull request |
| Never deploy | Deploy credentials available only to CI, not to the agent’s environment |
| Tests must pass | A required status check on the pull request |
| Don’t run destructive commands | The agent tool’s own permission settings; Claude Code, for example, documents hooks and deny rules for this |
The file still earns its place. It tells the agent the rule before it runs into the control, which saves a failed attempt. And it covers judgment calls no control can check, such as when to stop and ask.
A good AGENTS.md also makes review easier. When the definition of done says what the pull request must report, a reviewer can compare the claim with the evidence. How to review AI-generated code before you merge it covers that step.
If several agents work at once, the file is where shared rules about branches and ownership live. Parallel AI coding agents without merge chaos explains how to divide the work so those rules hold.
Keep it current, and test it
An instruction file goes stale like any other document, with a difference: an agent acts on it. A renamed test script or a retired deployment path in AGENTS.md becomes a wrong action in the next session.
- Change it with the code. When a pull request changes a command, a folder layout or a deployment step, it should update AGENTS.md in the same change.
- Run the commands. Every command in the file should work on a fresh clone. If one does not, fix it or remove it.
- Ask the agent to restate it. At the start of a session, ask the agent which rules apply to the task and which command it will use to verify the result. A wrong answer points to a rule that is unclear, buried or contradicted.
- Watch for repeated corrections. If you keep telling agents the same thing in chat, that instruction belongs in the file.
The aim is a file that a new team member could read in a few minutes and use straight away. If it works for them, it is likely to work for an agent too.
Conversation
Discussion
Loading comments…