Sub topic 2
What AGENTS.md is
Prerequisites
This chapter assumes you know basic Git and repository layout, can read Markdown, and have used an AI coding assistant at least once. You do not need to have written any instruction file before.
The problem AGENTS.md solves
A coding agent is a tool that reads your repository, runs commands, and edits files on your behalf. It can read source code quickly. It cannot guess the things that are not written in the code. Examples are which command runs a single test, which directory holds business logic, or which migrations must never be edited.
Without that knowledge, an agent tends to guess. It might run the wrong test command, add a default export in a codebase that bans them, or edit a migration that has already shipped. You then spend time correcting work that could have been right the first time.
AGENTS.md addresses this. It is a plain Markdown file in your repository that tells agents how to build, test, and work in that codebase. Think of it as a README written for an agent. A README introduces the project to people. AGENTS.md gives an agent the operational details it needs to do a task correctly.
How an agent uses the file
Many coding agents look for AGENTS.md when they start work in a repository. They read it and add its contents to their working context, so the instructions are present before the first edit or command.
Because the file lives in the repository, it is versioned with the code. Everyone who clones the repository gets the same instructions, and changes to the instructions go through the same review as code changes.
A first example
This is a compact AGENTS.md for an invoice-processing API.
# AGENTS.md
## Project overview
Web API for invoice processing. TypeScript, Node.js 20, PostgreSQL.
## Setup
- Install dependencies: `npm ci`
- Start the local database: `docker compose up -d db`
## Build and test
- Build: `npm run build`
- Run all tests: `npm test`
- Run one test file: `npm test -- path/to/file.test.ts`
- Lint and type-check before finishing: `npm run lint && npm run typecheck`
## Code style
- Use named exports; do not add default exports.
- Keep route handlers thin and put business logic in `src/services/`.
## Project structure
- `src/routes/`: HTTP handlers
- `src/services/`: business logic
- `migrations/`: database migrations (never edit an existing migration)
## Pull requests
- Add or update tests for every behavior change.
- Use the title format `[area] Short description`.Each section answers a question the agent would otherwise have to guess:
| Section | Question it answers |
|---|---|
| Project overview | What kind of project is this, and what stack does it use? |
| Setup | How do I get a working environment? |
| Build and test | How do I check that my change works? |
| Code style | Which conventions are specific to this codebase? |
| Project structure | Where does each kind of code belong? |
| Pull requests | What must a change include before review? |
What AGENTS.md is not
- It is not a configuration format. The file has no required fields and no schema. An agent reads it as text, the way a person would.
- It is not enforcement. The file guides the agent. It does not stop the agent from breaking a rule. Keep your linter, type checker, tests, and code review in place.
- It is not a replacement for the README. Keep user-facing documentation in the README. Put agent-facing, operational detail in AGENTS.md.
- It is not a place for secrets. Anyone with repository access can read it, and agents may include its contents in requests to a model provider.
Why a dedicated file helps
You could paste the same guidance into every prompt. A file is better for three reasons.
- It is written once. You do not retype build commands for every task.
- It is shared. Teammates and their agents work from the same rules.
- It is reviewable. When a rule is wrong, you fix it in a pull request, and the history shows why it changed.
A dedicated file also keeps the instructions in one predictable place. Agents and people both know where to look.
Common mistakes at this stage
- Writing a long essay about project history. Agents need commands and rules, not background.
- Listing commands that no longer work. A stale command is worse than a missing one because the agent trusts it.
- Describing the whole codebase. Describe only what an agent cannot easily infer from reading the code.
The following chapters cover the file format, what to include, how to write instructions an agent can act on, and how to place files in a larger repository.
Exercise
A teammate says, "We don't need AGENTS.md because our README already explains the project." Give two reasons AGENTS.md is still useful, and name one thing it cannot do.
Show answer
It is useful because it holds agent-focused operational details the README may omit, such as the exact command to run one test file or which directories must not be edited. It is also versioned with the code, so every teammate and every agent gets the same instructions, and changes are reviewed like code. It cannot enforce rules: it only guides the agent, so linters, tests, and code review are still needed. (Another valid limit: it must not hold secrets.)
Exercise
Look at this line from an AGENTS.md: "Run the tests properly before you finish." Which question from the table does it try to answer, and why is it weak?
Show answer
It tries to answer the Build and test question: how do I check that my change works? It is weak because it names no command. The agent has to guess what "properly" means, and a reviewer cannot check whether the instruction was followed. A better line is: "Run npm run lint && npm test before finishing."