AGENTS.md: When Your Repository Becomes Agent-Readable
Agent coding tools read repo context before they start work. Teams that write it well get compounding leverage. The rest donate context window to archaeology.
Every major agent coding tool now ships with a mechanism for reading persistent repo context before it starts work. OpenAI Codex reads AGENTS.md. Claude Code reads CLAUDE.md. GitHub Copilot agent reads .github/copilot-instructions.md. Cursor reads .cursor/rules/. The file names differ and the syntax varies, but the pattern is identical: give the agent a structured document that tells it how to work in this codebase, and it will start from correct assumptions rather than bad ones.
Most engineering teams have not taken this seriously yet. They treat these files the way early developers treated README files: something you create once when you set up the repo, then ignore until it is conspicuously wrong. That approach donates context window to archaeology every time an agent starts a task in the repo. The agent has to infer what you intended from file patterns, existing code, and best guesses. Inference is slower, less reliable, and invisible when it goes wrong.
The teams getting real leverage from agent-assisted development are the ones who have figured out what designing for delegation looks like at the repository layer. This post is about what that means in practice.
What the agent actually needs to know
When a coding agent opens your repository, it is trying to answer a specific set of questions before it touches anything.
What command runs your tests? Not the conceptual answer — the exact string. The agent that infers npm test when your project uses pnpm run test:unit is going to produce commits that break CI.
Which directories are safe to modify? Generated code, vendor dependencies, CI configuration owned by another team — these are all in the repo, and they all look like plausible edit targets without explicit guidance. An agent that modifies a generated file is creating a problem that will surface at build time, not review time.
What is your branching strategy? Should the agent push a branch and open a PR? Push directly to a feature branch? Draft the changes and stop short of pushing? The default behaviour differs by tool, and none of the defaults are necessarily right for your team's workflow.
What style and architecture constraints apply? If your codebase uses a specific abstraction pattern for database access, or has a convention for error handling, or has a rule against using a particular library, the agent has no way to know unless you tell it.
What must pass before a change is submitted? Unit tests, integration tests, a specific linter configuration, type checking — the agent needs to know what done looks like so it can validate its own output before handing off.
These are not edge cases. They are the baseline questions any contributor needs answered in the first hour of working on a codebase. The difference is that human contributors read the README, ask a question in Slack, and build up a mental model over days or weeks. An agent has no persistent memory across sessions. It answers these questions from scratch every time it starts work, using whatever context it can find in the current session.
A well-written AGENTS.md turns that cold-start problem into a solved problem.
The three-layer analogy
The three-layer stack we use to describe AI-native systems — record, context, action — maps directly onto how agents interact with a codebase.
The record layer is the codebase itself: source files, tests, configuration, and history. It is the source of truth for what the system does and how it is built.
The action layer is the tools the agent uses: editing files, running tests, committing changes, opening pull requests. This is where the agent's work becomes concrete.
The context layer is what sits between them. It grounds the agent's reasoning about what to do and how to do it safely. Without a strong context layer, the agent is reasoning about the record using its general knowledge of software engineering rather than specific knowledge of this codebase. The gap between general and specific is where most agent mistakes happen.
AGENTS.md is the primary investment in the context layer for developer tooling. Teams that build it well get agents that make correct decisions because they are reasoning from the right context. Teams that skip it get agents that are doing their best with incomplete information — which is visible in the pull requests they produce.
What to put in it
A useful agent context file is not a marketing document for the codebase. It is a specification for how to interact with it. The content that matters most:
Command catalogue. The exact commands to run tests, build the project, run the linter, start a development server. Not a description of what these commands do — the literal strings. If there are variants (unit tests vs integration tests, fast lint vs full lint), document all of them with the appropriate use cases.
Safe-to-modify scope. Which directories and files the agent should treat as in-scope for edits, and which to avoid. Generated files that are overwritten by a build step, vendor code, CI infrastructure owned by a platform team — these need to be explicitly excluded. An agent that modifies a generated Protobuf file is creating work, not saving it.
Workflow conventions. How the team handles branches, commits, and pull requests. If your convention is one branch per issue with a specific naming pattern, document it. If the agent should open a draft PR rather than a ready-for-review PR, say so. If commits need to follow Conventional Commits format, include that.
Style and architecture constraints. The patterns that exist in the codebase that a new contributor would need to learn and that are not obvious from reading the code. Naming conventions, preferred abstractions, patterns to avoid, dependencies to use or not use.
Testing requirements. What coverage is expected, what must pass before a change is submitted, how to run tests in isolation. If there is a slow test suite and a fast subset, document both and when to use each.
Environment and secrets. How to set up a local development environment, what environment variables are needed, what should never be committed. An agent that does not know your secrets management conventions can create security issues even when trying to do the right thing.
The governance problem
Who owns the agent context file? The answer matters more than it seems.
The right answer is: the same team that owns the code it describes. Agent context is code governance documentation. It should be reviewed in pull requests like any other code. When a convention changes — a new test runner, a renamed directory, a deprecated pattern — the AGENTS.md should change with it.
Stale agent context is worse than no agent context. An AGENTS.md that tells the agent to run a test command that no longer exists produces errors that take longer to debug than a missing context file. The agent follows the documented instruction confidently, gets an error, and has to reason about why the documentation is wrong — which is a harder problem than starting from observation.
This is the same discipline that makes internal documentation valuable or worthless. Documentation maintained by the people who write the code stays accurate. Documentation maintained by a separate team, or by no one, drifts until it is worse than useless.
The nested pattern for larger repos
OpenAI's Codex documentation recommends a layered approach: AGENTS.md at the project root sets defaults for the whole repo, AGENTS.md files in subdirectories override for their scope. The outer file applies unless an inner file says otherwise.
This is particularly useful for monorepos with multiple services. A root AGENTS.md covers shared conventions — commit format, overall branching strategy, secrets management, general style rules. A per-service AGENTS.md covers service-specific commands, owners, architecture patterns, and testing requirements. An agent working in a specific service directory gets both layers: the shared context from the root, the specific context from the local file.
The composability pattern is familiar. It is how .eslintrc works, how .editorconfig works, how most tool configuration with project-wide and local overrides works. Apply the same mental model.
Starting from where you are
You do not need to write a perfect AGENTS.md on the first try. A useful starting point is observation: what does the agent get wrong most often in your codebase?
If it keeps running the wrong test command, document the right one. If it keeps modifying files it should not touch, define the safe scope. If its commits are failing linting, document the linter and the command. Each corrective feedback loop tells you what the context file needs.
The first version will be incomplete. That is fine. Treat it as a living document that gets updated when the agent produces the same kind of mistake twice. By the time the file is three or four revision cycles old, it will cover the cases that actually matter for your team's workflow.
The leverage compounds quickly. Every agent invocation in the repo benefits from every improvement to the context file. A human contributor needs to learn the codebase once. An agent needs to be told every session. A good AGENTS.md is the mechanism for making that per-session onboarding cost negligible instead of a drag on every task.
Your repository already has a new kind of contributor. The question is whether you have made it easy for that contributor to do good work.