AGENTS.md

On this page 7

AGENTS.md is an open, plain Markdown file format placed in a software repository to give AI coding agents the project-specific instructions they need, such as how to build, test and style the code. In AI for coding, it acts as a README written for agents: humans read the README, while agents read AGENTS.md before they edit files or run commands.

The format emerged in 2025 as a shared convention backed by several agent vendors, replacing a patchwork of tool-specific instruction files. It has no required schema, which keeps adoption simple, and its value depends almost entirely on how precise, current and verifiable its contents are.

How agents discover and apply AGENTS.md

A compatible agent looks for AGENTS.md at the repository root when a session starts and loads its text into the model context as standing instructions. The file is ordinary Markdown with free-form headings, so the model interprets it the same way it interprets a well-written prompt.

Large repositories and monorepos can contain nested AGENTS.md files in subdirectories. By convention, the closest file to the edited code takes precedence, so a package-level file can override root-level guidance for that package. An explicit instruction from the user in the chat still outranks anything written in the file.

The table below summarizes how instruction sources usually interact in an agent session.

SourceScopeTypical priority
User promptCurrent taskHighest
Nested AGENTS.mdOne directory subtreeHigh for files in that subtree
Root AGENTS.mdWhole repositoryDefault project guidance
Agent built-in defaultsAll projectsLowest, used when nothing else applies
Precedence of instruction sources in a typical agent session

What a useful AGENTS.md contains

An effective file contains facts an agent cannot reliably infer from the code alone. The most valuable entries are exact commands for setup, building, linting and testing, because agents use them to verify their own changes before reporting success.

SectionExample contentWhy agents need it
Setup commandspnpm install, required runtime versionAvoids guessing package managers
Build and testpnpm test --filter apiEnables self-verification
Code styleStrict TypeScript, no default exportsKeeps output consistent
Project structureWhere services, schemas and fixtures liveSpeeds up navigation
BoundariesNever edit generated files or migrationsPrevents harmful changes
Pull request rulesCommit message format, required checksMatches team workflow
Security notesNo secrets in code, use the vault clientReduces risky behavior
Common AGENTS.md sections and their purpose

Concise files work better than long ones. Every line consumes context window tokens on every task, and vague advice such as “write clean code” adds cost without changing behavior. A practical target is one to three screens of text at the root, with detail pushed into nested files.

AGENTS.md compared with other instruction files

Before the shared convention, each tool read its own file, and teams using several assistants had to maintain duplicate instructions. AGENTS.md is a vendor-neutral form of the broader project rules file concept, and many tools now read it directly or let a tool-specific file point to it.

FilePrimary readerFormatPortability
AGENTS.mdMany coding agentsFree-form MarkdownCross-tool
README.mdHuman contributorsFree-form MarkdownUniversal, but not agent-focused
CLAUDE.mdClaude CodeMarkdown with importsTool-specific
.cursor/rulesCursorRule files with metadataTool-specific
copilot-instructions.mdGitHub CopilotMarkdownTool-specific
CONTRIBUTING.mdHuman contributorsMarkdownProcess guidance only
AGENTS.md and related files

A common migration pattern is to make AGENTS.md the single source of truth and reduce tool-specific files to a short reference or a symbolic link, so that every assistant follows identical project rules.

Writing and maintaining the file

AGENTS.md should be treated as code, not documentation: it lives in version control, changes through reviewed pull requests and must stay in sync with the build. A stale test command is worse than none, because the agent will trust a broken instruction and may misreport failures.

MistakeEffect on agentsFix
Outdated commandsFailed or skipped verificationRun commands in CI to validate them
Vague style adviceNo measurable changeState concrete, checkable rules
Very long fileWasted context, diluted prioritiesMove detail into nested files
Contradicting the linterAgent loops between fixesDefer formatting to tooling
Secrets or internal URLsExposure through logs or outputsReference secure tooling instead
Frequent mistakes and how to fix them

Teams often ask the agent itself to propose updates after a session reveals a missing rule, then review that change like any other diff. This keeps the file grounded in observed agent mistakes rather than speculation.

Limitations and security considerations

AGENTS.md is guidance, not enforcement. Language models follow it probabilistically, so critical rules such as protected directories or forbidden commands also need hard controls in permissions, sandboxes, branch protection and CI checks.

  • Prompt injection risk: a malicious contributor can hide harmful instructions in the file, so changes need code review like any executable configuration.
  • No guaranteed support: tools differ in whether they read nested files and how they merge them.
  • No standard schema: free-form text cannot be validated automatically beyond basic linting.
  • Context cost: every instruction competes with source code for the model’s limited attention.

Understanding it simply

AGENTS.md is a note for AI helpers that write code. It sits in the project folder. It tells the AI how this project works.

Think of a new team member on day one. A good colleague hands over a short sheet: how to start the app, how to run the tests and which files to leave alone. AGENTS.md is that sheet, but for an AI assistant. With it, the assistant makes fewer wrong guesses and checks its own work.

Applied in practice

A ten-person team maintains a TypeScript monorepo with a web app, an API and a shared design library. Developers use two different coding agents, and both kept running the wrong test runner and editing generated API client files. The team writes a root AGENTS.md of about 60 lines with setup commands, the test command for each package, naming rules and a list of directories that must never be edited by hand.

They add a nested AGENTS.md in the API package that explains database migration rules. After two weeks, reviewers report that agent pull requests pass CI on the first run far more often, and edits to generated files stop appearing. The file now changes through normal review, and a CI job runs every listed command nightly so that broken instructions are caught early.