01 — Documentation and AI_README
Commandment I: document for the agent, not for the archive. The goal: the next session understands a directory without reading all of its code.
Three layers, split by reader
| Layer | File | Holds |
|---|---|---|
| Constitution | CLAUDE.md (root) | what the project is, exact run commands, policies that override default behavior, a dated “Current state” with numbers. Loaded every session. |
| Directory map | AI_README — A map file in every code directory: what’s here, what it’s for and what to watch out for — written for search. The assistant finds the right file with one search instead of reading the whole directory. more in the glossary → in every directory with code | module Index (database) — A lookup in the database that makes searching instant instead of scanning everything in order. The first move for slow queries — like an index at the back of a book instead of reading 400 pages. more in the glossary →, key APIs (signature + contract), gotchas, numbers, the grep index. Read before touching that directory. |
| Reference / plans | docs/ | architecture, data model, Runbook — A written step-by-step guide for production operations, with numbered lessons from incidents. The memory of outages can’t live in someone’s head — the next deploy starts by reading the runbook. more in the glossary →, plans/. |
README.md is the public front door (what it is, how to start) — not a layer for the agent. Where does a
fact go? Ask who reads it — and write it once; the other files link.
Rules
CLAUDE.mdpoints to theAI_README.mdmaps — without that pointer a new session doesn’t know they exist.AI_README.mdis updated before the Commit — A saved, labelled point in the project’s history — a confirmation of a specific batch of changes. Small, described commits make a history you can return to any working state from. more in the glossary →, in the same commit as the code. A test enforces the index (every module named, size ceiling) → 17.- Write the index for
grep, not for reading. Keyword-dense one-liners: concrete names, synonyms, both languages if the project is bilingual.grep -i <topic>should hit one line pointing at one file. - One file = one topic. A topic spread over five files is five hits and burned context.
- State, not intent. Describe what the code does now; delete entries for removed code — a dead entry is worse than none. Numbers (records, tests) go stale → update them.
docs/describes the current version only. History lives in git and theCHANGELOG; update the doc, don’t keep the old version beside it.docs/plans/is a living backlog. Problem → options → choice → why. When a plan lands, fold the decision into the doc /CLAUDE.mdit governs and delete the plan — git keeps the record.- A new directory is created together with its
AI_README.md— never “later”. - Generated artifacts (HTML, Snapshot — A saved state of data from a specific moment — e.g. a database copy or a file of computed statistics. It speeds things up and keeps them safe, but is stale from the moment it’s taken — you need to know where fresh data comes from. more in the glossary →) are derivatives: commit them, never edit them by hand, regenerate on command (a skill), not on every commit.
Update the docs for: a new module/function/script/flag, a schema change, a behavior change (threshold, fallback), changed counts. Not for: a pure bugfix with no API — An agreed way for two programs to talk to each other — one asks, the other answers in a set format. Through an API your app connects to outside services (payments, maps, AI). Treat an API key like a password. more in the glossary → change, typos.
Anti-patterns
- 🚫 “I’ll update the docs at the end” — the end never comes, the docs lie.
- 🚫 An
AI_READMEdescribing wishes instead of state. - 🚫 The same state copied into five files — one source of truth, the rest link.
- 🚫 Generic descriptions (“helpers”, “various rules”) — grep misses, the agent reads everything.