Every coding agent now reads a Markdown file from your repository before it
starts work. Claude Code reads CLAUDE.md. Codex, Copilot, Grok Build (called
Cursor until 30 November) and most of the others read AGENTS.md. What goes in that
file shapes every session, and it is easy to spend its length on things the
agent could have worked out for itself.
This is the first of three posts on configuring a coding agent. It covers the instruction files. The next two cover the parts that are enforced rather than requested: settings and auto mode, then the deny list and hooks.
What these files are
They are context. The agent reads the file the way it reads your prompt, and then it uses its judgement.
Claude Code's documentation is exact about this. CLAUDE.md is delivered as a
user message after the system prompt, not as part of it. Claude tries to follow
it, with no guarantee of strict compliance, especially where instructions are
vague or conflict. The docs call it context, not enforced configuration.
Everything else in this post follows from that. An instruction file is the right place for "here is how we do things" and the wrong place for "this must never happen".
Which file
AGENTS.md is the shared format: plain Markdown, no required fields, now
stewarded by the Agentic AI Foundation under the Linux Foundation. Codex, GitHub
Copilot, Jules, Grok Build and Devin Desktop read it without being told to. Grok
Build is what Cursor became on 30 November 2026, and Devin Desktop is the name
Cognition gave Windsurf in June. Zed also reads it, unless it finds one of the
files it checks first, such as a .rules. Aider and Gemini CLI need pointing at
it in their own config.
Claude Code reads it too, since v2.1.277, with one condition by default: only
when there is no CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md in the
working directory or above it. If both kinds exist, Claude reads the CLAUDE.md
and ignores the other. The Project instructions setting in /config changes
that default, for example to read both.
So for a repository more than one tool works on, keep the instructions in
AGENTS.md, and if you need Claude-specific lines as well, add a CLAUDE.md
that imports it:
@AGENTS.md
## Claude Code only
- Use plan mode for anything that touches migrations.
Don't use a symlink for this if anyone on the project works on Windows. Creating
one needs Administrator rights or Developer Mode, and Git checks a committed
symlink out as a plain text file unless core.symlinks is on, which leaves that
clone with a one-line CLAUDE.md and no instructions.
The tool-specific files still exist: .github/copilot-instructions.md,
.cursor/rules/*.mdc (Grok Build kept the folder name), GEMINI.md. Reach for
one only when you need something the shared file can't express, such as rules
scoped to a glob of files. Three files that say the same thing become three
files that say different things.
How they load
In Claude Code, instruction files are found in several places and concatenated,
broadest first: an organization's managed file, your own ~/.claude/CLAUDE.md,
then every CLAUDE.md from the top of the directory tree down to the directory
you started in, so the closest file is read last. A CLAUDE.local.md beside a
CLAUDE.md holds what you don't want to commit. Nothing overrides anything. It
all goes in.
One trap: in a project that relies on AGENTS.md, a CLAUDE.local.md counts as
a CLAUDE.md, so adding one stops Claude reading AGENTS.md for you. Set
Project instructions to claude-md-and-agents-md to keep both.
Files in subdirectories are different: they load on demand, when Claude reads or
edits a file in that directory. That is the tool for a monorepo. The same idea
applies to AGENTS.md elsewhere, where the nearest file to the code being
edited wins.
Two details are worth knowing. Rules in .claude/rules/*.md can carry a paths
entry in their front matter, and then load only when Claude reads, writes or
edits a matching file. And @imports organize a long file without shrinking it:
an imported file loads along with the file that imports it, so it costs the same
context.
Do
Write down what can't be inferred. The agent can read your composer.json
and work out that the project uses PHPUnit. It can't work out which order two
tools have to run in. This site's README has a line of exactly the right kind:
run cs-fix after rector-fix, because Rector changes structure and leaves the
formatting to PHP-CS-Fixer. Nothing in the code says that.
Give exact commands. "Run docker compose exec php vendor/bin/phpunit" is
an instruction. "Make sure the tests pass" is a hope.
Explain what looks wrong but isn't. Every codebase has a few things a careful newcomer would "fix". Say what they are and why they are that way.
Keep it short. Claude Code's docs say to aim for under 200 lines per file, because longer files use more context and are followed less well. Grok Build's docs suggest keeping each rule under 500 lines. Codex stops adding instruction files once their combined size reaches 32 KiB by default. These are ceilings. Most projects need far less.
Scope what is local. An instruction about the API layer belongs in a path-scoped rule or a nested file, where it is loaded when relevant and not otherwise.
Review changes to it like code. A line in this file changes what an agent does on every developer's machine. Put it under the same review as a CI workflow, with a code owner.
Prune it. When the agent gets something wrong twice, add a line. When a line
has stopped earning its place, delete it. Claude Code's /doctor prompt-audit
looks for instructions that contradict each other or name files that no longer
exist, and proposes edits. Block-level HTML comments are stripped before the
file is injected, so a note to the next maintainer about why a line exists costs
nothing.
Don't
Don't paste in a tour of the repository. A directory tree and a paragraph per folder is common content in these files, and the best evidence so far says it doesn't help. A 2026 study from ETH Zurich and LogicStar.ai tested context files across several agents and models. It found they did not generally improve task success, and raised inference cost by more than 20% on average. Agents followed the instructions well. Repository overviews, specifically, were not helpful. The authors' conclusion is the useful part: these files are good for specifying non-standard practices.
Don't generate it and walk away. /init will write a CLAUDE.md from your
codebase, and it is a reasonable first draft. It is also, by construction, made
of things discoverable from the codebase. Treat it as a draft to cut down.
Don't use it for prohibitions that matter. "Never force-push" in
CLAUDE.md is a request. It is a useful one, and in auto mode the classifier
reads the file as well, so it steers two models and not one. It is still not a
block. If it has to hold, it is a deny rule or a hook.
Don't restate the linter. If a formatter enforces it, a hook or CI should run the formatter. Prose style rules spend context on something a tool does better.
Don't put secrets in it. It is committed, and its contents go to the model at the start of every session.
Don't trust one you didn't write. An instruction file in a repository you just cloned is someone else's prompt. In 2025, researchers at Pillar Security showed that hidden Unicode characters in a rules file could steer the code an agent generates, invisibly to a human reviewer. Read the file before you run an agent in an unfamiliar repository, and scan for zero-width and bidirectional characters in CI if you accept outside contributions.
Don't use it as a log. What changed last sprint belongs in git. What the agent learned about your preferences belongs in its own memory, which Claude Code keeps on your machine, outside the repository, and loads the index of at the start of each session.
A skeleton
Most of a good file is commands and exceptions. For a Symfony project that runs in Docker, as this site does:
# AGENTS.md
## Commands
- Everything runs in the container: `docker compose exec php <command>`.
- Tests: `vendor/bin/phpunit`.
- Static analysis: `composer phpstan`.
- Style: `composer cs-fix`. Run it after `composer rector-fix`, not before.
## Things that look wrong but aren't
- Blog posts are Markdown files in `content/blog/`. Merging one schedules it.
- `robots.txt` has no `Disallow: /` on purpose. A test fails if one is added.
## Out of bounds
- Don't run `docker compose down -v`. It deletes the database volume.
Fourteen lines. Each one is something an agent would otherwise get wrong, or have to discover by breaking it.
The last line of that skeleton is also the weakest. It asks. The next post is about the settings that decide what an agent may do without asking you, and the one after is about making a line like that one hold.
Sources
- How Claude remembers your project,
Claude Code docs: how
CLAUDE.mdis delivered, load order,CLAUDE.local.md, imports, path-scoped rules, the 200-line guidance, HTML comments,/init,/doctor prompt-audit,AGENTS.mdsupport and the Project instructions setting, the Windows symlink warning, and auto memory. - Choose a permission mode,
Claude Code docs: the auto mode classifier sees your
CLAUDE.md, and deny rules block in every mode. - AGENTS.md: the format, the tools that read it, nearest file wins, and the Aider and Gemini CLI settings.
- Formation of the Agentic AI Foundation,
Linux Foundation, December 2025:
AGENTS.mdas a founding project. - Custom instructions with AGENTS.md, Codex docs: the 32 KiB combined limit.
- Cursor is now Grok Build, 30 November 2026: the rename.
- Rules, Grok Build docs
(where Cursor's rules page now redirects):
.cursor/rules/*.mdc, glob-scoped rules,AGENTS.mdsupport and the 500-line guidance. - Windsurf is now Devin Desktop, Cognition, June 2026: the rename.
- Devin Local Customizations,
Devin Desktop docs:
AGENTS.mdread as an always-on rule. - Adding repository custom instructions,
GitHub Copilot docs:
.github/copilot-instructions.mdandAGENTS.md, nearest file first. - Getting started, Jules docs: reads
AGENTS.mdfrom the repository root. - Instructions, Zed docs: the files Zed checks, in order, and that it uses the first one it finds.
- Provide context with GEMINI.md files,
Gemini CLI docs:
GEMINI.mdby default,context.fileNameforAGENTS.md. - Evaluating AGENTS.md: Are Repository-Level Context Files Helpful for Coding Agents?, Gloaguen et al., 2026, with the authors' affiliations (ETH Zurich and LogicStar.ai) in the full text.
- How Hackers Can Weaponize Code Agents, Pillar Security, March 2025: the rules file backdoor.
I use coding agents daily on production PHP and Symfony codebases. See how I build AI and LLM integration into them.