A CLAUDE.md That Earns Its Place
Why This Matters
Everything in CLAUDE.md is loaded at the start of every session. A line that does not change the agent’s behaviour costs context on every task, and a long file buries the rules that matter. Anthropic’s own guidance is that longer files consume more context and reduce adherence.
TestPilot’s setup
AGENTS.md ← shared instructions for any coding agent (commands, structure, rules)
CLAUDE.md ← imports AGENTS.md, adds Claude Code specifics
@AGENTS.md
## Claude Code specifics
- Use plan mode for changes that touch more than one file in `src/`.
- After editing, run `npm run check` and show the result.
The @AGENTS.md import keeps one source of truth for every agent your team uses.
In Claude Code, /memory shows exactly this chain: the project’s CLAUDE.md (checked in), the AGENTS.md it imports, and your personal ~/.claude/CLAUDE.md next to it:
The test for every line
Would the agent do something different without this line?
| Line | Keep? |
|---|---|
“Run npm run check before saying you are done” | Yes: the agent cannot know your quality gate |
| “Tests never call the real API; use the fake client” | Yes: a project decision |
| “This project uses TypeScript” | No: the agent sees that from the files |
| “Write clean, maintainable code” | No: it changes nothing |
| A 60-line explanation of the triage algorithm | No: put it in docs/ and let the agent read it when needed |
“Never commit .env” | Keep, and enforce it (lesson 46) |
What does not belong here
- What the agent can read from the code. Folder structure in detail, language, framework.
- Long tutorials. Link to them.
- Rules for one folder only. Use a path-scoped rule (lesson 44).
- Multi-step procedures. Use a skill (lesson 45).
- Rules that must never be broken. CLAUDE.md is context, not enforcement. Use permissions or hooks (lesson 46).
Splitting a growing file
Imports keep files organised, but imported files still load at startup, so they do not save context. To actually load less, move content into path-scoped rules or skills that load only when relevant.
Exercise
Here is a bloated CLAUDE.md. Cut it to what earns its place, and move everything else to the right home (docs, rule, skill or hook):
# Project
This is a TypeScript project using Node.js. We use Vitest for tests.
Please write clean code and follow best practices.
## Testing
Always write tests. Tests go in tests/. Use the fake client from tests/triage.test.ts.
Never call the real API in tests. When adding a golden case, first create the fixture,
then add the label with a reason, then run npm run eval and paste the scorecard in the PR.
## Security
Never read .env. Never commit secrets.
## Commands
npm run check runs typecheck and tests. Run it before you finish.
Compare with solution/lesson-52-claude-code, which has the Claude Code setup for lessons 42–52. Its docs/claude-code-demo.md walks you through all of module 6 in one session.
