The Agent-Readable Codebase

The Agent-Readable Codebase

Repo affordances are written once and stay in the repository for later sessions to start from. What belongs in an instruction file, why canonical examples can beat prose, and how to keep the file honest.

Per-task context is assembled fresh every session; repo-level affordances are written once and stay in the repository for later sessions to start from. The durable set is small — a short instruction file at the repo root, one clearly canonical implementation per pattern, and naming and structure a stranger could navigate — and the return carries over to future delegated tasks in that repo. The hard part is not writing the instruction file; it is keeping it honest as the code moves out from under it.

The repo as standing context

Every delegated task starts with the same problem: the agent brings general knowledge of the language and the ecosystem, and starts each session knowing little about this codebase beyond what is carried into it. In Claude Code, for example, each session begins with a fresh context window, and two mechanisms carry knowledge across sessions: the instruction files you write — CLAUDE.md, or a repository's AGENTS.md in its place — and the auto memory notes Claude writes itself (How Claude remembers your project, as of November 2026). Some of the gap gets closed per task, by supplying the files and constraints that particular piece of work needs. That work is real, and it starts over every session.

Repo-level affordances are the other half. They are written once, they live in the repository, and later sessions that touch the repo can start from them — including the sessions you did not run and the ones a teammate runs later. An hour spent making the repo legible does not accelerate one task; it raises the floor under all of them.

The useful intuition is that agents fail on the same things a competent new hire fails on. If someone joining the team would have to ask which of the three HTTP clients in the codebase is the current one, an agent has to guess; a working hypothesis, not a documented rule, is that it leans toward whichever client appears in the most files, deprecated or not. If a new hire could not find where validation belongs, a working hypothesis, not a documented rule, is that the agent will struggle too. Legibility for humans and legibility for agents are not two projects, and the second can come as a byproduct of taking the first seriously.

Instruction files that earn their place

One convention, described both on agents.md and in vendor documentation, is a plain-text instruction file at the repository root that the agent reads into its context at the start of a session; whether that happens automatically depends on the tool — Aider and Gemini CLI, for example, read AGENTS.md once they are configured to (agents.md FAQ, as of November 2026). The naming is still unsettled: AGENTS.md is promoted as an open, tool-neutral format and says it is used by over 60,000 open-source projects, with support listed from a growing set of coding agents and editors (agents.md, as of November 2026), while individual vendors document their own filenames — Anthropic's guidance says Claude Code loads CLAUDE.md into every session (Best practices for Claude Code, as of November 2026). Several tools now read one or both (as of November 2026), and some repositories carry a short file that simply points at the other. Claude Code is one example: by default it reads AGENTS.md only when no project-level CLAUDE.md or CLAUDE.local.md sits in the working directory or above it, reading it directly requires v2.1.277 or later, and some sessions cannot read it (Claude Code memory documentation, as of November 2026). Treat the filename as a detail that may move and the practice as the durable part.

What goes in it is more stable than what it is called, and the discipline is subtractive.

Belongs in the instruction fileDoes not belong
Build, test, and run commands an agent cannot guess from the manifestAnything the code already states plainly
Conventions that differ from the language's defaultsStandard idioms the model already knows
Hard constraints — the module never to edit directly, the helper always to useAspirational style essays and team philosophy
Pointers to the one canonical example of each recurring patternFile-by-file descriptions of the repository
Environment quirks: required variables, local service dependenciesDetailed API documentation better kept where it lives
Non-obvious gotchas that have burned people beforeAnything that will soon be false

Anthropic's Claude Code documentation names the failure mode here: a long instruction file is followed less reliably — longer CLAUDE.md files, it says, "consume more context and reduce adherence" (as of November 2026). A long file competes for the same attention budget as the task context, and past a certain length the rules that matter are buried among the rules that do not. The pruning test is blunt — for each line, ask whether removing it would cause a mistake. If not, it is decoration.

A file that passes that test can be short enough to read at a glance:

markdown
# Commands
- Test one file: pnpm vitest run <path>  (never run the full suite locally)
- Typecheck: pnpm tsc --noEmit

# Constraints
- Never edit files under src/generated/ — they are rebuilt from the schema
- All outbound HTTP goes through lib/http.ts, never fetch() directly
- Money is always integer minor units; there is no float currency anywhere

# Canonical examples
- API route: src/routes/invoices/create.ts
- Table component: src/components/InvoiceTable.tsx

Note what that file is not doing. It is not stating the intent of any particular piece of work — the work statement is its own artifact with its own lifetime. Instruction files carry standing constraints, the things that are true of every task in the repo; the moment a line is only true of one task, it belongs in that task's brief instead.

Conventions and canonical examples as anchors

A working hypothesis, not a documented rule, is that agents follow the patterns in front of them at least as readily as written instructions. Given a repository, a model takes much of its sense of "how do we do things here" from what the surrounding code already does — which means an efficient way to specify a pattern is to point at one implementation and call it the blessed one rather than describe it.

Prose describing a pattern has to be interpreted. A canonical example does not: it shows the naming, the error handling, the test structure, and the small decisions nobody thought to write down. Three lines in an instruction file naming the reference implementation for each recurring shape in the codebase can do more work than three pages describing those shapes.

The corollary is that consistency is machine-legibility. A working hypothesis, not a documented rule, is that a pattern-matcher reads each deviation from the dominant convention as a second pattern that might be the correct one. A codebase with two competing approaches to data fetching does not have one convention and one exception; it leaves a guess on every new module. That is the concrete cost of drift, and it is why the cleanup that consolidates three ways of doing something into one matters: it removes the ambiguity from the code itself, while documentation about which way is preferred can flag the ambiguity but leaves it in place.

Several habits that were already good practice double as affordances. Names that state what a thing is rather than abbreviating it. Types and interfaces that make contracts explicit instead of leaving them implied by usage. Tests that document intended behavior, which give an agent both a specification and a way to check itself. Directory structure that groups by domain concept rather than by technical layer, so that everything a change touches is findable from one place. None of these are agent-specific investments; they are the ordinary craft, now with a second beneficiary.

Keeping the instruction file honest

A stale instruction file can be worse than no instruction file. Absent guidance, an agent explores the code and infers — imperfectly, but from something true. Given a confident instruction that stopped being true two refactors ago, it may follow the instruction — Anthropic's Claude Code best-practices guide says the model usually follows your commands, with no guarantee that it will (as of November 2026) — and when it does, the failure is hard to spot in review because the output looks deliberate.

The maintenance discipline that works is small and local: when a session reveals the file misled the agent, the correction to the file lands in the same change as the work. Not a ticket, not a periodic documentation sweep — the same commit. The moment you have just discovered the line is wrong is a moment when you both know the truth and care enough to write it down.

Periodic pruning uses the same test as any other document, applied twice. Would a new engineer be helped by this line, or misled by it? And would removing it cause a mistake? Lines that fail either test come out. An instruction file that only grows is drifting toward the length at which its lines start getting lost, and the entropy runs one direction unless somebody deliberately cuts.

The honest limit on all of this: affordances raise the floor of what an agent produces in your repository. They do not raise the ceiling, and they do not remove the per-task work — the intent still has to be stated, the relevant context still has to be supplied, and the output still has to be reviewed by someone who understands the consequences. What they change is the starting position. Sessions begin oriented rather than guessing, which is worth an hour of anyone's time in a repository they expect to keep working in.

Project Inquiry