AGENTS.md and CLAUDE.md: Writing Instruction Files for AI Coding Agents
How to write repository instruction files for AI coding agents: what to include, structure, length, keeping them current and common mistakes.
Published December 1, 2026
Every time an AI coding agent starts a session in your repository, it knows nothing about your conventions, commands or architecture. Instruction files fix that. Files such as AGENTS.md (a cross-tool convention) or CLAUDE.md (used by Claude Code) are read automatically by many agents and act as onboarding documentation for your AI collaborators, and they help human newcomers too.
The concept
A good instruction file answers the questions a capable new teammate would ask on day one: how do I install, build, test and lint? How is the code organised? What conventions must I follow? What must I never do? Which files are generated or dangerous to touch? It should be specific to your repo, concise and verified.
These files are loaded into context on every session, so length has a cost. Aim for the essential rules and pointers, and link to deeper docs that agents can read when relevant. Nested files in subdirectories can hold module-specific guidance, and keeping the file in version control means changes are reviewed like code.
What to include
| Section | Include | Example |
|---|---|---|
| Commands | Install, dev server, test, lint, typecheck | npm test -- --run; php artisan test |
| Architecture | Key directories and their roles | src/modules/<name>/api.ts is the only public entry |
| Conventions | Style, naming, patterns to follow | Money in integer paise; use zod for validation |
| Rules / never | Dangerous actions, generated files | Never edit migrations that shipped |
| Gotchas | Non-obvious behaviours | Monaco swallows Cmd+Enter; use editor.addCommand |
| Verification | What "done" means | Run lint + tests before finishing |
Layering instructions
Keeping it useful
- Start with commands and the top 5 rules
- Add a short architecture map
- Record gotchas whenever an agent (or human) trips over one
- Prune outdated or redundant lines regularly
- Review changes in PRs like code
Practical examples
A compact example
Specific, verifiable, short.
# AGENTS.md
## Commands
- Install: npm ci · Dev: npm run dev · Test: npm test · Types: npx tsc --noEmit
## Architecture
- Next.js App Router in src/app; API client in src/lib/api.ts
- Tool logic lives in src/lib/tools/*.ts as pure functions (unit-testable)
## Rules
- Never call fetch() with user-supplied URLs from the backend; use SafeHttpClient
- Every new tool page needs a layout.tsx using buildToolMetadata(slug)
## Done means
- Lint, typecheck and tests pass; no new console errorsModule-level file
Guidance that only applies in one area.
# src/billing/AGENTS.md
- All amounts are integers in paise. Never use floats.
- Invoice numbers are generated by InvoiceNumberService only.Turning a repeated mistake into a rule
If you correct the agent twice, write it down.
- Use pnpm, not npm, in this repo (lockfile is pnpm-lock.yaml)Common mistakes
- Generic advice ("write clean code") that wastes context.
- Huge files that duplicate the README and all docs.
- Outdated commands that make agents fail on first try.
- Secrets or credentials in instruction files.
Key takeaways
- Instruction files onboard AI agents (and humans) to your repo.
- Prioritise commands, architecture, conventions, rules and gotchas.
- Keep them short; layer with subdirectory files and links.
- Version, review and prune them like code.
FAQ
AGENTS.md or CLAUDE.md?
Use what your tools read. Some teams keep one canonical file and reference it from the other.
How long should it be?
Often under a few hundred lines. If it grows beyond that, move details into linked docs.
Do instruction files replace documentation?
No. They summarise and point to docs; architecture docs and READMEs still matter.