How to write AGENTS.md
Give AI agents a clear guide to your projects. Learn what to include in AGENTS.md and how to organize your instruction and which common mistakes to avoid.
- Published
- Published:
- Updated
- Updated:
- minute read
- 4 minute read
Many developers now use an AGENTS.md file in their projects. But asking an AI to generate one can produce a long file full of instructions an agent could have figured out on its own. That costs time and context without helping the work.
Here’s how to keep AGENTS.md useful, and when to put more detailed guidance elsewhere.
#What is AGENTS.md?
AGENTS.md is a Markdown file that gives coding agents instructions and context about a project. Think of it as a README.md for agents: it can identify the project’s conventions, the package manager it uses, relevant checks, and rules an agent might otherwise miss.
The format grew out of collaboration across the AI coding agent ecosystem, including OpenAI Codex. Tools do not all discover or apply these files in the same way, so check how yours handles them before relying on a particular folder structure.
#Keep it small
Project instructions may be loaded into an agent’s context. Keep the file focused on information that helps across many tasks, especially nonstandard rules the agent cannot safely infer from the code.
For example, tell an agent if a directory contains generated code that must be changed through a schema, if a migration requires a particular review process, or if a package has an unusual test setup. These details can prevent mistakes. Routine instructions such as how to run a dependency install command usually add little value.
#Reference other files
Suppose your project has detailed conventions for CSS, routing, and components. Many tasks will need only one of those topics. Keep the details in separate documents and say when to read each one:
- For CSS changes, read docs/css-conventions.md.
- For routing changes, read docs/routing.md.
- When creating a component, read docs/components.md.
A link alone does not guarantee that an agent will open the file. State when it is relevant, and check that your tool follows references or imports.
#Avoid duplicate instructions
If you use instruction files for different tools, avoid copying the same rules into each one. Copies can drift apart. Where your tools support it, keep one source of truth and link or import it from the others.
For example, in Windows Command Prompt:
mklink CLAUDE.md AGENTS.md
On macOS or Linux:
ln -s AGENTS.md CLAUDE.md
Both examples make CLAUDE.md point to AGENTS.md. Check that your agent supports this setup.
#Use nested instruction files when they help
Put project-wide rules at the root and folder-specific rules near the code they apply to. Different coding tools discover nested instruction files differently. For example:
- Codex loads
AGENTS.mdfiles from the project root down to the directory where you start the session. To load instructions in a deeper folder, start Codex there. In the same directory,AGENTS.override.mdtakes priority overAGENTS.md. Codex documentation - Claude Code loads
CLAUDE.mdfiles in the working directory and its parent directories at startup. It loads a nestedCLAUDE.mdwhen it works with a file in that folder. Recent versions can also readAGENTS.md, subject to their project instruction settings. Claude Code documentation
Check how your tool loads nested files before depending on a folder-specific rule.
#AGENTS.md is for durable project guidance
Use AGENTS.md for conventions and exceptions that should guide many tasks. Name the dependency manager your project uses such as pnpm or Bun so an agent works with the right lockfile. You do not need to spell out a routine command like npm install.
A small file could look like this:
## Project instructions
This project is a bilingual portfolio with a public website and an admin area for managing projects and articles. The web app handles presentation; the API handles content and authentication.
- Use pnpm for dependency management.
- The files in src/generated/ come from the schema. Edit the schema and regenerate them instead of editing those files directly.
- For CSS changes, read docs/css-conventions.md.
- For new components, read docs/components.md.
For a detailed process tied to one kind of task, a Skill may be a better fit. Some tools use a skill folder containing a SKILL.md file and supporting resources.
The aim is to give an agent the few project facts it needs to avoid wrong assumptions, then point it to deeper guidance when the task calls for it.
Related articles
In this post, we’ll explore four TypeScript concepts: discriminated unions, utility types, generics, and the differences between as, satisfies, and is. We’ll learn what they are, how they work, and how they help us write safer code through practical examples.
11 minute read
Read article