AGENTS.md from codebase
Produce a short, accurate map of the repository for coding agents. Every line must come from something you read or ran in this repo. A wrong command in AGENTS.md is worse than none, because agents trust it.
1. Read before you write
Work through these and take notes. Skip what does not exist.
- What it is:
README*, the package manifest (package.json,pyproject.toml,Cargo.toml,go.mod,*.csproj,pom.xml,build.gradle), top-level folders (ls, then one level into the main source folders). - How to run things: scripts in the manifest,
Makefile/justfile/Taskfile,.github/workflows/*(CI shows the commands that really gate merges),Dockerfile,docker-compose*,.env.example. - Conventions: linter and formatter configs (
eslint,biome,prettier,ruff,mypy,tsconfig,.editorconfig), test layout and naming,git log --oneline -30for commit style,CONTRIBUTING.md, PR templates. - Existing agent files:
AGENTS.md,CLAUDE.md,.cursor/rules,.cursorrules,.github/copilot-instructions.md. Keep what is still true; mention conflicts to the user instead of silently overwriting them. - Architecture rules: monorepo workspaces, layering (for example "domain must not import from web"), generated files that must not be edited by hand, and where secrets and config come from.
2. Verify the commands
Run the install, lint, type-check and test commands you are about to document (with the user's permission if they are slow, need network or touch services). Record what passed. If a command fails on a clean checkout, write it down as a known issue rather than leaving it out. Never invent a command that you have not seen in the repo.
3. Write AGENTS.md
Use the structure in references/template.md. Keep it under about 150 lines: agents read it at the start of every task, and a long file costs tokens and attention each time.
- Commands first, exact and copy-pasteable, including how to run a single test.
- Map, not tour: one line per important folder saying what lives there and what does not.
- Rules as instructions: "Run
npm run checkbefore finishing", not "We value quality". - Traps: things that already went wrong or easily will (generated files, a slow test suite to skip, a port that must be free, an env var that must be set).
- Definition of done: the exact checks that must pass before the agent says it is finished.
- Link to deeper docs instead of copying them.
4. Wire it up for other agents
AGENTS.md is read natively by many agents. For the ones that look elsewhere, offer (do not force) a pointer instead of a copy, so there is one source of truth:
- Claude Code:
CLAUDE.mdcontaining@AGENTS.md, or the user's existing CLAUDE.md with that line added. - Cursor: a rule in
.cursor/rules/that references AGENTS.md. - GitHub Copilot:
.github/copilot-instructions.mdpointing to AGENTS.md.
5. Hand over
Tell the user what you documented, which commands you ran and their result, and anything you were unsure about (marked in the file with TODO(confirm): so it is easy to find). Do not commit unless asked.
Refreshing an existing AGENTS.md
Diff the file against the repo: commands that no longer exist, folders that moved, rules the code now breaks. Update in place, keep the author's wording where it is still correct, and list what you changed.