What is an AGENTS.md file

By

Updated

Tagged: AI

Use AGENTS.md to give coding agents durable project instructions, from commands and conventions to scoped rules, verification, maintenance, and common mistakes.

AGENTS.md is a Markdown file that tells coding agents how to work in a repository.

Think of it as a README for the agent. The README explains the product to people, while AGENTS.md tells the agent which commands to run, which files to leave alone, and which traps to avoid when making changes.

There’s nothing special about the format. It’s just plain text in the repository root. What makes it work is that the knowledge lives next to the code, so every session reads it.

Durable repo memory is one habit that survived in what I learned using agentic AI.

Why the file exists

A new agent session starts with no memory of yesterday’s chat.

So it guesses the package manager, runs the wrong test command, edits a generated file, or misses a deployment constraint you explained last week. Then you have to explain it all over again.

AGENTS.md is where those corrections go once, so you stop repeating them:

repeated correction -> durable rule -> every future task sees it

The agent spends less time figuring out how the project works, and you spend less time fixing mistakes it didn’t need to make. I wrote about treating the second correction as a bug in the setup in Proton’s AI manifesto and what it means to lead coding agents.

Once those rules are in the file, give that setup a week of ordinary work before you change it again.

My AI fundamentals guide explains how durable rules fit with prompts, context, tools, and verification.

Create the first file

Put AGENTS.md in the repository root and start small:

# Project instructions

## Setup

- Install dependencies with `npm install`.
- Run the development server with `npm run dev`.
- Run the complete check with `npm test`.

## Code

- Application code lives in `src/`.
- Generated files live in `dist/`. Do not edit them.
- Use two spaces for indentation.

## Before finishing

- Run `npm test`.
- Report any test you could not run.

That’s already useful. The agent knows how to run things, where the code lives, what not to touch, and what to check before finishing.

You don’t need to document the whole system. Add the facts that would otherwise cost the agent a wrong guess.

What belongs in AGENTS.md

Put an instruction here if it’ll still be true next month, applies specifically to this project, and tells the agent what to do rather than giving vague advice.

Commands that really work

List the exact commands an agent should run:

## Commands

- `npm run dev`: start the site on port 3000.
- `npm run check`: validate Astro and TypeScript.
- `npm test`: run the test suite.
- `npm run build`: build the production site.

Explain any unusual requirements beside the command. If tests need Docker or a local database, say so.

Don’t write “run the tests” when the repository has five test commands. Name the exact command that proves the change is safe, which is often a focused check rather than the whole suite (How to speed up tests for AI coding agents).

A short architecture map

Point to the important boundaries. If a coding agent built the app, draw an architecture diagram of it and keep that map next to the project. Even a few lines help:

## Architecture

- UI components live in `src/components/`.
- HTTP routes live in `src/pages/api/`.
- Database access goes through `src/data/`.
- Do not query the database from UI components.

That last line is the most valuable part. The agent can discover the folder list by itself, but it can’t tell which layer is allowed to call which.

Project conventions

Record the choices an agent can’t infer from the language alone:

## Conventions

- Use `npm`, not `pnpm` or Yarn.
- Keep public API errors free of internal details.
- Add a migration for every schema change.
- Add a 301 redirect when deleting or renaming a public page.

A formatter can handle spacing. Save AGENTS.md for choices a formatter can’t make.

Safety boundaries

Spell out the actions that need special care:

## Safety

- Never print or commit secrets.
- Never write to the production database from local tests.
- Do not deploy unless the user explicitly asks.
- Ask before adding a production dependency.

Keep real permissions and sandboxing in place because an agent can still ignore a text file. What these lines do is tell a well-behaved agent which actions you consider dangerous in this project.

What does not belong

Skip secrets completely. AGENTS.md normally lives in version control and may be sent to an AI service along with your task, so credentials have no place in it.

Leave temporary status out too. Notes like this go stale fast:

- We are fixing checkout this week.
- Sara is reviewing pull request 42.
- The staging server is down today.

Put that kind of status in a ticket, a work log, or the current task instead.

The same goes for pasting entire manuals into the file. When the agent only needs the details occasionally, link to stable project docs instead:

## Deployment

- Follow `docs/deployment.md` for releases and rollback.
- Never force-push a release branch.

And don’t fill the file with rules a tool already enforces. If Prettier or Biome formats the code, the agent doesn’t need a bullet about indentation.

How scope works

Support differs between coding agents, so check the docs for the tool you use. OpenCode loads project instructions from AGENTS.md, while Cursor project rules and Claude Code’s .claude/rules/ scope instructions to matching files. The rules entry covers those files in Claude Code, Codex, Cursor, and Grok Build.

Codex builds its instruction chain in two parts.

First, it checks the Codex home directory, normally ~/.codex/, for global guidance. AGENTS.override.md wins when it exists; otherwise Codex reads AGENTS.md.

Next, it starts at the project root and walks down to the current working directory. In each directory, it checks AGENTS.override.md before AGENTS.md and reads at most one instruction file. Instructions from deeper directories appear later in the chain, so they can override broader project guidance.

The combined project instructions have a size limit (32 KiB by default in Codex). If a large root file is approaching that limit, move detailed procedures into focused documents and link to them instead of assuming every line will load.

This lets a monorepo define a general rule at the root and a narrower rule inside one package:

shop/
├── AGENTS.md
├── apps/
│   ├── storefront/
│   │   └── AGENTS.md
│   └── admin/
└── packages/
    └── payments/
        └── AGENTS.md

The root file might say:

- Use `npm` workspaces.
- Run `npm test` before finishing.

packages/payments/AGENTS.md can add:

- Treat amounts as integer minor units.
- Run `npm test --workspace payments` after payment changes.
- Never log payment payloads or webhook secrets.

Keep shared rules at the root, and add a nested file only when a subtree has different commands or constraints.

Some agents only read the root file. If a nested rule is critical across tools, keep a short version at the root and link to the detailed file.

Resolve conflicts deliberately

Instructions can disagree, and sometimes that’s intentional. Say the root file specifies:

- Use PostgreSQL for application data.

And a nested test fixture overrides it:

- Tests in this folder use SQLite. Do not replace it.

That narrower rule makes sense because its scope is clear.

Accidental conflicts are a different story. If one section says npm test and another says tests must never run locally, the agent has to guess which instruction is still current.

Delete old rules instead of stacking exceptions on top of them:

- Run `npm test`, except in old projects, unless CI is active, but only...

When a rule needs that many conditions, move the logic into a script and give the agent one command to run.

Write for execution

An agent reads the file to decide what to do next, so every rule should be something it can act on.

Compare these two. The first sounds careful and changes nothing:

- Be careful with content.

The second tells the agent exactly what to check, and why:

- Before deleting an image, search `src/posts/` for references.
- A missing referenced image makes the production build fail.

Same problem here:

- Follow best practices.

Nobody knows which practices you mean. Name the choice:

- Validate request bodies at the route boundary with Zod.
- Return `400` for invalid input.

The same habit helps one-off prompts. I wrote about that in What teaching can tell us about prompting.

Short bullets work best. Add the reason only when it changes how the agent applies the rule, like the build failure above.

Include verification

Every important rule should have a way to check it. For example:

## Content checks

- Run `npm run content:check` after editing posts.
- Run `npm run build` after adding images or internal links.
- Confirm future-dated posts do not link to later drafts.

Now the agent knows what to do and how to check the result. This catches changes that look done in the editor but fail during the build, like a post that links to a missing image.

Maintain the file from real mistakes

Don’t try to predict every future problem up front. Use a simple maintenance loop instead:

  1. Notice a correction you had to repeat.
  2. Decide whether it’s durable project knowledge.
  3. Put it at the narrowest useful scope.
  4. Remove any older instruction it replaces.
  5. Test it on the next relevant task.

Repeated corrections are strong candidates. A fix you needed for one unusual task usually isn’t.

Review the file whenever commands, deployment steps, or the architecture change, because a stale instruction sounds authoritative and will mislead the agent. If you use Claude Code, you can audit your instruction files with /doctor prompt-audit.

Common mistakes

The easiest trap is letting the file grow forever. Every rule seems worth adding at the time, until the agent is reading two thousand words before it even looks at the task. Keep the main file short enough to scan, and move long procedures into docs/ with a link.

Another common issue is writing preferences like hard rules. “Prefer small functions” is guidance, whereas “Never run migrations against production” is a real boundary. When every line sounds equally severe, the agent can’t tell which ones really matter.

Corrections also tend to stay trapped in chat. You point out a mistake, the agent agrees, and the next session repeats it because the rule never made it into the repository.

Commands go stale just as easily. Someone renames npm run check to npm run lint and nobody updates AGENTS.md. Run each command yourself after adding it and check again whenever scripts change, otherwise broken commands teach the agent to ignore the file.

And if a rule relies on tool-specific behavior, say which tool it applies to. Nested-file discovery and precedence differ between agents, so mark anything that only works in Codex or Cursor.

How I use AGENTS.md

I treat AGENTS.md as the memory of the repository.

I put the build commands there, sure, but the most valuable lines are usually the odd project quirks: a configuration name that has to match a hosted project, a folder that looks generated but isn’t, or a redirect rule that needs to stay at the end of a file.

Those details are easy to forget after three months, and they’re expensive for an agent to rediscover by breaking something.

I don’t use the file as a daily to-do list. Plans and current work belong elsewhere. AGENTS.md holds the facts I still expect to be true next month, plus a pointer to project decision records when the reasoning matters.

It’s also a poor fit for product documentation meant for customers. When an agent needs the site’s content, I point it at Markdown versions of the site or the source files directly, and keep AGENTS.md focused on how to work in the repo.

A practical final template

Use this as a starting point:

# Project instructions

## Setup

- Install with `npm install`.
- Start development with `npm run dev`.

## Project map

- Application code: `src/`
- Tests: `tests/`
- Operational docs: `docs/`
- Generated output: `dist/` — do not edit.

## Rules

- Keep changes inside the requested scope.
- Never commit secrets or `.env` files.
- Ask before adding production dependencies.

## Verification

- Run `npm test` after code changes.
- Run `npm run build` after routing or content changes.
- Report skipped checks and the reason.

Delete the lines that don’t apply to your project, and add new ones as corrections come up in real sessions.

Want me to talk about your product? You can sponsor this site.

Related posts about ai: