What is AGENTS.md? What to put in it, with an example
Updated
AGENTS.md is a Markdown file that tells coding agents how to work in your repository. Put the build and test commands there, along with project conventions and files to leave alone. Tools differ in how they load it. For example, by default Claude Code uses AGENTS.md when it finds no project CLAUDE.md or CLAUDE.local.md in the working directory or its ancestors. Claude Code’s project instruction rules
What it looks like#
A short file that pays for itself:
# AGENTS.md
## Commands
- Install: `pnpm install`
- Test one file: `pnpm vitest run path/to/file.test.ts`
- Before finishing: `pnpm lint && pnpm test`
## Layout
- API handlers in `server/routes/`, shared types in `packages/types/`.
## Rules
- Use `date-fns` for dates, not `moment`.
- Do not edit anything under `generated/`. Run `pnpm codegen` instead.
- No new dependencies without asking.
Without it, the agent guesses npm test, runs the whole suite to check one file, and edits a generated file that gets overwritten on the next build. With it, the agent runs the right command the first time.
What should I put in AGENTS.md?#
Only what the agent can’t work out by reading the code, and would get wrong:
- Commands: install, build, test, lint, and how to run a single test. This is the most useful part, because a wrong guess costs a full agent turn.
- Where things live: two or three lines, not a tour.
- Rules it can’t see: which library to use for dates or HTTP, error-handling patterns, what not to import.
- What not to touch: generated files, vendored code, commands not to run, such as migrations.
- Done means: “lint and tests pass, no new warnings”.
- Secrets: where they live and that the agent must not read or print them. See keep secrets away from AI agents.
The fast test command matters most when the full suite is slow. In a Go codebase where a plain go test run had become a coffee break of several minutes, renaming tests with TestUnit_ and TestIntegration_ prefixes made the unit subset a 0.3-second run :
go test -run ^TestUnit_ ./...
That one line in AGENTS.md is the difference between an agent that checks every edit and one that waits minutes per turn or skips the check.
Leave out:
- Anything a linter or formatter already enforces.
- Architecture essays. Link to them.
- Things that change every week. The agent will follow the stale version.
How long should it be?#
Short. The file is added to the model’s context in every session, and a longer file gives the model more to follow, not more to know. Claude Code’s docs suggest keeping its instruction files under 200 lines. Codex stops reading project instruction files once they add up to 32 KiB by default (the project_doc_max_bytes setting).
Add a line when an agent repeats a mistake. Delete a line when it no longer matters. An old onboarding rule carries over unchanged: every question a new hire asks is a bug in the documentation, and every mistake an agent repeats is a line missing from AGENTS.md.
A typical line of that kind: “Never silence a warning with # nosec, // eslint-disable or @ts-ignore; fix the cause or stop and ask.” A common failure: an agent that only wanted the code to run interpolated a coupon code straight into SQL and added # nosec to quiet the linter, next to a TODO: Add input validation. The AI reviewer passed it, reading the TODO as a human’s deliberate note. Comments in the code are read as instructions too, which is prompt injection via code comments.
Should I let the agent write it?#
Be careful. Claude Code’s /init and similar commands draft a file from your code, and that is a fine start, but cut it down by hand. A February 2026 study of several coding agents found that context files written by a model tended to lower task success, while files written by developers helped slightly. Both made agents explore more and cost more. The authors’ advice: describe only minimal requirements.
Does Claude Code read AGENTS.md?#
Yes, in current versions, with one catch. Claude Code reads AGENTS.md when your project has no CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md in the working directory or above it. If you have one of those, it reads only the CLAUDE.md files.
To keep one shared file and still have a CLAUDE.md, put this line at the top of CLAUDE.md, with any Claude-only instructions below it:
@AGENTS.md
This also covers sessions where Claude Code can’t read AGENTS.md directly, which its docs describe for older versions and a few setups. A symlink from CLAUDE.md to AGENTS.md works too, but on Windows creating symlinks needs Developer Mode or administrator rights, so the import is simpler.
How do other tools read it?#
-
Codex reads
~/.codex/AGENTS.mdfor your personal defaults, then one file per directory from the project root down to where you are. Files closer to your current directory come later and win. A file namedAGENTS.override.mdreplacesAGENTS.mdin its directory. -
OpenCode loads global guidance, then discovers instruction files in the workspace and its ancestors. When it reads a file below the workspace, it also checks for instructions in the intervening folders. Each directory can supply
AGENTS.mdor fall back toCLAUDE.md. OpenCode instructions -
Gemini CLI, which Google now keeps for Gemini Code Assist licenses, reads
GEMINI.mdby default. Add this to.gemini/settings.json:{ "context": { "fileName": "AGENTS.md" } } -
Aider needs
read: AGENTS.mdin.aider.conf.yml. -
VS Code uses the discovery rules of the agent you select. The billing example below shows where Copilot, the original Local agent and Codex differ.
-
Cursor, Zed, Jules, goose, Junie, Warp, Devin, Amp and many others are listed on agents.md as supporting it. Check a tool’s own docs if it seems to ignore the file.
Does it work in a monorepo?#
Yes. Put shared rules at the root and the service’s test command inside its own folder. For example:
AGENTS.md Use pnpm throughout the repository.
services/billing/AGENTS.md Test billing changes with pnpm --filter billing test.
services/billing/src/invoice.ts The file you want to change.
Does GitHub Copilot read nested AGENTS.md files in VS Code?#
Yes. The shared Copilot harness is the default for new agent sessions in VS Code. Open the repository root and ask Copilot to change services/billing/src/invoice.ts: it picks up the billing test command as it works on that file. Other sessions discover the same file differently. VS Code’s explanation of the default agent
| Session | What happens to the billing instructions |
|---|---|
| Copilot in VS Code | The shared Copilot agent discovers instructions along the path to files it works with. When it works on invoice.ts, it combines the applicable root and billing guidance. |
| Original Local agent in VS Code | The root file requires chat.useAgentsMdFile. Nested discovery also requires chat.useNestedAgentsMdFiles, which is experimental and off by default. With both enabled, the agent sees a list of nested files and can load the billing file on demand. These settings affect Local only. |
| Codex | Codex builds its instruction chain at session start, from the root down to its working directory. Start the CLI with codex --cd services/billing to include both files. The billing instructions come later and take precedence where they conflict with the root file. |
VS Code nested instruction rules · VS Code settings · Codex instruction discovery
How do I know the agent read it?#
Ask. Start a session and type “Summarize the instructions you were given for this project.” Codex’s docs suggest exactly this check. In Claude Code, an interactive session shows a line naming the AGENTS.md it loaded when there is no CLAUDE.md.
If the agent ignores a rule, the rule is usually too vague or buried. “Run make test” works better than “make sure tests pass”. “Do not edit generated/” works better than “we usually avoid generated files”.
What AGENTS.md can’t do#
It is advice, not enforcement. The model can still ignore a line, especially late in a long session. If an action must never happen, such as pushing to main or reading .env, block it with your agent’s permission rules or hooks. See AI agent permissions.
It is also just a file in the tree, and an agent can change or delete it like any other. In the repository behind Contenox 1.0, 530 uncommitted paths once piled up in one working tree, and somewhere in them the file holding the repository’s own conventions had been deleted; nobody noticed for days, because nobody reads a 530-file diff. Commit small, and a change to AGENTS.md shows up in a diff short enough to read.
Where AGENTS.md came from#
AGENTS.md started in 2025 as a shared convention, so teams could stop keeping one instruction file per tool. In December 2025 OpenAI contributed it to the new Agentic AI Foundation under the Linux Foundation, alongside Anthropic’s MCP and Block’s goose. There is no required structure and no schema: it is just Markdown.
Related guides#
What is an AI coding agent?: the loop that reads this fileWhat is an AI coding agent? How it works, with an exampleWhat is an AI coding agent? A program that reads your code, runs commands and edits files in a loop until the task is done. How it works, and where it goes wrong.
AI agent permissions: for rules that must holdAI agent permissions: what to allow, ask and blockAI agent permissions for coding agents: a safe starting rule set, real config for Claude Code and Codex, the gaps in command rules, and when to skip prompts.
Keep secrets away from AI agentsHow to keep secrets away from AI agents (and out of git)How to keep secrets away from AI agents: block .env reads in Claude Code, OpenCode and Codex, stop keys leaking through commands, and what to do if one leaked.
AI coding costs: why a shorter file is cheaperAI coding costs: why agents burn tokens and how to cut itAI coding costs explained: why one agent session can send hundreds of millions of tokens, what sessions really cost, and the habits that cut the bill.
GlossaryAI coding glossary: agents, MCP, RAG, KV cache and moreAI coding glossary: plain definitions of the terms you meet when building software with AI agents, from ACP and AGENTS.md to prompt caching, RAG and worktrees.
AI codingAI coding: what it is, how it works, and the tools in 2026AI coding explained: the three kinds of tools (autocomplete, agents, app builders), which fits which job, what it costs, where it goes wrong, how to start.
What is an AI harness?What is an AI harness? Agent = model + harness, explainedWhat an AI harness is, what's inside one, an example loop in 20 lines, why the same model scores 14 points apart in two harnesses, and which harnesses exist.