You Keep Telling It the Same Thing

Every session starts the same way. You tell the agent the tests run with pnpm test:unit, not npm test. You tell it not to touch the generated client. You tell it the team stopped using the old repository pattern last year. Then a colleague opens a session and has the same conversation, and the agent still reaches for the old pattern, because it can see forty examples of it in the code.

Repo instructions are the fix, and they are the highest-value file you can add for coding agents. A small Markdown file at the root of the repo tells every session what a new team member would need on their first day. The difference from a README is the audience: it's written for an agent that can run commands, and it covers what humans pick up by osmosis.

You need this if
  • You repeat the same corrections in every session
  • Agents copy old patterns from your codebase
  • The team uses several different coding tools
  • Your instructions file has grown past the point where anyone reads it

AGENTS.md Is the Shared Format

AGENTS.md is an open format described as a README for agents, used by more than 60,000 open-source projects and now stewarded by the Agentic AI Foundation under the Linux Foundation. It has no required fields, because it is plain Markdown. Tools that read it include Codex, Cursor, GitHub Copilot's coding agent, VS Code, Gemini CLI, Jules, Windsurf, Zed, Devin and JetBrains Junie.

Claude Code uses CLAUDE.md first. From v2.1.277 it reads AGENTS.md directly when no CLAUDE.md applies, so a repo with only AGENTS.mdneeds no extra file. If you have both, keep one source of truth and import it, so the two can't drift apart:

<!-- CLAUDE.md -->
@AGENTS.md

## Claude-specific
Use subagents for broad codebase searches.

Some tools need a nudge. Gemini CLI takes "context": { "fileName": "AGENTS.md" } in .gemini/settings.json, and Aider takes read: AGENTS.md in .aider.conf.yml.

What Belongs in It

# AGENTS.md

## Commands
- Install: pnpm install
- Test one file: pnpm test:unit path/to/file.test.ts
- Before committing: pnpm lint && pnpm typecheck

## Rules
- Never edit src/generated/. Run pnpm codegen instead.
- New data access uses the query layer in src/db/queries. Do not copy the
  repository classes in src/legacy/.
- Migrations are additive. Removing a column takes two releases.

## Gotchas
- Integration tests need Docker running.
- The payments module has its own AGENTS.md. Read it before changing it.

## Pull requests
- Title format: [area] what changed
- Keep each PR to one change.

Every line should pass one test: would the agent get this wrong without it? Commands, things that look safe and aren't, and decisions that the code doesn't reveal all pass. “Write clean code” doesn't. Neither does a description of your folder structure, because the agent can read that itself.

KeepCut
Exact commandsGeneral advice about good code
Rules with a reason the code doesn't showWhat a linter already enforces
Traps specific to your repoFile-by-file descriptions
Pointers to deeper docsThe deeper docs themselves

Keep It Short

This file loads on every session, so each line competes for attention with the task. A 900-line instructions file is the same mistake as a bloated system prompt: the rule you care about is buried, and the model treats it as a suggestion. I try to stay under a couple of hundred lines. When a procedure only applies to some tasks, move it into an Agent Skill, which loads on demand.

In a monorepo, put another AGENTS.md in each package. The format's rule is simple: the closest file to the code being edited wins, and explicit chat prompts override that repo guidance, though not the higher-priority rules a tool sets for itself.


flowchart TD
    R["AGENTS.md at the root<br/>commands, global rules"] --> A["packages/api/AGENTS.md<br/>API conventions"]
    R --> W["packages/web/AGENTS.md<br/>UI conventions"]
    A --> P["packages/api/payments/AGENTS.md<br/>closest file wins"]
    S["Skills<br/>load on demand"] -.-> R
      

Make It a Rule, Not a Request

An instruction is advice, and agents will occasionally ignore it. If something must always happen, enforce it with a tool: a linter rule, a pre-commit hook, a CI check, or a harness hook. The instructions file can explain why the rule exists, while the check makes sure it holds. “Never commit secrets” in a Markdown file is a hope. A secret scanner in CI is a control.

What Goes Wrong

⚠️ Common Mistakes

1. Generating it and never reading it

Starting from a generated file is fine, but they tend to be long and generic. Delete everything the agent could work out by itself, then treat what is left like code.

2. Letting it rot

A stale command wastes a turn on every session, and a stale rule teaches the wrong thing with authority. Review it when your tooling changes, and let pull requests touch it.

3. Treating it as trusted when it isn't yours

The agent follows this file, so a poisoned AGENTS.md in a cloned repo or a dependency is a prompt injection with a head start. Read it before you run an agent in a repository you don't trust.

4. Fighting your own codebase

If the code shows forty examples of the old way, one line of instruction may lose. Point at the file that shows the right way, and migrate the examples when you can.

How to Tell Whether Your File Works

Most instruction files are never tested, so nobody knows which lines matter. There's a simple check. Pick a small, real task. Run it in a fresh session with the file, and again without it, and count the corrections you had to make in each. If the numbers are about the same, the file isn't earning its tokens.

You can test one rule the same way. Delete a line and run a task that depends on it. If nothing changes, that line was doing nothing, or the agent could already work it out from the code. Delete it for good.

Read your agent's session logs now and then too. They show where it wasted turns: running the wrong command, searching for a file you could have named, or trying something that was never going to work. Each of those is a candidate for one short line.

Secrets and sensitive paths

This file is committed, and it's sent to a model on every session, so it must never hold credentials, internal hostnames you'd rather not expose, or customer details. Say where things are, not what they are. If some paths must stay off limits, put that in your tool's permission settings, because a sentence asking the agent to keep out is only a request. Permissions enforce it.

For an open-source project, remember that contributors' agents read this file as well. A clear AGENTS.md raises the quality of the pull requests you receive, and that's a real benefit for maintainers.

What I Would Do First

Write down the last five corrections you gave an agent, and start the file with those plus your exact test and lint commands. That will likely fit in twenty lines, and it is better than most generated files. Then make a habit of it: when you correct an agent twice, add a line.