AGENTS.md Explained: A Practical Guide to Project Context for AI Coding Agents
AI coding agents usually fail not because they can't write code, but because they don't know how a particular project writes code. AGENTS.md is an open, plain-text Markdown file, typically placed at the repository root, that declares a project's context and behavioral rules to coding agents. This article explains the problem it solves and the four design principles behind it, traces how the format evolved into a community standard, lays out what a high-quality file should contain (with a template), shows how to layer and inherit the file across monorepos and multi-stack repositories, calls out common anti-patterns, and explains how to govern the file as an engineering asset and measure its impact. Readers will learn what to write, what to leave out, and how to roll it out across a team.
The Root Problem: Coding Agents Don’t Lack Capability, They Lack Context
Over the past couple of years, the capability boundary of AI coding tools has expanded rapidly: from single-line completion, to function-level generation, to coding agents that can autonomously read a repository, modify multiple files, run commands, and commit changes. Yet the most common failure mode in engineering practice is not that “the model can’t write code” — it’s that “the model doesn’t know how this project writes code.”
A typical failure chain looks like this: an agent adds a module following generic best practices and pulls in a third-party dependency the project never adopted; or it calls data-access code directly across layers in an existing layered architecture; or it gets unit tests passing but never updates the API documentation; or it runs a destructive cleanup command. What these problems share is that the project’s tacit knowledge lives only in the heads of senior members and in old code, and was never written down in a machine-readable form inside the repository.
There have been two approaches in the past, and neither is good enough:
- Repeating the context in prompts. You paste the project background at the start of every session. It’s costly, easy to omit, and different members describe things inconsistently.
- Per-tool private config files. Early on, each AI coding tool defined its own configuration convention, with different filenames, locations, and semantics. A team using two or three tools at once had to maintain several near-duplicate configuration files, and the migration cost became obvious the moment a tool was discontinued or the team switched toolchains.
This is exactly the core problem AGENTS.md aims to solve: turning “the instruction manual for AI agents” from a one-off prompt and a personal habit into a versioned, reviewable, tool-agnostic engineering asset inside the repository.
What AGENTS.md Is: Definition and Design Principles
AGENTS.md is an open-format plain-text Markdown file, usually placed at the repository root, used to declare a project’s context and behavioral rules to AI coding agents. It can be read without depending on any specific tool, and human members can read and maintain it directly just the same.
Its design philosophy can be summarized in four points:
- Simple and predictable. Fixed filename, fixed location, fixed semantics. The agent doesn’t have to guess “which file should I read,” and the team doesn’t have to memorize each tool’s private convention.
- Open format and tool-neutral. The specification isn’t bound to any single vendor or product; any tool can choose to support it. This gives the format a chance to become shared industry infrastructure rather than a feature bolted onto one product.
- Practical rather than all-encompassing. It is not an architecture design document, nor a complete development standards manual. It aims to “eliminate the mistakes an agent makes most often with as few words as possible,” so it emphasizes being concise, executable, and unambiguous.
- Versionable and reviewable. Because it’s just an ordinary text file in the repository, it naturally enters code review and version control. Changes to the standard are traceable, and it evolves just like code does.
How It Evolved: From Fragmentation to Community Consensus
Understanding how this format came to be helps explain “why the filename looks the way it does.”
Phase 1: Popularizing the concept. AI coding tools began supporting a dedicated configuration file at the project root, letting an agent automatically load project instructions at the start of a session. This “project-level instruction file” approach proved highly effective and was later imitated by many tools — but each used a different filename.
Phase 2: Standard proposal and naming convergence. In 2025, a community initiative emerged to unify this kind of file format, and some initially advocated a singular-form name. Then another major participant acquired the corresponding site domain and pushed for the plural form as the standard. After a period of open competition, the party that had proposed the initiative first voluntarily conceded and aligned with the other side, and the naming dispute converged from there. This process shows that the outcome of an open standard often depends on the scale of adoption and ecosystem consensus, not on who proposed it first.
Phase 3: Neutral hosting and adoption at scale. With several tech companies jointly pushing it, the format was placed under the stewardship of a dedicated organization within a neutral industry foundation, with the specification text and discussion process publicly available. According to community counts, tens of thousands of open-source repositories have adopted the format, and mainstream AI coding tools have gradually added support.
Phase 4: Compatibility issues surface. Notably, the adoption process also brought real friction: some tools that insisted on reading their own config filename could not interoperate with repositories using the unified format, causing the same repository to behave inconsistently under different tools. Some organizations reported internally that this led to configuration fragmentation, and the community then began discussing interoperability approaches — the common ones being symlinks to a same-named file, scripts to sync across multiple config files, or multi-filename fallback lookup at the config-loading layer. The lesson from this phase is worth remembering: any “unified standard” needs to leave a compatibility path for existing tools during early adoption.
What a High-Quality AGENTS.md Should Contain
The content checklist comes down to seven sections. The principle is simple: only write down information that is “impossible to guess” or “costly to guess wrong.”
1. Project Overview and Architecture Map
Explain in one sentence what the project does and who it serves; then use three to five sentences to describe the layered structure and dependency direction. The key here is to write architecture constraints as decidable rules — for example, “the interface layer must not access the persistence layer directly” or “cross-module calls must go through the domain service” — rather than a vague “please follow good architecture.”
2. Environment and Command List
This is the highest-return section. The place where agents most often go wrong is not knowing how to build, test, and run static analysis. List the real, runnable commands clearly, and the agent can verify its work before and after on its own.
3. Code Style and Conventions
Don’t restate generic style guides — only write this project’s deviations: indentation and line width, import ordering rules, naming conventions, error handling, logging and exception-wrapping conventions, comment language, and so on.
4. Directory Navigation and “Where to Make Changes”
Explain which directory a new feature should land in, how test files should be named and placed, and which locations the docs and changelog need to be updated in sync.
5. Testing and Verification Requirements
Spell out the “definition of done”: which levels of tests must be added, coverage thresholds, and the combination of commands that must pass locally. Without this section, the code an agent delivers often can’t be merged.
6. Security Boundaries and Prohibited Actions
Explicitly list what’s forbidden: never commit secrets and credentials, never modify production config files, never force-push or rewrite history, never delete data, and always confirm with a human first for any irreversible operation. This section is the last guardrail against incidents.
7. Collaboration and Commit Conventions
Branch naming, commit message format, the language for change descriptions, and whether changes need to be linked to a ticket.
Sample Template
# AGENTS.md## Project OverviewThis repository is the backend service for order fulfillment. It exposesREST endpoints externally and is organized internally into three layers:interface / domain / persistence. Dependencies may only point downward.## Common Commands- Install dependencies: ./scripts/bootstrap.sh- Run locally: ./scripts/dev-up.sh- Unit tests: ./scripts/test-unit.sh- Full test suite: ./scripts/test-all.sh- Static analysis: ./scripts/lint.sh- Formatting: ./scripts/fmt.sh## Code Conventions- Language & version: Python 3.12, type annotations are mandatory- Indent with 4 spaces, max 100 characters per line, formatted by fmt.sh- Wrap exceptions as domain exceptions; never raise low-level exceptions at the interface layer- Database changes must go through versioned migration scripts; manual schema edits are forbidden## Change Guidelines- New endpoints: add routes under controller/, put business logic in domain/,and keep data access in repository/ only- Place unit tests next to the module under test, named test_<module>.py- When changing public interfaces, update docs/api.md and the changelog## Definition of DoneBefore committing, test-all.sh and lint.sh must pass locally;new logic must include unit tests; do not lower the existing coverage baseline.## Prohibited Actions- Never commit any secrets, tokens, or production connection strings- Never force-push, rebase-rewrite shared branches, or delete remote branches- Never run irreversible operations such as rm -rf or bulk DROP- Changes to production config, permissions, and data migrations must be confirmed by a human first
Layering and Inheritance: Adapting to Monorepos and Multiple Tech Stacks
In a large repository or monorepo, a single root file quickly gets out of hand. The recommended structure here is layered: the root AGENTS.md keeps only global constraints (commit conventions, prohibited actions, overall architecture), and each subproject places a supplementary file in its own directory describing that subproject’s tech stack, commands, and conventions. When an agent enters a subdirectory to work, it first loads the global rules, then overlays the nearest local rules.
repository root/├── AGENTS.md # Global: architecture boundaries, security red lines, commit conventions├── services/│ ├── AGENTS.md # Common conventions for backend services│ ├── order-api/AGENTS.md # Service-specific commands and module notes│ └── user-api/AGENTS.md└── web/└── AGENTS.md # Frontend stack, component conventions, build commands
When layering, keep two disciplines in mind: when rules conflict, the nearest file wins (the proximity rule must be stated explicitly in the root file), and avoid duplication — don’t copy content already written in a parent file into a child file, or you’ll easily end up with two sets of instructions drifting out of sync.
Common Anti-Patterns
- Turning it into a catch-all document. Stuffing the architecture design doc and requirements doc into AGENTS.md bloats it until the agent can’t use it effectively. The practical range is: keep the root file around 100 lines; if it exceeds that, you should be layering.
- Writing only “should” without “how.” Statements like “keep the code clean” or “mind performance” have almost no binding force on an agent; they must be replaced with decidable rules and commands.
- Drifting out of sync with the actual repository state. After a command is renamed or a script path is moved, the file is forgotten. The suggestion is to add a lightweight validation step to the CI pipeline that checks the file exists, the required sections are present, and the example commands actually run.
- Only an AI perspective, no human perspective. A well-written AGENTS.md is often also the best onboarding document for new team members, because its content is precisely “the things you most need to know first when taking over a project.”
- Putting sensitive information in it. Credentials, internal addresses, and real customer data must never go into this file — it’s distributed along with the repository.
Governance and Measuring Effectiveness
Governing it like code is the key to unlocking long-term value:
- Put it through review. Changes to AGENTS.md should go through review like ordinary code, to prevent individuals from loosening constraints on their own.
- Version it. Record the evolution history of the standard, so during team handovers you can trace “why it was decided this way back then.”
- Validate in CI. Use a script for structural and executability checks to prevent the standard from rotting.
- Measure the payoff. Observable metrics include: the first-pass acceptance rate of agent-produced code, the number of review comments raised due to style or architecture issues, the rework rate per task, and the average number of interaction turns per task. If these metrics don’t improve, it means the file contains rules that “look correct” rather than rules the agent “will actually use.”
Three Recommendations for Enterprise Adoption
- Fold it into a unified development workflow. On your code hosting and CI platforms, make AGENTS.md one of the template files for newly created repositories, and set up the layered-inheritance directory skeleton, so the standard exists by default rather than being written after the fact. General-purpose capabilities such as code hosting, pipelines, and logging, monitoring, and alerting — offered by platforms like Baidu AI Cloud — can serve as the infrastructure for carrying these validation steps and effectiveness measurements.
- Prepare a compatibility layer for existing tools. A team’s toolchain is rarely just one thing; keeping multiple configs consistent via symlinks or sync scripts is the most practical approach during the transition. At the same time, prefer tools that already support the format to reduce the long-term maintenance surface.
- Define the human-machine division of labor. Make the “prohibited actions” and “must confirm” items in the file actually take effect: irreversible operations, permission changes, and production changes are always decided by a human at the end. The value of the standard is not in letting the agent do more, but in letting it do more within the correct boundaries.
Conclusion
The significance of AGENTS.md goes beyond being a configuration file format. It turns tacit knowledge that was previously scattered across personal prompts, verbal hand-me-downs, and private configs into explicit engineering assets that are version-controlled, reviewable, and reusable across tools. For an individual developer, spending half a day writing this file well usually pays off continuously in every subsequent round of agent collaboration. For a team, it’s the point of connection that embeds AI coding capability into the engineering system, rather than leaving it stuck as a personal productivity tool.
