Dev tools
AGENTS.md and CLAUDE.md: Giving Coding Agents Context
What AGENTS.md and CLAUDE.md files are, how coding agents read them, what to put in them, and how to keep one set of instructions for every tool.
AGENTS.md is a plain Markdown file in your repository that tells AI coding agents how your project works: how to install it, how to run the tests, which conventions to follow and what to avoid. CLAUDE.md does the same job for Claude Code. Instead of repeating the same explanations in every chat, you write them down once, and the agent reads them at the start of each session.
These files are one of the simplest ways to get better results from a coding agent. This guide explains what each file is, how the tools load them, what to write in them, and how to keep a single source of truth when your team uses several agents. For a broader introduction to working with Claude Code, see our guide on how to use Claude Code.
What Is AGENTS.md?
AGENTS.md is an open, tool-neutral format for giving instructions to coding agents. Think of it as a README for agents: the README explains the project to people, while AGENTS.md holds the practical details an agent needs to work on it, which might clutter a human-facing README.
It has no required structure. It's just Markdown, with headings and lists for whatever matters in your project. OpenAI introduced the format with Codex, and it's now looked after by the Agentic AI Foundation under the Linux Foundation, alongside the Model Context Protocol. Many tools read it, including OpenAI Codex, Google Jules, Gemini CLI, Cursor, GitHub Copilot's coding agent, VS Code, Devin, Amp and Claude Code.
What Is CLAUDE.md?
CLAUDE.md is Claude Code's own project instructions file. Claude Code reads it at the start of every session and treats its contents as context. It supports a few extras that plain AGENTS.md doesn't:
- Several levels: personal instructions in
~/.claude/CLAUDE.mdfor all your projects, shared project instructions in./CLAUDE.mdor./.claude/CLAUDE.md, and personal project notes in./CLAUDE.local.md, which you add to.gitignore. - Imports: a line such as
@docs/testing.mdpulls another file into the instructions. Imported files can import others, up to four levels deep. - Rules folder: Markdown files in
.claude/rules/split instructions by topic, and can be scoped to specific file paths so they only load when relevant. - Organisation-wide instructions: companies can deploy a managed CLAUDE.md that applies to every developer's machine.
Running /init in Claude Code creates a starting CLAUDE.md from your codebase, with build commands, test instructions and conventions it discovers.
How Claude Code Reads AGENTS.md and CLAUDE.md
Recent versions of Claude Code, from v2.1.277, can read AGENTS.md directly. By default:
- If your repository has an AGENTS.md and no CLAUDE.md, Claude Code reads the AGENTS.md as its project instructions.
- If it has both, Claude Code reads only the CLAUDE.md files.
- If your CLAUDE.md imports AGENTS.md with a line like
@AGENTS.md, Claude Code reads both, with AGENTS.md included through the import.
For this check, a CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md in your working directory or any folder above it counts. Your personal ~/.claude/CLAUDE.md and .claude/rules/ files don't, and load alongside AGENTS.md.
You can change the default with the Project instructions setting in /config, for example to always read both files. Claude Code doesn't read AGENTS.local.md, AGENTS.override.md or files under an .agents/ folder, which some other tools use.
One File for Every Coding Agent
If your team uses more than one coding agent, keep a single source of truth:
- Put the shared instructions in AGENTS.md at the root of the repository.
- If you need Claude-specific instructions, create a short CLAUDE.md that imports the shared file and adds only what's different:
@AGENTS.md
## Claude Code
- Use plan mode for changes that touch more than three files.
- Run the linter before every commit.This way every agent sees the same build commands and conventions, and nobody has to update three files when something changes. If you don't need anything Claude-specific, a plain AGENTS.md is enough for recent versions of Claude Code.
What to Put in Your Project Instructions
Good project instructions contain the things an agent can't easily discover by reading the code, or would otherwise get wrong. Here is a useful structure for an AGENTS.md file:
## Project
Online booking service for clinics. Go backend in /server, React frontend in /web.
## Setup and commands
- Install: `make deps`
- Run locally: `make dev` (needs Docker running)
- Tests: `make test`; run a single package with `go test ./server/booking/...`
- Lint: `make lint` must pass before committing.
## Conventions
- Database changes go in /migrations as numbered SQL files; never edit an old migration.
- Use the existing logger in /server/log, not fmt.Println.
- Frontend components use TypeScript and live next to their tests.
## Don't
- Don't change files in /vendor or /generated.
- Don't add new dependencies without asking.
- Never commit secrets; use .env.example for new settings.
## Pull requests
- Small, focused changes with a clear description and tests.The most valuable lines are usually:
- Exact commands for installing, running, testing, linting and building.
- Project layout: where the main parts live.
- Conventions the code doesn't make obvious, such as naming, error handling or which library to use.
- Boundaries: files and folders not to touch, and actions that need approval.
- Gotchas: things that waste time, such as a service that must be running first, or a slow test suite to avoid.
Writing Instructions a Coding Agent Follows
A coding agent treats these files as guidance, not as hard rules. Clear, short instructions are followed much more reliably than long ones:
- Keep it short. Claude Code's documentation recommends keeping each CLAUDE.md under about 200 lines; longer files use more context and are followed less consistently.
- Be specific. "Run
make testbefore committing" works better than "make sure the code is tested". - Use headings and bullet points so the agent can find the right part quickly.
- Remove contradictions. If two instructions conflict, the agent may follow either one.
- Update it when the agent makes a mistake. If it keeps running the wrong command, add the right one.
- Leave out what the code shows. Don't describe every file; the agent can read them.
Everything in these files uses up part of the model's working memory in every session. Our guide to the context window explains why that space is worth protecting.
Nested Files in Large Repositories
In a monorepo, different parts of the code often need different instructions. Both formats support files in subfolders:
- AGENTS.md: you can place additional AGENTS.md files in subprojects. Tools that support nesting use the one closest to the files being edited.
- CLAUDE.md: Claude Code loads CLAUDE.md files from your working directory and the folders above it at the start, and loads files in subfolders when it starts working there. Path-scoped rules in
.claude/rules/load only when Claude touches matching files.
Keep shared rules at the root and put team- or package-specific instructions next to the code they describe.
A Context File Is Guidance, Not Security
A context file shapes what the agent tries to do, but it doesn't enforce anything. If something must never happen, such as deleting production data or reading secret files, use the tool's permission settings, hooks or sandboxing rather than relying on a line in a Markdown file.
Also review instruction files in pull requests like any other code. Because agents follow them, a malicious or careless change to AGENTS.md can steer an agent in harmful ways.
Choosing Between AGENTS.md and CLAUDE.md
- Your team uses several coding agents: use AGENTS.md as the main file, and add a small CLAUDE.md that imports it only if you need Claude-specific features.
- Your team uses only Claude Code: CLAUDE.md gives you imports, rules and personal files; you can still import an AGENTS.md later.
- Open-source project: AGENTS.md is the friendliest choice for contributors who use different tools.
If you're still choosing tools, our Claude Code vs Cursor comparison covers how two popular agents differ.
FAQ
What is AGENTS.md?
AGENTS.md is an open Markdown file format that gives AI coding agents instructions about a project, such as setup commands, tests, conventions and boundaries. Many coding tools read it, including Codex, Cursor, Gemini CLI, GitHub Copilot and Claude Code.
Does Claude Code read AGENTS.md?
Yes. From version 2.1.277, Claude Code reads AGENTS.md when the repository has no CLAUDE.md or CLAUDE.local.md. If you have both, it reads CLAUDE.md, which can import AGENTS.md with a line such as @AGENTS.md.
What is the difference between AGENTS.md and CLAUDE.md?
AGENTS.md is a tool-neutral format shared by many coding agents. CLAUDE.md is Claude Code's own file and adds features such as imports, personal and organisation-wide instructions, and path-scoped rules.
How long should an AGENTS.md or CLAUDE.md file be?
As short as possible while covering what the agent can't discover itself. Claude Code's documentation suggests under about 200 lines per CLAUDE.md; move details that apply to only part of the codebase into nested files or scoped rules.
Should I commit AGENTS.md to the repository?
Yes. Shared project instructions belong in version control so the whole team and every agent use the same guidance. Keep personal preferences in files that aren't committed, such as CLAUDE.local.md.