After this, you'll have a working CLAUDE.md with your first five project-specific rules, each written from a real mistake rather than speculation.
Before you start
Before diving in, complete Plan Before You Code so your first five rules come from gaps you spotted in real plans rather than from speculation.
The idea
CLAUDE.md is the file that Claude Code reads at the start of every session, before you type anything. Whatever is in it persists. Every session starts with it already loaded. This is the answer to the hardest problem at Level 3: the model makes the same mistake again and again because there is nowhere for lessons to go. CLAUDE.md is where they go.
Here is the before and after: Five rules from one real project: "Never use var. Always const or let." "All database queries go through the query-builder utility in src/db/query.ts, not raw SQL." "This project uses Tailwind v4. Do not suggest v3 class names." "Test files live in src/__tests__, not next to the source files." "Never add console.log to production code." Each of these rules came from a mistake that happened at least once. None of them are advice Claude already knows. They are project-specific constraints.
The test for every line: would Claude do the right thing without this rule? If yes, delete it. If no, keep it. General advice ("write clean code", "handle errors gracefully") fails this test every time. Project-specific constraints ("use query.ts, not raw SQL") pass it. Start with five rules from real mistakes. That is the whole first CLAUDE.md.
Try it (20 min)
Watch out for
Paste this into Claude:
I want to write my first CLAUDE.md. Help me do it correctly. Ask me: (1) What are the top three mistakes Claude has made in my project that it repeated more than once? (2) What tech stack, versions, or libraries does this project use that Claude might get wrong? (3) Are there specific files, utilities, or patterns I always want Claude to use instead of the default approach? (4) What should Claude never do in this codebase (forbidden patterns, wrong libraries, wrong file locations)? After I answer, write me a CLAUDE.md under 30 lines with only the rules that pass this test: would Claude do the right thing without this rule? If no, it stays. If yes, delete it.
What good looks like:
What a good response looks like:
Based on your answers, here is your first CLAUDE.md. Every line came from a mistake you described. ``` # Project Rules ## Stack - This project uses Tailwind v4. Do not suggest v3 class names (e.g. use `text-sm` not `text-base/sm`). - Database layer: all queries go through src/db/query.ts. Never write raw SQL or use the Prisma client directly. - TypeScript strict mode is on. Never use `any`. Use `unknown` and narrow it. ## Patterns - API responses always use the ApiResponse wrapper in src/types/api.ts. Never return plain objects from endpoints. - Errors are logged via src/lib/logger.ts. Never use console.log or console.error in production code. ## File locations - Tests live in src/__tests__/. Never create test files next to source files. ``` Lines I removed from your draft: "Write clean, maintainable code" (Claude knows this), "Handle errors gracefully" (too vague to act on), "Follow TypeScript best practices" (already covered by strict mode). Those three lines cost tokens every session and change nothing. The six lines above will change behavior the first time you open a new session.
When this breaks
Claude can do it for you
After any session where Claude made a mistake you have seen before, say: "Add a rule to my CLAUDE.md that would prevent this mistake. Write the exact line." Then copy that line into your file. That is the compounding habit.
You can now
Produce a CLAUDE.md under 30 lines where every line has a named real-world failure or constraint behind it and would change Claude's output if removed.
Key takeaways
Five rules from real mistakes beat 50 rules from good intentions. Write from what went wrong, not from what you hope will go right.