Writing AGENTS.md and CLAUDE.md Files That Coding Agents Actually Follow
What to put in AGENTS.md, CLAUDE.md, Copilot instructions and Cursor rules, how long they should be, and how to keep one source for every AI coding tool.

An AI coding agent arrives in your repository knowing a lot about programming and nothing about your project. It does not know that tests run with one command and not another, that a certain folder is generated, or that one file holds rules nobody should change without a review. An instruction file in the repository root fills that gap, and it is read before every session. A good one makes the agent noticeably more useful; a bloated or vague one wastes context on every request.
One idea, many file names
Each tool looks for its own file. AGENTS.md has become the shared open format, read by Codex, Jules, Zed, Aider and others. Claude Code reads CLAUDE.md. Gemini CLI reads GEMINI.md. GitHub Copilot reads .github/copilot-instructions.md. Cursor reads rule files with a short front matter header in .cursor/rules, and Windsurf has its own rules folder with a character limit per file.
Keeping five copies by hand means they drift apart. The AI Agent Instruction File Builder keeps one set of sections and exports each file name from it. For Claude Code it can write a two-line CLAUDE.md that simply imports AGENTS.md, so there is only one place to edit.
What to write
Commands matter most. Write the exact commands to install, run, build, lint, type-check and test, inside a code block, including how to run a single test. Agents that can check their own work make far fewer broken changes, and they cannot guess that your project uses pnpm or a custom script.
Boundaries come next. Name the files and folders that need your approval, the commands that must never run (deploys, production migrations), and the data that must never be printed or committed. Short, specific rules work: never edit src/lib/sync/merge.ts without asking.
Add a short overview of what the product does and the one or two qualities that matter most, such as never losing user data. This helps the agent choose between two reasonable designs. Then add the folder structure, style rules and testing expectations, written as patterns rather than adjectives. Prefer named exports for helpers is a rule; write clean code is not.
Finally, a gotchas section collects the things that cost someone an afternoon: an environment variable the dev server needs, a test that is flaky on first run, a generated folder to leave alone.
Templates and imports
Starting from a stack template saves typing. The builder has templates for Next.js, Python with uv, Go, Rust and Rails, and fills only the sections you have left empty unless you ask it to replace them. If you already have an instruction file, import it: second-level headings are matched to sections, and anything that does not match lands under gotchas.
Keep it short
Every line is read at the start of every session. The builder counts lines, words and estimated tokens, and warns when a file passes a sensible size for its tool, or the hard character cap Windsurf documents. It also points out vague phrases, repeated lines, rules written in capitals too often, a missing test command and anything that looks like a secret.
When a file grows, move detail elsewhere. Long architecture notes can live in docs that the agent reads when needed, and folder-specific rules can live in nested files where tools support them.
Maintain it like code
Review the file when commands change, when a new teammate joins, and whenever an agent makes the same mistake twice. Each repeated mistake is usually a missing rule. Because the builder saves your draft and has undo, you can try a tighter version, compare, and export only when you are happy. The tool cannot check that your commands work, so run each one once after you write it down.



