Claude Code & Context Engineering

The AGENTS.md Field Guide: Portable Rules Every AI Coding Tool Respects

7 October 2026 · Updated 28 November 2026 · 12 min read · by Yang Kai

Write an AGENTS.md that Codex, Cursor and other agents actually follow: what ports from CLAUDE.md, what does not, and an annotated template to start from.

Template inside: Annotated portable AGENTS.md template

Contents
  1. The format in one table
  2. The six areas a complete file covers
  3. What ports cleanly from CLAUDE.md
  4. What does NOT port
  5. How the tools actually load the file
  6. An annotated portable AGENTS.md
  7. What this project is
  8. Commands (do not guess these)
  9. Stack and conventions
  10. Testing
  11. Git workflow
  12. Boundaries
  13. Definition of done
  14. When stuck
  15. The two-file architecture to run
  16. How we researched this

Keep instruction files for three different AI tools on one project and, in practice, you will maintain one and let two rot. The stale files are worse than no files: agents follow outdated commands with total confidence, and the failure looks like carelessness instead of what it is — a filing problem.

The fix is architecture, not discipline. One portable AGENTS.md carries the rules every tool needs, and each tool-specific file shrinks to only what is genuinely specific. This guide shows what a complete AGENTS.md contains, what ports from CLAUDE.md, what does not, and how the major tools actually load the file.

Everything mechanical here is checked against the agents.md format and the tools’ own documentation as of November 2026 — this corner of the tooling changed during 2026, and older advice about it is now partly wrong.

The format in one table

Fact What the spec and docs say
Format Plain Markdown. No required fields, no required sections, no special syntax
Steward The Agentic AI Foundation, under the Linux Foundation
Adoption 60,000+ open-source projects, per the agents.md site’s own count
Read by Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf, Devin, Zed, Aider, and more
Placement Repo root; additional files can nest inside subprojects
Precedence The file closest to the edited code wins; an explicit instruction in your prompt beats every file

That is the entire specification. The value is not in the format — it is in the file sitting at a path every tool already checks. Which makes the content the whole game.

The six areas a complete file covers

GitHub’s analysis of more than 2,500 AGENTS.md files found that the files which work cover six areas:

  1. Commands — the exact build, test, and check commands, with their flags.
  2. Testing — what must pass, and how to run a single test, not just the suite.
  3. Project structure — where things live, so edits land in the right layer.
  4. Code style — shown with an example, not described in prose.
  5. Git workflow — branching, commit, and pull-request expectations.
  6. Boundaries — what the agent must never touch.

The same analysis put commands early in the file, preferred one real code example over paragraphs of style description, and found “never commit secrets” to be the most common helpful boundary. An independent scan of 32 real AGENTS.md files found only 7 covering all six areas — most files in the wild are partial even before portability enters the picture.

For boundaries, the pattern GitHub’s analysis recommends is three tiers:

What ports cleanly from CLAUDE.md

The good news first: the core of any good instruction file is tool-agnostic, because it describes the project, not the agent. These sections transfer word for word:

Build, test, and check commands. Every agent needs them, every agent guesses them wrong when they are absent. This is the highest-value section in any dialect of the file.

Stack and package manager. Facts, not preferences. “npm, never pnpm in this repo” works everywhere.

Boundaries. Files and folders that must not be edited without asking. Every tool respects an explicit prohibition better than an implied one.

Style rules that can be checked. “Match the existing pattern in this folder” and “no new dependencies without asking” are portable because they reference the repo, not the tool.

Definition of done. Build passes, tests pass, summary of changes. Universal, because it describes your standards rather than the agent’s features.

If your CLAUDE.md is already lean — built along the lines of the CLAUDE.md that actually works — then most of it is already an AGENTS.md waiting to be renamed. The overlap is the point: project truth is project truth.

What does NOT port

The failures come from instructions that secretly depend on one tool’s features. Watch for these:

References to skills. A line like “use the release-notes skill” means something in Claude Code’s skills system and nothing to a tool without it. Portable version: describe the procedure inline in AGENTS.md, or link a plain doc in the repo that any agent can read. The skills directory shows how Claude packages procedures — but the content of a procedure must live somewhere tool-neutral if you want it shared.

Hook-dependent rules. “The formatter will fix it” assumes your Claude Code hooks are running. Other tools do not run your settings.json hooks. If formatting matters, the AGENTS.md must say “run the formatter” as an instruction, not assume it as infrastructure. For what hooks can enforce on the Claude side, see Claude Code hooks by event.

Slash commands and tool-specific syntax. Any instruction phrased as a product feature — specific commands, modes, or UI flows — is a dialect, not a standard. Keep dialects in the tool-specific file.

MCP assumptions. “Query the database server” presumes an MCP setup the other tool may not share. Name the underlying action and the plain fallback — where the connection details live, the CLI command — so any agent can complete the task. Setup differences like these are covered in Claude Code with MCP workflows.

Claude-specific memory behaviour. Notes about how a particular agent should use its memory or session features do not transfer, and worse, they confuse: a different tool may read the line and improvise an interpretation. Memory layering that stays inside one tool’s world belongs with that tool — the pattern version lives in agent memory patterns.

The rule underneath all five: if a rule names a feature, it does not port. If it names a fact about the project or a standard you hold, it does.

Three lines, rewritten portably

Most non-portable lines have a portable twin that loses nothing:

CLAUDE.md dialect Portable AGENTS.md version
“Run the release-notes skill before tagging” “Before tagging a release, update CHANGELOG.md from the merged PR titles since the last tag”
“The format hook will clean this up” “Run npm run format before finishing; CI rejects unformatted code”
“Ask the database MCP server for the schema” “Schema lives in db/schema.sql; read it before writing queries. Local DB: npm run db:local”

Read the right-hand column as a stranger’s tool would: every line is an action or a fact, executable with no knowledge of which agent is reading. That is the conversion to apply line by line when you migrate an existing file — and the reason the migrated file is usually better than the original, even for the tool it came from. Procedures written out in plain steps survive; procedures hidden behind feature names rot quietly.

How the tools actually load the file

Portability advice is useless without the loading rules, because each tool assembles the file differently. Checked against vendor documentation, November 2026:

Nesting (all tools). You can place an AGENTS.md inside a subproject as well as at the root. Per the agents.md site, agents read the nearest file in the directory tree, so the closest one to the code being edited takes precedence — and an explicit instruction in your chat prompt overrides every file.

Codex. Codex starts at the project root and walks down to your working directory, concatenating the files it finds; because the closer files appear later in the combined prompt, they override earlier guidance where they conflict. It also reads a personal file at ~/.codex/AGENTS.md, and an AGENTS.override.md in any directory takes precedence over the plain AGENTS.md there.

Claude Code. This is the part that changed. Since version 2.1.277 (September 2026), Claude Code reads AGENTS.md directly — as a fallback. If no CLAUDE.md or CLAUDE.local.md exists in the working directory or any directory above it, Claude Code loads AGENTS.md instead. If a CLAUDE.md exists anywhere in that chain, the AGENTS.md is ignored by default. The behaviour is switchable under Project instructions in /config, including a mode that loads both files. Caveats from Anthropic’s docs: the fallback is not yet available on Bedrock, Vertex, or Foundry deployments, and sessions that cannot fetch feature flags (telemetry disabled, for example) cannot use it. An AGENTS.md loaded through the fallback also does not appear in the /memory file list, which can make it look unloaded when it is not. The @AGENTS.md import inside CLAUDE.md remains the route that works everywhere, in every session type.

Everyone else. Cursor, Copilot, Gemini CLI, Windsurf, and the rest of the agents.md list read the file natively, each with its own additional rule system on top (.cursor/rules/, copilot-instructions.md, and so on). Those extras are dialects; the AGENTS.md underneath stays shared.

An annotated portable AGENTS.md

# AGENTS.md — [Project name]

<!-- Portable on purpose: no tool-specific features referenced.
     Tool-specific extras live in CLAUDE.md / .cursor/rules. -->

## What this project is
[Two lines: what it does, who it serves. Every agent makes
better trade-offs with this than without it.]

## Commands (do not guess these)
- Install: [npm install]
- Dev: [npm run dev]
- Build: [npm run build]
- Test: [npm run test — and how to run one test file]
- Lint/format: [npm run format — run before finishing]

## Stack and conventions
- [Framework + version, language strictness]
- Package manager: [npm] — do not use others in this repo
- Match the pattern of the file/folder you are editing
- No new dependencies without asking first

## Testing
- [What must pass before work counts as done]
- [Where tests live; add tests for new behaviour in (area)]

## Git workflow
- [Branch naming, commit style, PR expectations]
- Never commit directly to [main]; work on a branch

## Boundaries
- Always: [run the checks above before finishing]
- Ask first: [.env files, migrations, lockfile, published content]
- Never: [commit secrets, edit generated files]

## Definition of done
- [ ] Build passes and tests pass (commands above)
- [ ] Formatter has been run
- [ ] Summary states: what changed, what was NOT tested

## When stuck
- State what you tried and what failed. Do not invent
  file paths, APIs, or config keys — search the repo first.

Note what the template optimises for: a competent agent from any vendor, opening the repo cold, can work safely from this file alone. That is the correct bar for AGENTS.md. It will not contain your cleverest workflow tricks — those live in tool-specific layers — and that restraint is exactly what keeps it from rotting: there is little in it that can go stale except the commands, and commands announce their staleness loudly by failing.

The two-file architecture to run

In practice: AGENTS.md holds the portable core above, and it is the file to keep meticulously current. CLAUDE.md then becomes thin — mostly an @AGENTS.md import line plus only Claude-specific notes: which skills to prefer, hook behaviour to be aware of, subagent conventions. Other tools’ config files get the same thin treatment. One source of truth, small dialects at the edges.

When a command changes, you edit it in exactly one place, and every tool’s next session inherits the correction. The head-to-head reasoning behind this split — including when the Claude Code fallback makes even the import line unnecessary — is in AGENTS.md vs CLAUDE.md.

If you currently have only a CLAUDE.md, the migration is an afternoon’s light work: copy it, delete every line that names a Claude feature, check the remainder against the six areas, and save the result as AGENTS.md. Then slim the original down to the import line and the Claude-only notes. A good first file to practise the judgement on is your own — your first CLAUDE.md walks the beginner version of the same exercise.

If several people maintain the file, the failure mode changes from staleness to edit wars and silent divergence. CLAUDE.md for teams covers the review and ownership habits that apply to the shared file just as much as to the Claude-specific one.

How we researched this

This guide is desk research, not a benchmark. The format facts come from the agents.md site itself; the coverage findings from GitHub’s published analysis of 2,500+ files and the 32-file independent scan linked above; and every loading behaviour from the relevant vendor’s own documentation — OpenAI’s for Codex, Anthropic’s memory documentation for Claude Code — all checked in November 2026. Loading behaviour is the fastest-rotting part of this topic, so treat the version numbers as the facts to re-check first in your own setup before relying on them.

FAQ

What is AGENTS.md? A Markdown file at your repo root containing the instructions every AI coding tool should follow on that project: stack, commands, conventions, hard rules. It is an open format stewarded by the Agentic AI Foundation — plain text any agent can read, with no required sections.

Does Claude Code read AGENTS.md? Yes, since version 2.1.277 — as a fallback. If a folder and its parents contain no CLAUDE.md or CLAUDE.local.md, Claude Code loads the AGENTS.md instead. If a CLAUDE.md exists, it wins by default; you can load both via the Project instructions setting in /config, or import AGENTS.md from CLAUDE.md with an @AGENTS.md line, which works on every version and deployment.

How is AGENTS.md different from a README? A README explains the project to humans who are choosing or joining it. AGENTS.md instructs an agent that is about to change it: commands to run, lines not to cross, and what “done” means. Different reader, different document.

What does not port from CLAUDE.md? Anything Claude-specific: hook configuration, Claude Code slash commands, and references to Claude features such as skills. The test is simple — if a rule names a tool, it belongs in that tool’s file, not the shared one.

How long should AGENTS.md be? Short enough that every line earns its place. Practitioner consensus puts healthy files somewhere between roughly 60 and 300 lines, and Anthropic’s under-200-lines guidance for CLAUDE.md is a sensible ceiling to borrow. Rules an agent never acts on are not harmless; they dilute the ones that matter.

Category: Claude Code & Context Engineering · Tags: #agents-md #ai-coding #claude-code #ai-agents #claude-md

Next step: this article is part of Claude Code guides, which covers the full topic from first setup to advanced use.

Related guides