AI coding agents are writing real production code now. But most teams learn the hard way that an agent without context is just a fast way to create technical debt.
That's where AGENTS.md comes in. It's a single file that tells an agent how your repository works: what to build, what not to touch, and how to validate its own output.

AGENTS.md is a machine-readable operating manual for AI development agents.
In practice, the file helps an agent answer five questions before it writes anything:
Without these answers, agents guess. And agents that guess create PRs that need heavy rewriting.
Most teams using agents now work in a hybrid model: humans set direction, agents execute scoped tasks, reviewers check the output. The weak link is usually unclear repository rules. An agent can't follow conventions it doesn't know about.
A good AGENTS.md fixes this by giving agents the right starting point. Generated code follows existing patterns because the file says what those patterns are. Agents skip trial-and-error discovery because commands and structure are documented. Security rules are explicit. PR expectations are clear. New engineers benefit from the same source of truth.
For teams running AI agent development at scale, this file is the difference between agents that produce review-ready code and agents that produce cleanup work.
The file needs to be specific to your repository, not generic advice. Here are the sections most teams should include.
Start with a short explanation of the product and system boundaries. Then map core directories.
Example structure:
src/app for routes and pagessrc/components for UI primitivessrc/lib for shared business logiccontent/ for MDX contentscripts/ for build and maintenance toolingWithout this, agents will put files wherever seems reasonable to them, which is rarely where you want them.
List canonical commands for install, run, test, and build. Include exact package manager requirements.
Example command set:
yarn installyarn devyarn buildyarn testIf linting is temporarily broken, say so and document what the agent should run instead. Don't leave it to figure out on its own.
Define language-level standards and style boundaries, such as:
Be explicit about editing constraints, including rules for destructive git operations and changes in unrelated files.
This is where you draw hard lines. Common ones:
If you're building AI features in regulated sectors, these guardrails work well alongside MCP server development where you can control exactly which tools and data the agent can access.
Define what “done” means for autonomous execution.
Recommended rules:
The difference between a PR you can review in 10 minutes and one you need to rewrite often comes down to whether these rules existed.
Use this baseline and customize by stack:
# AGENTS.md
## Project Context
- Product: <what this repository builds>
- Primary stack: <frameworks/languages>
- Core goal: <business or technical objective>
## Repository Map
- <path>: <purpose>
- <path>: <purpose>
## Commands
- Install: `<command>`
- Dev: `<command>`
- Test: `<command>`
- Build: `<command>`
## Implementation Rules
- Follow existing architecture and naming conventions.
- Make minimal, scoped changes.
- Add or update tests for behavior changes.
- Do not modify unrelated files.
## Security Rules
- Never expose secrets in code, logs, or docs.
- Validate external input before processing.
- Respect authorization boundaries.
## Git and PR Workflow
- Use focused commits for each milestone.
- Run required validation commands before handoff.
- Document risks, assumptions, and test coverage in PR summary.
We see these a lot, even from experienced teams.
| Mistake | Why it breaks workflow | Better approach |
|---|---|---|
| Generic instructions only | Agent cannot map rules to repository reality | Add concrete file paths, commands, and ownership boundaries |
| Missing validation commands | Agent stops without deterministic quality checks | Define exact build/test gates and fallback rules |
| No security section | Increased risk of unsafe code and accidental data exposure | Add explicit secret handling and permission rules |
| Contradictory guidance | Agent behavior becomes inconsistent between runs | Keep one canonical source and remove outdated rules |
| No commit/PR expectations | Handoffs require heavy manual cleanup | Enforce milestone commits and review-ready summaries |
If you're rolling this out across repositories, here's the sequence that works:
The file should change as your project changes. If your build process or architecture shifts, update it.
The file works best when someone actually owns it. If nobody is responsible for keeping it accurate, it rots fast.
Here's a lightweight ownership model:
| Role | Responsibility |
|---|---|
| Engineering lead | Owns technical accuracy and architecture rules |
| Security lead | Reviews guardrails, data handling, and permission boundaries |
| Developer experience owner | Maintains command reliability and onboarding clarity |
| Repository maintainers | Approve updates as part of normal pull request review |
This keeps the file accurate without adding another meeting to anyone's calendar.
Track these before and after you add the file:
If these numbers improve, the file is doing its job.
The structure stays the same across stacks, but the specific rules should match your tools.
Useful rules include:
Useful rules include:
Useful rules include:
These kinds of stack-specific details are what separate a useful file from a generic one.
You don't need the whole thing on day one. Build it up over a few weeks.
Each week adds a layer, and you'll see results from week one.
The following example can be inserted into a repository and adjusted to local constraints:
## Autonomous Edit Policy
- Scope: modify only files directly related to the requested task.
- Safety: do not run destructive git commands (`reset --hard`, forced checkout) without explicit approval.
- Validation: run build and test commands before declaring completion.
- Traceability: include changed-file summary and risk notes in final handoff.
- Security: never print secrets or place credentials in source files.
- Unknowns: when behavior is ambiguous, prefer conservative assumptions and document them.
This kind of block works because it's concrete. An agent can follow "run build and test commands before declaring completion" much more reliably than "ensure quality."
Quick sanity check for reviewers:
Using this consistently catches most agent mistakes before they hit the main branch.
No. Small teams actually see the biggest immediate impact because there's less room for miscommunication and every bad PR costs more time.
Update it whenever architecture, tooling, or release workflows change. A monthly review cadence is usually enough for active repositories.
No. The file improves first-pass quality, but human review is still required for security, product correctness, and edge-case validation.
Write down your build commands, map your important directories, and list things the agent must never do. You can add coding conventions and PR expectations after your first couple of agent runs.
If you're using AI agents to write code, tell them how your repository works. The teams getting good results from agents aren't using better models. They're giving better instructions.
Start with commands, a repo map, and security rules. Build from there.