Blog · AI & platform

AGENTS.md: The Complete Field Guide

Every team shipping with AI coding agents eventually creates an AGENTS.md. Most of them make the same mistakes: one giant file, stale instructions, rules written for humans. This guide covers what the file actually does, why it breaks down at scale, and how to structure it so agents reliably follow it.

What is AGENTS.md?

AGENTS.md is a Markdown file placed at the root of a repository that gives AI coding agents persistent instructions about the codebase, coding conventions, architecture decisions, and how to work within the project. It is the primary mechanism for encoding engineering judgment into the environment the agent operates inside.

The file is read by agents like OpenAI Codex, GitHub Copilot Workspace, and similar tools at the start of each session. Unlike a one-off prompt, it persists across every agent run — meaning any rule you write there is enforced on every line the agent produces, without repeating it each time.

Think of it as the onboarding document for a new engineer who never forgets, never shortcuts the conventions, and scales their work across every file in the codebase simultaneously.

Why it exists and where it came from

The term gained widespread traction in February 2026 when Ryan Lopopolo at OpenAI published a detailed account of building a production product entirely with AI agents — zero lines of application code written by hand. The AGENTS.md file was a central mechanism in what they called harness engineering: the discipline of building the environment the agent operates inside, rather than writing the code directly.

Thoughtworks Distinguished Engineer Birgitta Böckeler then analysed the experiment on Martin Fowler's blog, identifying the AGENTS.md as the entry point to a structured knowledge architecture — and noting the key failure mode: teams creating a single sprawling file that rots and stops being followed.

Before AGENTS.md was formalised, the same role was played by README sections titled "For AI assistants," .cursorrules files, system prompt preambles, and custom instructions in various tools. AGENTS.md is the converging convention.

What goes in AGENTS.md

The file should contain three categories of content:

1. Orientation (where am I?)

  • What this repository is and does
  • The tech stack (language, framework, runtime, major dependencies)
  • How to run the project locally
  • Where to find things (directory structure overview)
  • Who owns what (team or module ownership if relevant)

2. Taste invariants (how should code look?)

  • Naming conventions (files, functions, variables, types)
  • Error handling patterns the team has settled on
  • Logging format (structured? what fields are required?)
  • File size limits (e.g. "no file over 300 lines")
  • Import order and module boundary rules
  • What to avoid (anti-patterns the team has learned to reject)

3. Pointers (where is the deep truth?)

  • Links to deeper docs for architecture decisions
  • Which ADRs (architecture decision records) apply
  • Where the API contracts live
  • Which runbooks cover operational patterns
  • Where to find the test strategy and coverage expectations

The single-file problem

The most common AGENTS.md mistake: putting everything in one file and treating it as a permanent document.

Context is a scarce resource. An agent has a finite context window, and every token spent on AGENTS.md is a token not spent on the actual code being changed. A 2,000-line AGENTS.md becomes noise — the agent effectively ignores instructions buried in the middle because they fall outside the attention window or are washed out by surrounding content.

The specific failure modes of a monolithic AGENTS.md:

  • Staleness compounds silently. When the codebase evolves but the file doesn't, the agent follows outdated conventions. No one notices until a PR review catches a pattern you thought was prohibited.
  • Rules conflict. Different engineers add sections over time without reading the existing content. The agent receives contradictory instructions and resolves them unpredictably.
  • Specificity is lost. A rule like "use structured logging" is too vague to enforce consistently. A rule with an example, a counter-example, and a pointer to the logging module is actionable. Monolithic files trend toward vague.
  • No ownership. Nobody reviews the AGENTS.md in PRs because it's treated as documentation, not as code that runs on every agent session.

The table-of-contents pattern

The solution the OpenAI harness engineering team landed on: treat AGENTS.md as an index, not a document. The file itself stays short — one to two pages — and its primary job is to tell the agent where to find the authoritative truth for any given domain.

AGENTS.md structure (table-of-contents pattern)

# About this codebase
[2-3 sentence description]

# Tech stack
- Runtime: Node.js 22, TypeScript 5
- Framework: Next.js 15 (App Router)
- Database: Postgres via Drizzle ORM

# How to run
[minimal getting-started steps]

# Conventions (summary)
See docs/conventions/ for full rules.
Short version:
- Structured logging (see docs/conventions/logging.md)
- No file over 300 lines (see docs/conventions/file-size.md)
- All errors typed (see docs/conventions/errors.md)

# Architecture
See docs/architecture/ for ADRs.
Key decisions: docs/architecture/adr-001-database.md

# Testing
See docs/testing/strategy.md
Coverage target: 80% on business logic paths

# What to avoid
See docs/conventions/anti-patterns.md

The AGENTS.md never contains the full rules. It contains stable pointers to the files that do. When a convention changes, you update one targeted doc file — not hunt through a monolith.

What goes in the docs directory

The docs directory referenced from AGENTS.md is the actual harness. Each file should be narrow, owned, versioned, and written for a system reader — not a human skimming during onboarding.

FileContentsWho owns it
docs/conventions/logging.mdRequired fields, format, forbidden patterns, example snippetsPlatform / infra lead
docs/conventions/errors.mdError type hierarchy, when to throw vs return, wrapping rulesTech lead
docs/conventions/naming.mdFile, function, variable, type, and constant naming rulesTech lead
docs/conventions/file-size.mdLine limit, when to split, how to name the splitTech lead
docs/conventions/anti-patterns.mdBanned patterns with before/after examplesTech lead
docs/architecture/adr-NNN.mdSingle architectural decision with context, decision, consequencesDecision author
docs/testing/strategy.mdCoverage target, what needs tests, test file location rulesQA / tech lead
docs/testing/fixtures.mdHow to create and name test fixtures and factoriesQA / tech lead

Each doc file should open with a one-sentence rule statement, followed by examples, then counter-examples. Agents perform best when the rule is stated before the reasoning, not after.

What not to put in AGENTS.md

  • Business context and product decisions. The agent doesn't need to know the company's mission or OKRs to write code consistently. That's noise.
  • Full inline examples for every rule. Examples belong in the referenced docs files, not in the index. Inline examples in AGENTS.md inflate the token cost of every agent session.
  • Aspirational rules not yet enforced. If a convention isn't actually applied to the existing codebase, telling the agent to follow it creates inconsistency. Only document what is true today, with a clear path to what will be true.
  • Instructions that belong in CI. If a rule can be enforced by a linter or a CI check, it should be. Writing it in AGENTS.md without a mechanical backstop means it's enforced only when the agent happens to follow it.
  • Vague preferences. "Write clean code" and "prefer simple solutions" are not rules. They take up tokens without giving the agent anything actionable to check against.

Keeping it fresh: the staleness problem

A stale AGENTS.md is worse than no AGENTS.md. The agent follows it confidently, producing code that matches outdated conventions — and the output looks correct on the surface because it follows the rules.

Three mechanisms that reduce staleness:

  • Treat docs as code. Add docs/ changes to the PR review checklist. Any PR that changes a convention without updating the relevant doc file should fail review.
  • Run a garbage collection agent. Schedule a weekly background agent run that reads AGENTS.md, scans the codebase for divergence from its rules, and opens targeted PRs. If the agent keeps flagging the same pattern as a violation, the convention may need updating, not the code.
  • Version the AGENTS.md index. Add a "Last reviewed" date and an owner to each section. Sections not reviewed in 90 days should be flagged for audit. Stale sections are more likely to be wrong than fresh ones.

AGENTS.md vs CLAUDE.md vs .cursorrules

FileUsed byScopeNotes
AGENTS.mdOpenAI Codex, Codex CLI, many toolsRepo-levelThe emerging cross-tool convention
CLAUDE.mdClaude Code (Anthropic CLI)Repo or directory levelHierarchical: project > user
.cursorrulesCursor IDERepo-levelBeing superseded by .cursor/rules/
.cursor/rules/Cursor IDEFile/folder-level rulesMore granular than single file
GitHub Copilot instructionsVS Code CopilotRepo-levelIn .github/copilot-instructions.md

The practical answer for most teams: maintain one canonical docs/ directory with your conventions, then have each tool-specific file (AGENTS.md, CLAUDE.md, .cursorrules) point to it. You write the rules once; each agent reads them via whichever entry point it supports.

Frequently asked questions

How long should AGENTS.md be?

The index file should be under 150 lines. If it's longer, you're probably putting content in it that belongs in the docs directory it points to. The goal is an agent that can read the index in seconds and know exactly where to find any rule.

Should AGENTS.md be in every repo or just the main one?

Every repo that AI agents work in should have one. In a monorepo, a root AGENTS.md sets the baseline; package-level AGENTS.md files (or subdirectory equivalents) can override or extend it for packages with different conventions.

What happens if the agent ignores AGENTS.md?

Agents don't ignore AGENTS.md — they follow it too literally or not specifically enough. If you're seeing violations, the rule is either too vague, buried in a long file, or contradicted by a pattern already in the codebase. A mechanical linter enforcing the same rule will catch what the agent misses.

Do I need AGENTS.md if I'm using Claude Code or Cursor with their own conventions?

Yes — the tool-specific file (CLAUDE.md, .cursorrules) and AGENTS.md serve the same purpose. If you're using multiple tools, AGENTS.md is the cross-tool standard. Maintain one docs/ directory and have all tool files reference it.

How is AGENTS.md different from a README?

A README is written for a human who reads it once during onboarding. AGENTS.md is written for a system that reads it on every task, with a finite token budget, and needs to act on it immediately. Rules in AGENTS.md should be machine-actionable: specific, verifiable, and free of ambiguity.

Related reading: AI didn't remove engineering judgment — it moved it upstream, knowledge architecture for AI coding agents, and harness vs prompt vs context engineering.