Skip to content
AI Skills Central

Type to search Agent Skills, workflows, tutorials, tools and the glossary.

Workflow recipe

Write a useful AGENTS.md: example, template and test

An AGENTS.md example and template with build and test commands, conventions and traps, plus a before-and-after task that shows whether the file actually helps.

By Checked Beginner30 min6 steps
Bookmark

Bookmarks are kept in your free account, so you can find this page again on any device.

Sign in to bookmark
On this page

A useful AGENTS.md is a short file with the commands that build and test the project, the conventions an agent cannot guess and the traps that have bitten people. To write one, collect working commands, let the agent draft it and cut half, shape it to a template, point Claude Code at it and test it on a real task.

An instruction file is loaded into every session, so each line costs context on every task. The useful ones are short and specific: the commands that build and test the project, the conventions an agent cannot guess, and the traps that have bitten people before. The useless ones restate what the agent already knows (“write clean code”) or describe the architecture in essay form.

AGENTS.md is read by Codex, Cursor and many other agents. Claude Code reads CLAUDE.md, and since v2.1.277 it also reads AGENTS.md when there is no CLAUDE.md. This recipe produces one AGENTS.md that works everywhere, plus a one-line CLAUDE.md if you need it.

TerminalAbout 5 min

1. Collect the commands that actually work

Run every command you are about to write down. Agents follow instruction files literally, so a stale command wastes more time than a missing one.

# Note the exact form of each one that succeeds
npm ci
npm run build
npm test
npm test -- path/to/one.test.ts   # how to run a single test file
npm run lint

Write down the single-test form in particular. Agents run the whole suite by default, which is slow and floods the context with output.

Agent chatAbout 5 min

2. Let the agent draft it, then expect to cut half

Both Claude Code and Codex have an /init command that scans the repository and writes a starting file. Use it for the draft, not the final version.

Run /init in the Codex CLI. It writes an AGENTS.md scaffold in the current directory.

Then ask for a ruthless edit:

Trim the draft · Any coding agent
Edit AGENTS.md so that every line passes this test: would a capable engineer new to this repo get it wrong without this line? Keep: exact build, test, single-test and lint commands; where things live when it is not obvious; conventions that differ from the language default; known traps. Delete: general advice, descriptions of what the code does, anything a linter or the type checker already enforces, and anything you could not verify by running a command or reading a file. Target under 60 lines. Show me the diff before writing.

EditorAbout 10 min

3. Shape it to a template you can keep up to date

A layout that works for most repositories, filled in for a TypeScript web app. Replace every value with yours.

# AGENTS.md

## Commands
- Install: `npm ci`
- Dev server: `npm run dev` (http://localhost:4321)
- Build: `npm run build`
- Test all: `npm test`
- Test one file: `npm test -- tests/unit/pricing.spec.ts`
- Lint and types: `npm run check` (run before saying a task is done)

## Layout
- Pages: `src/pages/`. API routes: `src/pages/api/`.
- Database schema: `src/db/schema/`. Never edit files in `drizzle/migrations/` by hand; run `npx drizzle-kit generate`.

## Conventions
- TypeScript strict. No `any`; use `unknown` and narrow.
- Dates are stored in UTC and formatted with `formatDate()` from `src/lib/dates.ts`.
- New UI uses the components in `src/components/ui/`. Do not add CSS files.

## Traps
- `npm test` needs Postgres running: `npm run db:local` first.
- The CSP blocks inline scripts and styles. Do not add `style="..."` attributes.

## Done means
- `npm run check` and the relevant tests pass.
- No new dependencies without saying why.

Keep the “Done means” section. It is the cheapest way to stop an agent declaring victory before the tests run.

EditorAbout 2 min

4. Make Claude Code read the same file

You have two options.

If the repository has no CLAUDE.md, recent Claude Code versions load AGENTS.md automatically and print a line saying so at the start of an interactive session.

If you also want Claude-specific notes, create a CLAUDE.md that imports the shared file, so both stay in sync:

@AGENTS.md

## Claude Code only
- Use plan mode for changes that touch more than three files.

Once a CLAUDE.md exists, Claude Code reads it instead of AGENTS.md, so the @AGENTS.md import line is what keeps the shared rules loaded.

Agent chatAbout 6 min

5. Run a before-and-after test on a real task

Pick one small task from your backlog, such as adding a field to a form with a test. Commit the new file, then run the task twice in fresh sessions, in two throwaway worktrees: one with the file removed, one with it.

git worktree add ../try-without HEAD --detach
rm -f ../try-without/AGENTS.md ../try-without/CLAUDE.md
git worktree add ../try-with HEAD --detach

# Start a fresh agent session in each folder and give it the same task.

# Afterwards, throw both away:
git worktree remove --force ../try-without
git worktree remove --force ../try-with

Give the same task prompt both times and record four things for each run: did it use the right test command, did it run the checks before finishing, how many times you had to correct it, and how many files it touched that it should not have.

If the “with” run is not clearly better on at least one of those, the file is not doing its job. Look at the correction you had to make and turn it into a line.

RepositoryAbout 2 min

6. Keep it alive

Treat the file like code. Two habits keep it useful:

  • When you correct an agent for the same mistake twice, add one line to “Traps” or “Conventions”.
  • When a command changes (a new test runner, a renamed script), update the file in the same pull request.

Large repositories can add nested AGENTS.md files in subdirectories. Codex reads files from the repository root down to the directory it is working in, so put package-specific rules next to the package. Codex stops reading instruction files after 32 KiB by default, which is another reason to stay short.

Check it worked

Verification checklist

0 of 6 done

When it goes wrong

If the agent ignores a rule, the rule is usually vague or buried. Make it concrete (“run npm run check before finishing”) and move it near the top. Very long files reduce adherence: Anthropic’s guidance for CLAUDE.md is to stay under 200 lines, and shorter is better.

If Claude Code does not seem to read AGENTS.md, check for a CLAUDE.md or CLAUDE.local.md anywhere from your working directory up to the repository root. Any of them makes Claude Code skip AGENTS.md, so add the @AGENTS.md import to it.

If the file goes stale, it does harm. An agent that follows an old test command will report failures that are not real. Add “update AGENTS.md” to your pull request template for changes to tooling.

Variations

For a monorepo, keep the root file to repository-wide commands and add a short AGENTS.md in each package with that package’s test command and conventions.

For personal preferences that should not be committed, Claude Code reads CLAUDE.local.md (add it to .gitignore) and Codex reads ~/.codex/AGENTS.md for global rules.

If you want an agent to draft and maintain the file for you, the agents-md skill packages a set of rules for writing these files.

For how to write CLAUDE.md and how it differs from AGENTS.md, read CLAUDE.md and AGENTS.md. The AGENTS.md format page describes the open format itself, and Agent Skills vs MCP vs AGENTS.md explains what belongs in it and what belongs in a skill. Context engineering basics covers why shorter files work better. If you are new to the repository yourself, understand a codebase with AI first, then write down what the map taught you. More recipes are in the AI workflow examples hub.

Outcome and tools

Outcome
A short instruction file with exact commands and conventions, tested on a real task.
For
Developers
Variants for
Claude Code, Codex, Cursor

Check your understanding

Write a useful AGENTS.md quiz

What belongs in an instruction file, working commands, using /init and cutting the draft, the Done means section, making Claude Code read AGENTS.md, testing the file and keeping it current.

8 questions · pass mark 70%

Question 1 of 80 answered
  1. Why should an AGENTS.md be short?
  • CLAUDE.md and AGENTS.md: instruction files for coding agents

    CLAUDE.md vs AGENTS.md: what to put in each, where Claude Code, Codex, Cursor and Copilot look for them, and how to keep one source of truth without drift.

    TutorialBeginner20 min

  • Context engineering techniques: what the model should see

    What to put in a model's context at each step, what to leave out, and how instruction files, retrieval and tools fit.

    TutorialIntermediate30 min

  • AGENTS.md

    An open, tool-neutral Markdown file of instructions for coding agents working in a repository, read by many different agents and editors.

    Glossary

  • CLAUDE.md

    Claude Code's instruction file, read at the start of a session from the project and user directories, so standing rules apply every time.

    Glossary

Back to top