Skip to main content

Instruction Docs

How to write instruction docs for AI agents. e.g. AGENTS.md and CLAUDE.md.

Key Insights

  • AGENTS.md = vendor-neutral open standard.
  • CLAUDE.md = Claude Code-specific memory file, loaded every session.
  • Human written docs improve success ~4% over LLM-generated ones1.

DOs

  • Focus on non-trivial, non-inferable, non-enforceable info that agents can't easily infer.
  • Use progressive disclosure with multiple docs.
  • Put all crucial commands in packages.json, Makefile, or nested docs.
  • Setup hooks to enforce code style and patterns.
  • Create a canary instruction so you can easily tell if agents are following instructions.

DON'Ts

  • Project tree structure without explanations. Agents can easily infer from the codebase itself.
  • Task-specific instructions. These should be in directory-specific AGENTS.md.
  • Code examples of patterns. Agents can learn from the codebase itself.
  • Set "Never do X" rules. This make agents get stuck, always provide alternatives.
  • Put repetitive, outdated, or non-crucial info (e.g. Emojis)

Hierarchy

./AGENTS.md                   → repo root (primary)
./packages/api/AGENTS.md → specific overrides

CLAUDE.md

Some behavior that only applies to Claude Code worth noting.

  • Loads into memory every session, so keep it under ~60–150 lines, only include what applies to every session.
  • You can store personal global preferences at ~/.claude/CLAUDE.md that apply to all sessions.
  • You can also have personal project-specific overrides at ./CLAUDE.local.md that are gitignored.

Before Claude Code starts support AGENTS.md, just put a single line in CLAUDE.md:

See @AGENTS.md

Template

# [Project Name]

[One sentence: what this project does and why it exists.]

## Project Map

- `path/to/dir` — Non-trivial info that agents can't easily infer.
- `path/to/dir` — This file is the entry point for X, it does Y and Z. If you want to modify X, this is the file to start with.
- `path/to/dir` — This is where the core domain logic lives, pure functions with no I/O.

## Landmines & Gotchas

<!-- Things the agent CANNOT discover by reading your code. -->
<!-- If it can figure it out from a directory listing or README, don't put it here — you're just adding noise. -->

- Use `uv` for Python deps, NOT pip
- Always run tests with `--no-cache` — fixture setup causes false positives otherwise
- `some.file` is auto-generated. Never edit it — modify `some.other.files` instead.
- The auth module uses a custom middleware pattern. Do NOT refactor to standard Express middleware.
- `some-path/` is deprecated but still imported by 3 production modules — do not delete anything in it
- When adding a new API route, you MUST also update `some.file`.

## Conventions & Workflow

- Prefer small, focused diffs
- Use Plan Mode for any refactor touching `src/core/`

## For More Context

<!-- Use progressive disclosure: don't paste docs here, point to them. -->
<!-- The agent will read these on-demand when relevant. -->

- Architecture deep-dive: see `agent-docs/architecture.md`
- Testing patterns: see `agent-docs/testing-guide.md`
- API conventions: see `agent-docs/api-conventions.md`

References

Footnotes

  1. A study by ETH Zurich, source.