AGENTS.md Template: One File for Claude Code, Codex and Cursor (Plus a HANDOFF.md)
Published Oct 19, 2026 · 6 min read
If you use more than one coding agent, you probably have a CLAUDE.md, a .cursor/rules folder and an AGENTS.md that slowly drift apart. The fix is one source of truth: an AGENTS.md at the repo root that every tool reads. Below is how each tool picks it up (checked against the official docs in October 2026), a copy-paste template, and a short HANDOFF.md pattern for switching tools mid-task and staying on track after context compaction.
How each tool reads AGENTS.md
- Codex reads
AGENTS.mdbefore doing any work. It checks~/.codex/AGENTS.mdfirst, then each directory from the project root down to your working directory, one file per directory (anAGENTS.override.mdwins in its directory). Files closer to where you are come later and override earlier guidance. The combined default limit is 32 KiB (project_doc_max_bytes)./initgenerates a starter file. - Cursor supports
AGENTS.mdin the project root and in subdirectories as a plain-markdown alternative to.cursor/rules. No frontmatter. Nested files are combined with their parents, and the more specific one takes precedence. - Claude Code (v2.1.277 or later) can read
AGENTS.mddirectly, but by default only when there is noCLAUDE.md,.claude/CLAUDE.mdorCLAUDE.local.mdin your working directory or above it. If you have one of those, Claude reads it instead. Some sessions can't readAGENTS.mddirectly at all, so the reliable setup is a smallCLAUDE.mdthat imports it.
The CLAUDE.md bridge
Put this next to AGENTS.md. The @AGENTS.md line imports the file, so Claude reads it first and then your Claude-only notes. Run /context in a new session to confirm it loaded.
@AGENTS.md
## Claude Code only
- Use the code-reviewer subagent before calling a task done.
## Compact Instructions
- Keep the current goal and the first unchecked item in HANDOFF.md.
If you don't need Claude-only lines, Anthropic's docs also allow a symlink (ln -s AGENTS.md CLAUDE.md), but recommend the import if anyone on the repo uses Windows.
The AGENTS.md template
# AGENTS.md
<One sentence: what this project is and who uses it.>
## Commands
- Install: `<pnpm install>`
- Dev: `<pnpm dev>`
- Test: `<pnpm test>` (one file: `<pnpm test -- path>`)
- Lint: `<pnpm lint>`
- Typecheck: `<pnpm typecheck>`
## Layout
- `src/<area>/`: <what lives here>
- `tests/`: mirrors src/
## Conventions
- <Language rule, e.g. strict TypeScript, no any>
- <Architecture rule, e.g. no DB calls from UI components>
- <Naming rule>
## Definition of done
1. Tests, lint and typecheck pass
2. New behavior has a test
3. `HANDOFF.md` is up to date
## Guardrails
- Never edit .env*, lockfiles or migrations already applied
- Never add a dependency without asking
- If requirements are unclear, ask one question instead of guessing
## Long tasks and handoffs
- At the start of a session, read `HANDOFF.md` if it exists.
- After each finished step, update `HANDOFF.md`: done, next, decisions, open questions.
- Before you stop, or when asked to hand off, make HANDOFF.md current.
Three notes on the template:
- Keep it tool-neutral. Anything only one agent understands (subagents, hooks,
.mdcglobs) goes in that tool's own files. - Keep it short. Anthropic recommends under 200 lines per instruction file, and Codex stops adding files at 32 KiB by default.
- Write
HANDOFF.mdin backticks, not as@HANDOFF.md. In Claude Code an@pathoutside a code span is imported at launch. In backticks it stays a pointer the agent opens when told to.
HANDOFF.md: switch tools mid-task
HANDOFF.md is a convention, not a built-in feature of any of these tools. It's a short progress file at the repo root that any agent can read and update.
# HANDOFF
Updated: <YYYY-MM-DD HH:MM> by <tool>
Goal: <one line: what "finished" looks like>
Branch: <branch> Last commit: <sha or "uncommitted">
## Done
- [x] <step> (<files touched>)
## Next
- [ ] <the very next concrete step>
- [ ] <the step after that>
## Decisions (don't reopen)
- <decision>: <one-line reason>
## Open questions / blockers
- <question>
## How to verify
- `<pnpm test -- path/to/feature>`
To switch tools:
- In the current tool: "Update HANDOFF.md as described in AGENTS.md, then stop."
- Commit or stash so the working tree matches what the file says.
- In the next tool: "Read HANDOFF.md and continue with the first unchecked item under Next."
Because the next tool also reads AGENTS.md, it starts with the same commands, conventions and guardrails. Commit HANDOFF.md on the feature branch if teammates or cloud agents will pick the work up; otherwise add it to .gitignore.
Staying on track after compaction
Long sessions get summarized. Codex has /compact, which replaces earlier turns with a summary. Claude Code compacts automatically as the context fills, and its docs warn that detailed instructions from early in the conversation may be lost. What lives in files holds up better: Claude Code re-reads the project-root CLAUDE.md from disk after compaction.
- Move anything that must persist out of chat and into
AGENTS.md. - Keep the plan in
HANDOFF.md. Then a lossy summary only needs to remember one thing: read the file. - Steer the summary. In Claude Code, run
/compact focus on <task>, or add a "Compact Instructions" section toCLAUDE.mdlike the bridge above. - Restart after editing instructions. Codex builds its instruction chain once per run, so start a new session to pick up changes.
Where tool-specific files still fit
AGENTS.md holds what every agent needs. Keep the rest where it belongs: glob-scoped Cursor rules in .cursor/rules/*.mdc (see Cursor rules examples), Claude-only memory in a lean CLAUDE.md (see the CLAUDE.md template), specialist agents in Claude Code subagents, and must-never rules in Claude Code hooks, because an instruction file is guidance and a hook is a guarantee. If you mostly work in Cursor, the Cursor Rules Pack ($19) ships 18 .mdc rules plus an AGENTS.md template.
Skip the setup
The Claude Code Agent Starter Kit ($39) includes CLAUDE.md templates for Next.js, Python/FastAPI, Node APIs, game dev (Godot/Unity) and monorepos, plus the subagents, skills and safety hooks they refer to.
FAQ
Does Claude Code read AGENTS.md?
Yes, Claude Code v2.1.277 and later can read AGENTS.md directly, but by default only when there is no CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md in your working directory or above it. If you have one, put @AGENTS.md at the top of CLAUDE.md so the file is imported.
Does Cursor support AGENTS.md?
Yes. Cursor reads AGENTS.md in the project root and in subdirectories as plain markdown with no frontmatter. Nested files are combined with their parents, with the more specific file taking precedence. Use .cursor/rules/*.mdc when you need glob-scoped rules.
Where does Codex look for AGENTS.md?
Codex reads ~/.codex/AGENTS.md (or AGENTS.override.md) first, then one file per directory from the project root down to your working directory, preferring AGENTS.override.md over AGENTS.md. The combined default limit is 32 KiB.
What is a HANDOFF.md file?
A convention, not a built-in feature of any tool: a short progress file at the repo root with the goal, what is done, the next step, key decisions and how to verify. Your AGENTS.md tells every agent to read it at the start of a session and update it after each step, so you can switch tools or recover after compaction.