1 · What is AGENTS.md?
AGENTS.md is a Markdown file that lives in your repository (or home directory) and acts as a briefing packet for AI coding agents.Why AGENTS.md?
README.md files are for humans: quick starts, project descriptions, and contribution guidelines. AGENTS.md complements this by containing the extra, sometimes detailed context coding agents need: build steps, tests, and conventions that might clutter a README or aren’t relevant to human contributors. We intentionally kept it separate to:- Give agents a clear, predictable place for instructions
- Keep READMEs concise and focused on human contributors
- Provide precise, agent-focused guidance that complements existing README and docs
What it contains:
- Describes how to build, test, and run your project
- Explains architectural patterns and conventions
- Lists external services, environment variables, or design docs
- Provides domain-specific vocabulary and code style rules
2 · One AGENTS.md works across many agents
Your AGENTS.md file is compatible with a growing ecosystem of AI coding agents and tools, including:- Factory Droid - Factory’s AI coding agent
- Cursor - AI-powered code editor
- Aider - AI pair programming in your terminal
- Gemini CLI - Google’s command-line AI assistant
- Jules - Google’s coding assistant
- Codex - OpenAI’s code generation model
- Zed - AI-enhanced editor
- Phoenix - AI development platform
- And many more emerging tools
3 · File locations & discovery hierarchy
Agents look for AGENTS.md in this order (first match wins):./AGENTS.md
in the current working directory- The nearest parent directory up to the repo root
- Any
AGENTS.md
in sub-folders the agent is working inside - Personal override:
~/.config/AGENTS.md
Multiple files can coexist. The closer one to the file being edited takes
precedence.
4 · File structure & syntax
AGENTS.md is plain Markdown; headings provide semantic hints.- Top-level headings (
#
) as sections - Bullet lists for commands or rules
- Inline code (
`
) for exact commands, filenames, env vars - Links to external docs (GitHub, Figma, Confluence…)
5 · Common sections
Section | Purpose |
---|---|
Build & Test | Exact commands for compiling and running the test suite. |
Architecture Overview | One-paragraph summary of major modules and data flow. |
Security | API keys, endpoints, auth flows, rate limits, sensitive data. |
Git Workflows | Branching strategy, commit conventions, PR requirements. |
Conventions & Patterns | Folder structure, naming patterns, code style, lint rules. |
6 · Templates & examples
Factory-style comprehensive example
Node + React monorepo
Python microservice
7 · Best practices
Keep it short
Keep it short
Aim for ≤ 150 lines. Long files slow the agent and bury signal.
Use concrete commands
Use concrete commands
Wrap commands in back-ticks so agents can copy-paste without guessing.
Update alongside code
Update alongside code
Treat AGENTS.md like code—PR reviewers should nudge updates when build steps
change.
One source of truth
One source of truth
Avoid duplicate docs; link to READMEs or design docs instead of pasting them.
Make requests precise
Make requests precise
The more precise your guidance for the task at hand, the more likely the agent
is to accomplish that task to your liking.
Verify before merging
Verify before merging
Require objective proof: tests, lint, type check, and a diff confined to agreed paths.
8 · How agents use AGENTS.md
1
Ingestion
On task start, agents load the nearest AGENTS.md into their context window.
2
Planning
Build/test commands are used to form the execution plan (e.g. run tests
after edits).
3
Tool selection
Folder and naming conventions steer tools like
edit_file
and
create_file
.4
Validation
Gotchas and domain vocabulary improve reasoning and reduce hallucinations.
9 · When things go wrong
Like any development work, agent tasks sometimes need course correction when scope creeps or assumptions prove wrong. The same iteration patterns that work with human collaborators apply here.Warning signs of agent drift:
- Plans that rewrite themselves mid-execution
- Edits outside the declared paths
- Fixes claimed without failing tests to prove they work
- Diffs bloated with unrelated changes
Recovery playbook:
- Tighten the spec: Narrow the directory or tests the agent may touch
- Salvage the good: Keep valid artifacts such as a failing test; revert noisy edits
- Restart clean: Launch a fresh session with improved instructions
- Take over: When you can tell the agent is failing, pair program the final changes
10 · Getting started
Specification Mode
Specs + AGENTS.md = instant context for new features.
Auto-Run
Reliable automation depends on accurate build & test commands.
Summary
- Add AGENTS.md at your repo root (and optionally submodules).
- Document build/test commands, conventions, and gotchas—concise & actionable.
- Agents read it automatically; no extra flags required.