← All posts

What Is AGENTS.md? How to Configure AI Coding Agents

AGENTS.md is a plain Markdown file, usually at your repository root, that tells AI coding agents how to work in your project: which commands to run, how the code is organized, which conventions to follow, and what never to touch. Agents read it automatically when a session starts, before you type your first prompt — so the rules apply to every task, not just the ones you remember to paste them into.

OpenCode and Codex CLI read AGENTS.md natively. Claude Code reads it too, as of version 2.1.277, when no CLAUDE.md is present. If you have ever re-explained "run npm test, don't touch next.config.mjs, keep components server-side" in every chat, this file is the fix.

What goes in an AGENTS.md

Think of it as the onboarding document you wish every new engineer read on day one. The useful contents fit in five buckets:

  • Commands — install, dev, lint, typecheck, test, build. Copy-pasteable, exactly as CI runs them.
  • Architecture — a three-line map: where routes live, where shared code lives, where business logic goes.
  • Conventions — naming, file layout, error handling, typing rules — the things linters can't enforce.
  • Testing expectations — what to run before you're done, what to mock, what must never hit the network.
  • Guardrails — files or areas that need a human, dependencies that need approval, secrets that never get committed.

Everything else — tutorials, marketing copy, the whole README — stays out. An instruction file is loaded into the model's context on every request; every line you don't need costs attention you could spend on the rules that matter.

Which tools read AGENTS.md

Tool Reads Notes
OpenCode AGENTS.md Project root, nested directories, and a global file at ~/.config/opencode/AGENTS.md.
Codex CLI AGENTS.md Global ~/.codex/AGENTS.md, then one file per directory from the root down. Combined files truncate at 32 KiB.
Claude Code CLAUDE.md or AGENTS.md Since v2.1.277 Claude reads AGENTS.md when no CLAUDE.md exists; a Project instructions setting controls whether it reads one, the other, or both.

That third row is why AGENTS.md is the safe default for new projects: one file works in all three tools today, and Claude-specific extras can live in a small CLAUDE.md that imports it. The full comparison is in CLAUDE.md vs AGENTS.md.

Where the file lives

Placement is part of the spec, and each runtime layers files by directory:

  • Project root — ./AGENTS.md is the canonical location. Commit it to version control: the file is team configuration, not personal preference.
  • Nested directories — src/billing/AGENTS.md scopes rules to that subtree. OpenCode and Codex both layer nested files over the root file, so broad rules stay at the top and local detail lives next to the code.
  • Global (per user) — OpenCode reads ~/.config/opencode/AGENTS.md; Codex reads ~/.codex/AGENTS.md. Personal preferences like "use short test names" go there — never project facts.

Case matters. On macOS and Linux the file is AGENTS.md; agents.md or Agents.md will not be picked up by tools that match literally.

AGENTS.md example

Here is a complete file for a typical TypeScript web app — short enough to read in a minute, specific enough that an agent can follow it without asking follow-up questions:

markdown
# Project instructions

## Overview

Next.js 15 App Router app (TypeScript, strict). PostgreSQL via Drizzle.
One deployable: the web app. No microservices.

## Commands

- Install: `npm ci`
- Dev server: `npm run dev`
- Lint: `npm run lint`
- Typecheck: `npx tsc --noEmit`
- Tests (unit + integration): `npm test`
- End-to-end: `npm run test:e2e`
- Production build: `npm run build`

Run `npm run lint` and `npx tsc --noEmit` before considering any task done.

## Architecture

- `app/` — routes and pages. Server Components by default.
- `src/server/` — business logic and database access. Never imported from `app/` directly — go through `src/server/index.ts`.
- `src/ui/` — shared presentational components (client components allowed here).
- Drizzle schema in `src/db/schema.ts`; migrations in `src/db/migrations/`.

## Code style

- TypeScript strict; no `any` (use `unknown` and narrow).
- Named exports only; no default exports.
- Colocate a component with its test and story.

## Testing

- Vitest for unit and integration; Playwright for e2e.
- Test behavior, not implementation: query by role, not by class.
- Never hit the real network; use the test fixtures in `test/fixtures/`.

## Never do

- Do not edit `.env*` files or add secrets to code.
- Do not run database migrations against the shared dev database.
- Do not add dependencies without asking.

The strongest line there is the last command section: "Run lint and typecheck before considering any task done." Agents are much more likely to verify their work when the file defines what "done" means.

How to configure your AI coding agent with it

  1. Create AGENTS.md at the repo root. Start from the example above or generate one from a short form — the generator asks for your stack and commands and writes the file for you.
  2. Fill in commands exactly as CI runs them. If CI runs pnpm test -- --run, write that — not "run the tests."
  3. Add the map and the guardrails. Ten honest lines about where code goes prevent most wrong-directory edits; the "never do" list prevents the expensive ones.
  4. Commit it. Treat changes to AGENTS.md like changes to CI config: reviewed, not slipped in.
  5. Verify discovery in a fresh session. Start a new agent session and ask: "What project rules are loaded, and what commands would you run before shipping a change?" If the answer is vague, the file was not read — see why agents ignore instructions.
  6. Re-check it as the project evolves. A stale command is worse than no command; the agent will faithfully run npm run test:old and fail.

How long should an AGENTS.md be?

Short. Claude Code's guidance is under 200 lines per file, and Codex CLI stops concatenating project instructions at 32 KiB by default — around 150–250 lines of prose — and silently truncates beyond that. Long files also get followed less reliably: rules at line 400 compete with the entire conversation for attention.

A good target is 50–150 lines. When you feel the urge to add more, split instead: put session-wide rules in the root file and move area-specific detail into a nested AGENTS.md next to that code. Nested files load when the agent works in that directory, not on every request.

One file for Claude Code, Codex, and OpenCode

AGENTS.md alone covers OpenCode and Codex. For Claude Code you have two good options:

  • Do nothing — Claude Code v2.1.277+ reads AGENTS.md directly when there's no CLAUDE.md.
  • Keep a thin CLAUDE.md — a few lines containing @AGENTS.md (Claude's import syntax, max four hops) plus any Claude-specific notes. This is the pattern Anthropic's own docs recommend for sharing one file across tools.

The generator and converter builds either shape: generate from a form, or paste an existing CLAUDE.md and get an AGENTS.md back with a report of everything that changed.

FAQ

Does Claude Code read AGENTS.md?

Yes — since v2.1.277, when no CLAUDE.md or CLAUDE.local.md exists in the working directory or its ancestors. You can also set Project instructions to claude-md-and-agents-md to load both files together. Older versions read only CLAUDE.md.

What is the difference between AGENTS.md and CLAUDE.md?

AGENTS.md is the open, tool-neutral file read by OpenCode and Codex CLI (and recent Claude Code). CLAUDE.md is Claude Code's native file, which supports @path imports and has the richer loading hierarchy. See CLAUDE.md vs AGENTS.md for the full comparison.

Does AGENTS.md replace my README?

No. The README is for humans who arrive at your repository; AGENTS.md is for agents that act inside it. Overlap is fine — but the instruction file should stay shorter, more imperative, and more current than any doc written for browsing.

Should AGENTS.md be committed?

Yes. It is shared project configuration: your teammates and your CI-derived commands all depend on it being the same for everyone. Personal preferences belong in your global user-level file instead.

Your turn

Take five minutes and write the file today: commands, map, guardrails. Then generate a clean version from a short form if you'd rather not start from a blank page — it runs entirely in your browser, and your text never leaves it. Once you have a draft, score it with the checker and fix what it flags.