CLAUDE.md and AGENTS.md
A short file at the repo root that the agent reads at the start of every session. It is how you stop repeating yourself.
Words on this page (9)
- repo
- : Repository: a project folder tracked by git, usually hosted on GitHub.
- agent
- : A model run in a loop that chooses its own tools and steps until the task is done.
- AGENTS.md
- : A shared convention for a repo file with instructions for coding agents.
- CLAUDE.md
- : A file at a repo root that Claude Code reads at the start of every session. AGENTS.md is the shared equivalent.
- attention
- : The mechanism that lets each token weigh all earlier tokens by relevance when computing its next representation.
- Docker
- : A tool that packages software and its dependencies into a portable container.
- harness
- : Everything around the model that makes it an agent: prompts, tools, rules, sandboxes, hooks, memory and checks.
- context window
- : The maximum number of tokens a model can look at in one call: your prompt, the conversation, tool results and the answer together.
- hook
- : A script the harness runs automatically at a fixed point, such as before a tool call. It enforces rules in code.
What it is
.md is a community convention read by Claude Code, Codex, Cursor, Aider and others. Claude Code also reads . The file holds what an agent cannot infer from the code: how to run tests and the build, the project layout, naming and style rules that differ from defaults, and things to never do.
What belongs in it
Commands (install, test, lint, run), architecture in a few lines, conventions that are not obvious, and sharp edges such as "do not edit generated files". Keep it short, since it is loaded into every session and each line competes for . When the agent makes the same mistake twice, add one line. Move long reference material into separate files and link to them so they load only on demand. Prune lines that stop mattering.
A worked example: a good file
Run: pnpm install, pnpm test, pnpm dev. Layout: app code in src/, tests in spec/. Conventions: functional components, no default exports. Never: edit src/generated, commit .env. Gotcha: tests need running. Eight lines. Every line prevents a repeated correction.
How the file is used
When a session starts, the reads the file and puts its text at the top of the model's context. The model does not remember earlier sessions by itself. Each one begins empty, so this file is the main thing that carries project knowledge from one session to the next. The agent can still read the code itself. Because the text sits in the , every line uses space and competes with your actual task.
A second example: a file that makes things worse
Imagine a file of 300 lines with the full history of the project, old decisions, and a tutorial for the framework. The agent now has to weigh all of it on every task. Important rules, like "never edit generated files", are buried. A shorter version keeps only what the agent cannot discover by reading the code: commands, traps and rules. The history can live in a docs folder that the file links to. Instructions in the file are also advice, not a lock. For a rule that must never break, use a permission setting or a .
What goes wrong
Files go stale. A command in the file changes, nobody updates it, and the agent keeps running the old one. You will see errors about a missing script or a wrong folder. Contradictions cause trouble too: one line says use tabs, another says spaces, and the agent may follow either. Over-long files lead to ignored rules.
How to tell it is working
Run a simple test. Start a fresh session and ask: "What commands would you run to test this project, and what must you never do?" The answer should match your file. If it guesses, the file is not being loaded or the wording is unclear. Then give the agent a real task and count how many corrections you make. Add a line for each repeated correction and remove one that never matters.
Try it yourself
Write a file of ten lines or fewer for a project you own.
- List the install, test and run commands.
- Add one convention and one thing to avoid.
- Start a new session and ask the test question above.
Expect the first answer to be mostly right and to reveal one missing line.
Common mistake
Pasting the whole architecture document. The file loads every session, so only keep what changes behavior.
Every morning you re-explain to your assistant: "we use pnpm, tests live in /spec, never edit the generated folder". By Friday you are tired of saying it. A short file at the root of the project says it once, and the agent reads it at the start of every session.
Check yourself
What belongs in CLAUDE.md?
Not quite. It loads every session, so keep it to high-value facts and link to the rest.
The agent repeats the same mistake. What do you do?
Not quite. One line fixes it for every future session.
Your memory file has grown past 300 lines. What is a sensible response?
Not quite. A short file keeps attention on what matters, and detail loads only when needed.
You got 0 of 3 right.
Go deeper
- ToolAGENTS.mdTool
Community · The shared format that most coding agents read.
- Docs
Anthropic · How CLAUDE.md files are discovered, imported and layered.
- Article
Anthropic · Includes guidance on writing an effective CLAUDE.md.
Spotted a mistake or something unclear? Report it on GitHub.