Sub topic 4
What to put in AGENTS.md
This chapter assumes you know basic Git and repository layout, you are comfortable with Markdown, and you have run build and test commands from a terminal. It also assumes you have used an AI coding assistant at least once.
The goal: facts the agent cannot guess
An agent can read your source files, but it cannot tell from them which command runs the tests, which directories are off limits, or what your reviewers expect in a pull request. AGENTS.md is the place for that information. Include what a new teammate would need on day one, and leave out what the agent can see by reading the code.
The file is plain Markdown with no required fields. Most useful files cover six areas.
| Area | Question it answers | Example |
|---|---|---|
| Project overview | What is this and what is it built with? | TypeScript, Node.js 20, PostgreSQL |
| Setup | How do I get a working environment? | `npm ci` |
| Build and test | How do I check my work? | `npm test`, `npm run lint` |
| Code style | Which rules does the linter not enforce? | Named exports only |
| Project structure | Where does each kind of code live? | `src/services/` |
| Pull requests | What must a change include? | Tests, a title format |
A compact example
This file covers all six areas in under 30 lines.
# 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`.Section by section
Project overview
Write one or two lines: what the project does, the language, the runtime version, and the main datastore. This tells the agent which conventions to assume. Do not paste a full README.
Setup, build, and test
These sections matter most. An agent that does not know your commands will guess, and a wrong guess wastes a run or produces a false "all tests pass". Give exact commands in backticks.
Include the single-file test command. Agents iterate on one change at a time, and running the whole suite after every edit is slow. State the check to run before finishing, here npm run lint && npm run typecheck, so the agent verifies its own work.
Code style
List only rules that a formatter or linter does not already enforce. If Prettier handles indentation, do not describe indentation. Good entries are decisions a reader could not infer from one file, such as "no default exports".
Project structure
Name the main directories and what belongs in each. Add constraints that prevent damage. The line "never edit an existing migration" is more valuable than a directory listing, because breaking it corrupts a database history.
Pull request conventions
Record what reviewers check: required tests, title format, and any changelog rule. The agent can then produce a change that passes review without edits.
Common errors
- Missing commands. The file describes the project but never says how to run tests. Add the exact commands.
- Duplicating the linter. Long style lists that tooling already enforces use space and add nothing.
- Stale commands. A renamed script makes the agent fail or improvise. Treat commands as code that needs updating.
- Writing a README. Marketing text and history do not help an agent act. Keep what changes its behavior.
Exercise
A repository's AGENTS.md says "Follow best practices and make sure everything works." Name two of the six areas it is missing, and write one concrete line for each.
Show answer
Any two of these. Build and test: "Run npm run lint && npm test before finishing and fix any failures you introduced." Setup: "Install dependencies with npm ci." Project structure: "Business logic goes in src/services/; route handlers stay thin." Pull requests: "Use the title format [area] Short description." Each line names an exact command or location that the agent can follow and a reviewer can check.