⚡ Standard & Skills

AGENTS.md best practices: write an instruction file coding agents actually follow

## Quick answer The core of AGENTS.md best practices is simple: keep one AGENTS.md at the root of your repo, keep it short, and write it as instructions, not description. Every rule should use an imperative verb and name a file, a command, or a tool the agent can act on. Point each agent's own instruction file at that one master file instead of keeping several copies. Move detail into linked docs, scoped rule files, or skills. Then test the file with real tasks and fix what the agent gets wrong. That is the whole method, and a study of 10,000 public repos explains why each part matters.

Test AGENTS.md rules: Write measurable rules, Run realistic tasks, Inspect changed files, Repeat across agents
Quick Answer

The core of AGENTS.md best practices is simple: keep one AGENTS.md at the root of your repo, keep it short, and write it as instructions, not description. Every rule should use an imperative verb and name a file, a command, or a tool the agent can act on. Point each agent's own instruction file at that one master file instead of keeping several copies. Move detail into linked docs, scoped rule files, or skills. Then test the file with real tasks and fix what the agent gets wrong. That is the whole method, and a study of 10,000 public repos explains why each part matters.

Why this matters now

On 21 October 2026, Gábor Mészáros published the Q3 2026 State of AI Instruction Quality report, built from a September 2026 snapshot of the 10,000 most-starred GitHub repos that ship an instruction file. The headline finding is convergence. AGENTS.md is becoming the shared instruction file across agents. In the top 100 repos, Claude Code is set up in 69, Copilot in 26, Gemini in 11, Cursor in 7, and Codex in 3, and 43.1 percent of repos with a mappable setup run two or more agents at once. The most common pairing is Claude Code plus AGENTS.md, found in 2,399 repos.

The pointer counts make the direction plain. Of 5,464 CLAUDE.md files, 998 (18.3 percent) are 25 words or fewer and simply point at AGENTS.md. Going the other way, only 39 of 6,128 AGENTS.md files point at CLAUDE.md. That is a ratio of 26 to 1. Another 11.3 percent of GEMINI.md files point at AGENTS.md, and 4.0 percent of Copilot instruction files do the same. Teams are not standardising on five files. They are standardising on one file with pointers.

The same study shows why most instruction files underperform. The CLAUDE.md files that teams do write are the least instruction-like main files of any agent: only about a quarter of their content tells the agent what to do, and the rest describes the project. Claude Code setups hedge less than others, at a median of 3.3 hedged phrases per 100 instructions against 4.7 for the field, but hedging is common everywhere. OpenAI repos leave a median of 48.7 of every 100 instructions without a file, command, or tool to act on, against 30.8 for the field. An instruction that names nothing is a guess the agent has to make, and guesses are where agent work goes wrong.

Two more findings shape the method below. Skills now hold 42.3 percent of all directives and constraints in the set, against 31.3 percent for all main files combined, so the main file is no longer where most rules live. And 221 repos already keep two copies of their main file that have drifted apart, typically sharing 32 lines while each side carries two or three lines the other lacks. One master file with pointers is how you avoid becoming repo 222.

What you need

  • A repo you work in with a coding agent
  • Any of Claude Code, Codex, Copilot, Cursor, or Gemini CLI
  • About 30 minutes for the first version, and a real task to test it with
  • No new tools, no accounts, and no paid services for the core method

AGENTS.md best practices: the eight steps

Step 1: Create one master file at the repo root

Create AGENTS.md in the repo root and commit it, so the whole team shares it. This file is the single source of truth. Every other instruction file in the repo should point at it, not restate it. If you run Claude Code, keep CLAUDE.md as a one line pointer that reads @AGENTS.md. Repeat the pattern for each agent you run, using that agent's documented instruction file as the pointer. One file to edit means one file that can stay current.

There is one exception to the pointer pattern, and it comes from the study. Gemini CLI concatenates AGENTS.md and GEMINI.md, and 21.4 percent of Gemini setups already carry identical text in both files. Do not duplicate text for Gemini. A pointer there means the agent reads the same rules twice, which wastes context and invites contradictions. For Gemini, rely on the shared file and keep GEMINI.md empty or absent unless you have a Gemini-only rule.

Step 2: Write the skeleton before you write the rules

A file the agent can scan beats a file the agent has to mine. Use this skeleton, in this order, and fill each section with lines, not paragraphs.

  • Critical rules: the two or three constraints that must never be violated, at the top
  • Project: one paragraph on what the project is and who it serves
  • Tech stack: a small table of language, framework, database, and key versions
  • Commands: the exact install, dev, test, lint, and build commands
  • Conventions: imperative bullets for code style, naming, and architecture decisions
  • Boundaries: what the agent must never do, and what it must ask about first
  • Pointers: links to deeper docs, such as an architecture note or API reference

Critical rules go first because emphasis matters. Guides based on Anthropic's documentation recommend putting non-negotiable constraints at the top of the file, and the study's drift finding is a warning about what happens when rules are scattered: copies diverge and nobody knows which version is true.

Step 3: Convert every description into an instruction

This is the step that fixes the study's biggest failure mode. Read each line and ask whether it tells the agent to do something specific. A line that only describes the project is not a rule, and the study found that most of what teams write falls in that bucket.

Rewrite description as imperative, and attach a file, command, or tool to each rule. "The project uses functional components with hooks" becomes "Use functional components with hooks. Never use class components." "Write clean code" becomes "Use snake_case for database columns. See docs/schema.md for the naming table." The second version in each pair can be checked. The first version cannot, and an agent that cannot check a rule will interpret it, which is a polite word for guessing.

Add a one clause reason only where the rule is not obvious. A bare rule generalises poorly when the agent meets a case you did not picture, and a short reason gives it something to reason with. Keep the reason to one clause. If the reason needs a paragraph, it belongs in a linked doc, not in the main file.

Step 4: Cut the file to under 200 lines

Guides based on Anthropic's documentation recommend keeping the file under 200 lines, and in practice 50 to 100 lines cover most projects. Length is not a virtue here. The file loads into every session, so every line costs context on every task, and rules buried at the end of a long file get lost. The study adds a sharper warning for Gemini setups: 8.1 percent hand the agent more than 5,000 words before the first prompt, against 2.3 percent across the field. Long files are a tax the agent pays before it does any work.

Cutting is a mechanical job. Move reference material into linked docs and point at them instead of pasting them. Move task-specific detail into scoped rule files, such as .claude/rules/ for Claude Code, or into skills that load only when the task matches. Move repeated workflows into skills outright, since skills now carry more directives than main files do. What stays in AGENTS.md is what the agent needs on every session: the critical rules, the commands, the conventions, and the boundaries.

Step 5: Remove hedges, shouting, and soft language

Hedged rules read like suggestions, and agents treat them that way. Replace "should" and "try to" with direct verbs wherever the rule is real. "Tests should cover new code" becomes "Add tests for new code. Run the full suite before opening a pull request." The study counted hedged phrasing across agents and found Claude Code setups hedge least, but no agent family is clean, so check your own file line by line.

Drop capital letter shouting at the same time. Anthropic's own prompting guide tells users of its newest models to dial that language back, advising "Use this tool when..." in place of "CRITICAL: You MUST use this tool when...". Reserve strong emphasis for the two or three critical rules at the top of the file. When every rule shouts, the agent learns that nothing is urgent, and the genuinely critical rule drowns with the rest.

Step 6: Keep secrets, linter rules, and one-off tasks out of the file

Three kinds of content do not belong in AGENTS.md, and each one causes a different failure. Secrets do not belong there because the file is committed to version control, and a committed secret is a leaked secret. Linter rules do not belong there because a deterministic tool enforces them better than a language model can; tell the agent which lint command to run, not which quote style to prefer. Task-specific instructions do not belong there because they rot: a rule about a feature you shipped last month will mislead the agent for the rest of the year. Put one-off instructions in the conversation instead, and delete rules the day they stop being true.

Step 7: Test the file with three real tasks

A file you have not tested is a guess, and the test takes ten minutes. Run three tasks through your agent and watch what it does.

  1. A normal task that should trigger a convention, such as adding a small feature in an existing module. Check that the agent follows the naming, structure, and test rules without being reminded.
  2. An edge case the file should handle, such as a change that touches a deprecated directory or a shared utility. Check that the boundary rule fires.
  3. A forbidden action, such as editing a migration by hand or committing without tests. Check that the agent refuses or asks first, exactly as the boundary says.

If you want a deterministic second opinion, run the check tool from the study itself: npx @reporails/cli check. It reads your instruction files with fixed rules and lists findings by file, so you can read each finding and decide whether it is fair. The tool is free to run and needs no account. Treat its output as a review, not a verdict, and fix the findings you agree with.

Step 8: Maintain the file after every agent mistake

A stale instruction file is worse than an empty one, because the agent follows the wrong rule with confidence. Adopt one maintenance rule: every time the agent makes a preventable mistake, the missing boundary goes into AGENTS.md the same day. Every time a pattern becomes established, it goes in as a code example. Every time a dependency is upgraded or a command changes, the file changes in the same commit. Review the file quarterly, remove stale content, and verify that every example still compiles and every command still runs. The study's drifted pairs are what happens when teams skip this step: two files, each partly right, and no one sure which one the agent read.

Copy-paste template

Replace the placeholders with your project details, then delete any section your project does not need. Keep the result under 200 lines.

# AGENTS.md: [project name]

## Critical rules
- Never commit secrets. Use environment variables and the `.env.example` file.
- Run the full test suite before opening a pull request.
- Ask before deleting files, changing migrations, or adding dependencies.

## Project
[One paragraph: what this project is, who it serves, and the one architectural
idea a new contributor must grasp first.]

## Tech stack
| Layer | Technology |
|---|---|
| Language | [for example, TypeScript 5] |
| Framework | [for example, Next.js 15] |
| Database | [for example, PostgreSQL 16] |

## Commands
- `npm install`: install dependencies
- `npm run dev`: start the development server
- `npm test`: run the test suite
- `npm run lint`: check code style
- `npm run build`: build for production

## Conventions
- Use named exports, not default exports.
- Keep functions short and name them for what they return.
- Put database access in `src/repos/`. Never query from route handlers.
- Follow the existing pattern in the file you are editing before inventing one.

## Boundaries
- Never edit files under `legacy/`. That directory is deprecated.
- Never rewrite a migration. Add a new one instead.
- Ask before changing public API shapes or error responses.

## Pointers
- Architecture notes: `docs/architecture.md`
- API reference: `docs/api.md`
- Coding standards detail: `docs/style.md`

What to do if it fails

Symptom Likely cause Fix
Agent ignores a rule Rule is vague, buried, or contradicted elsewhere Rewrite it as an imperative, move it to the top section, add a concrete example
Agent follows an old rule File is stale, or you edited a copy instead of the master Edit only the master AGENTS.md, delete duplicate files, turn the rest into pointers
Two files disagree Copies drifted apart Delete one copy, point it at the master, and re-run the three task test
File keeps growing Reference material and task detail piling up Move detail to linked docs, scoped rules, or skills, and keep the main file under 200 lines
Agent guesses instead of following Rule names no file, command, or tool Attach a concrete target to every rule, as in step 3
Agent reads the same rules twice Duplicated text across agent files, common with Gemini Remove the duplicate text and rely on the shared file

Test whether an agent follows AGENTS.md

An instruction file is configuration, so test its effects. Build a small repository fixture with tasks that exercise each important rule: a required test command, a forbidden file, a formatting convention and a rule about asking before a risky action. For each task, write the expected behavior before you run the agent.

Use a clean session and a harmless test branch. Inspect the diff, commands and tool actions, not only the assistant's explanation. Repeat the same cases after changing the instruction file or assistant, and include at least one task where the rule does not apply so you can catch overbroad behavior. Keep the fixture synthetic and avoid real credentials. This measures compliance on selected cases; it does not guarantee every future session will follow every rule. The shared agent memory guide explains how to keep canonical project guidance maintainable.

Frequently asked questions

Yes, as the shared file, with one caveat. Each agent reads its own instruction path, so you keep the master AGENTS.md and point each agent's own file at it. The exception is Gemini CLI, which reads both AGENTS.md and GEMINI.md together, so duplicating text there means the agent reads every rule twice. For Gemini, rely on the shared file and keep GEMINI.md empty or absent unless you have a Gemini-only rule.

Keep it under 200 lines. In practice, 50 to 100 lines cover most projects. Detail belongs in linked docs, scoped rule files, or skills that load only when the task matches. If your file passes 200 lines, it is time to split it, not to keep appending.

No. If you run Claude Code, keep CLAUDE.md as a one line pointer that reads `@AGENTS.md`. Deleting the agent's own file gains nothing, and the pointer pattern is exactly what the study found winning: 26 CLAUDE.md pointers for every one AGENTS.md pointer in the other direction.

No, they split the job. AGENTS.md holds always-on project rules that load every session. A skill holds on-demand know-how that loads only when a request matches its description. The study found skills now carry 42.3 percent of all directives, against 31.3 percent for main files, so most teams need both: a short master file plus skills for repeated workflows.

Treat them as one study's findings, not as settled fact. The author discloses that he works on Reporails, the company behind the `ails check` tool used for the measurements, so the study comes from a vendor with a product in this space. The methodology is public: 10,000 repos, a September 2026 snapshot, and definitions for pointers, setups, and instruction counts published in the article. The writing rules in this guide do not depend on the exact percentages, since they match independent guides based on Anthropic's documentation. Use the numbers as direction, and test the rules in your own repo.

Conclusion

AGENTS.md best practices come down to one discipline: a single short master file, written as checkable instructions, pointed at by every agent you run, and maintained after every mistake. The study gives the trend a number, with AGENTS.md pointers outnumbering the reverse 26 to 1, but the practice itself is older than the trend. Write rules the agent can verify, cut everything the agent does not need every session, and test the file with real tasks before you trust it. Teams that do that get agents that follow the project instead of improvising it.

Build the repeated workflows in your file into skills with the Skill Builder, validate them with the Quality Check Builder, and browse production examples in the Skills Directory. For the full story of how skills and instruction files fit together, see the guide to one SKILL.md for every agent.

For a tool-by-tool setup using one shared project memory across Codex, Gemini CLI and Claude Code, continue with the AI coding agent memory guide.

Sources and references

  • State of AI Instruction Quality: Coding Agent Comparison, Gábor Mészáros, Medium, published 21 October 2026: https://cleverhoods.medium.com/state-of-ai-instruction-quality-coding-agent-comparison-c6127c49bebd (all study numbers in this post come from this article; the author discloses working on Reporails)
  • CLAUDE.md Best Practices vs System Prompts in 2026, systemprompt.io: https://systemprompt.io/guides/system-prompts-vs-claude-md (CLAUDE.md mechanics, hierarchy, and the under 200 lines guidance as summarised from Anthropic's documentation)
  • CLAUDE.md: The File That Changes How Claude Codes Your Project, koriigami.com: https://www.koriigami.com/blog/claude-md-guide (imperative form, bullet format, reference instead of embed, secrets and linter exclusions)
TJ Singh

TJ Singh

Creative Technologist, AI Systems Architect, and author of the PromptStaging suite. Focused on Generative Engine Optimization (GEO), agent developer workflows, and client-side web utilities.

Test whether an agent follows AGENTS.md

A rule file is useful only when the agent discovers it and follows it on real work. Use a disposable repository without production credentials. Define expected behavior before each task and inspect the diff instead of asking whether the agent read the rules.

Eight-case instruction compliance suite

  1. Discovery: request a small task and check whether root instructions apply.
  2. Architecture: request a boundary-touching change and verify the declared pattern remains.
  3. File scope: name allowed files and check that no unrelated files changed.
  4. Verification: require a named check and see if it actually runs.
  5. Honest reporting: make a check fail and verify the report says so.
  6. Deployment boundary: state production actions are out of scope and verify none occur.
  7. Nested rules: test which instructions apply in a subdirectory.
  8. Conflict: introduce a lower-priority conflicting request and check precedence.

Record task, agent/version, instructions present, expected behavior, changed files, commands run and outcome. Compare assistants on the same repository snapshot; settings and model versions can also explain differences.

Fix rules that repeatedly fail

Make instructions short, observable and testable. Replace “be careful” with a specific boundary, allowed path or required check. Link deeper explanations instead of repeating them. Enforce requirements that must always hold with tests, permissions or CI too; an instruction file cannot technically prevent every violation.

Test AGENTS.md rules: Write measurable rules, Run realistic tasks, Inspect changed files, Repeat across agents
Write measurable rules → Run realistic tasks → Inspect changed files → Repeat across agents