How to write an AGENTS.md file that stops the re-explaining

A short file of commands, conventions and settled decisions that every agent reads before it starts.

By · Published

AGENTS.md is a Markdown file at the root of a repository that tells coding agents how to work in it: the exact commands, the conventions the code does not show, and the decisions that are settled. Codex, Cursor and other agents read it before they start, so you write the context once instead of in every conversation.

This guide covers where to put the file, how to write instructions agents follow, an annotated example, and how it relates to README.md and CLAUDE.md.

What is AGENTS.md for?

AGENTS.md is an open format, described on agents.md as a README for agents. Codex reads AGENTS.md files before doing any work, and Cursor lists it as a source of rules. Claude Code reads it when there is no CLAUDE.md (Claude Code memory documentation).

It is instructions, not documentation for people: short, directive and maintained like code.

Where should AGENTS.md go?

Put one at the repository root for rules that apply everywhere. In a monorepo, add one in a package or service folder for what only matters there, such as a different test runner. Codex reads files from the root down to the working folder, and the closer file overrides the earlier one; Cursor also gives the more specific file precedence. Keep nested files short and never contradict the root.

How do you write instructions agents follow?

Write commands, not descriptions. "The project uses pnpm" is a fact an agent can overlook; "Always use pnpm, never npm" is a rule it can follow. Give every line a testable outcome: "Run pnpm test before committing", "Never edit files in generated/", "Ask before adding a dependency".

Keep it short. Every line shares the context window with your code. Claude Code's guidance for CLAUDE.md is under about 200 lines, and Codex reads at most 32 KiB of project instructions by default. Cut anything the agent can learn by reading the repository.

An annotated AGENTS.md example

Build and test commands

## Build and test
- Install: `pnpm install --frozen-lockfile`
- Dev server: `pnpm dev` (port 3000; do not change it)
- One test file: `pnpm vitest run path/to/file.test.ts`
- Before every commit: `pnpm test && pnpm lint`

Without exact commands, agents guess: one runs npm install, another rewrites the lockfile, a third starts a server on a port your other checkouts use. The single-file test command matters because an agent that only knows the slow full suite tends to skip tests. "Do not change the port" looks trivial, but an agent that cannot bind port 3000 may "fix" your configuration and break your deploy script.

Conventions and guardrails

## Conventions
- TypeScript strict mode; no `any` without a comment explaining why
- Server code lives in `src/server/`; never import it from components
- Never edit `generated/` or `migrations/` by hand
- Never run `git push --force`
- Never delete or skip a test to make the suite pass

The last three lines are the ones that save you. Deleting a flaky test can look like a legitimate fix to a model; written down, it becomes a rule violation instead of a surprise.

Settled decisions

## Settled decisions (do not reopen)
- 2026-05: Drizzle, not Prisma. We need raw SQL.
- 2026-07: Session cookies, not JWT.
- 2026-09: No state machine library.

Without this section, each new conversation can reopen a closed debate. Date each entry. When a decision changes, rewrite the line instead of adding a contradiction.

What should you leave out?

  • Anything the code already shows, such as file listings or function names.
  • Marketing copy and long architecture essays.
  • Anything stale: a wrong instruction is worse than none, because the agent follows it.
  • Secrets. AGENTS.md is read by every agent and everyone with the repository. Write how the agent gets access, not the key. If agents must use keys without seeing them, that is a job for a broker, as in API keys for local development.

How is AGENTS.md different from README.md and CLAUDE.md?

File Read by Belongs there
README.md People What the project does, setup, license
AGENTS.md Coding agents Commands, conventions, guardrails, settled decisions
CLAUDE.md Claude Code Claude-specific additions, or a line importing AGENTS.md

If you keep both agent files, put the shared instructions in AGENTS.md and write @AGENTS.md in CLAUDE.md: Claude Code imports the file, and every agent reads the same rules. The comparison of AGENTS.md, CLAUDE.md and Fileaify covers what goes beyond the repository.

How do you test and improve the file?

Treat it like code. Save the exact prompt that went wrong, change one line, and rerun the prompt in a new conversation. If the behavior improves twice in a row, keep the line. If not, the rule is usually phrased as a description or buried under a heading the agent skims. After three failed rewrites, move the rule to a hook or a CI check, where it cannot be ignored. Commit every change so it has a diff and a reason.

Where does AGENTS.md stop?

AGENTS.md is static text in one repository. It holds no conversation history, no credentials and no record of which agent changed what. A lesson one agent learns stays invisible to the others until someone edits the file.

That is where a shared project record helps. Fileaify keeps decisions, current state and services in a hosted workspace that agents read over MCP or REST and update through reviewed proposals, with keys held in a vault. It is one more service to run, while AGENTS.md costs nothing: if your context fits in the file, keep it there.

Sources

Try it

The demo runs on a prepared project, with no account. To keep decisions beyond the repository, create a free workspace and give your agent https://fileaify.com/agent.

Common questions

Do all coding agents read AGENTS.md?

No. Codex and Cursor read it, and so does opencode. Claude Code reads it when the project has no CLAUDE.md; otherwise add @AGENTS.md to CLAUDE.md. Check each tool's documentation.

Should CLAUDE.md point to AGENTS.md?

If you keep both, yes: a CLAUDE.md that contains @AGENTS.md imports the shared file, so Claude Code reads the same instructions as your other agents.

How long should AGENTS.md be?

As short as it can be while staying complete. Claude Code recommends under about 200 lines for CLAUDE.md, and Codex stops reading project instructions at 32 KiB by default.

Can I put API keys in AGENTS.md?

Never. It is a plain file every agent and every reader of the repository sees. Say how the agent obtains access instead.

Written with AI assistance, reviewed by Stéphane Mermet and checked against the product. Fileaify publishes this guide and sells the service it describes.