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

SectionIncludeExample
CommandsInstall, dev server, test, lint, typechecknpm test -- --run; php artisan test
ArchitectureKey directories and their rolessrc/modules/<name>/api.ts is the only public entry
ConventionsStyle, naming, patterns to followMoney in integer paise; use zod for validation
Rules / neverDangerous actions, generated filesNever edit migrations that shipped
GotchasNon-obvious behavioursMonaco swallows Cmd+Enter; use editor.addCommand
VerificationWhat "done" meansRun lint + tests before finishing

Layering instructions

Root AGENTS.md / CLAUDE.mdproject-wide commands and rulesSubdirectory filesmodule-specific conventionsLinked docsdeep dives loaded when relevantCode + teststhe ultimate source of truth
Layered instructions keep each file short.

Keeping it useful

  1. Start with commands and the top 5 rules
  2. Add a short architecture map
  3. Record gotchas whenever an agent (or human) trips over one
  4. Prune outdated or redundant lines regularly
  5. Review changes in PRs like code
Maintaining the file over time.

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 errors

Module-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.

More AI articles