CLAUDE.md — The Map You Draw for Your AI

A beginner-friendly teaching edition

Core idea: CLAUDE.md is the persistent instruction and memory file that tells Claude Code how your project works and how you want it to behave.

Think of it as a map + constitution + guardrail system for your AI teammate.

What You Will Learn

  1. Why CLAUDE.md matters
  2. Guardrails, not manuals
  3. What belongs in CLAUDE.md
  4. What should stay out
  5. The CLAUDE.md hierarchy
  6. How to use @ imports safely
  7. A practical project example
  8. Auto Memory vs. handwritten CLAUDE.md
  9. The iterative flywheel
  10. How to create your first CLAUDE.md
  11. Common mistakes and fixes
  12. Practice, revision questions and memory map

1. The Main Idea

Claude Code can inspect your files and understand a project, but every new session still needs reliable project-specific rules. That is where CLAUDE.md comes in.

The book describes it as more like a contract than a manual: the things you and Claude have agreed about how to work together live there. Claude Code reads the file when a new conversation starts.

Remember: If you have explained the same important rule to Claude more than once or twice, consider moving that rule into CLAUDE.md.

2. Why Is CLAUDE.md So Important?

Imagine joining a new company on your first day. You know programming, but you do not know:

  • which commands the team uses,
  • which testing framework they prefer,
  • which architectural decisions are intentional,
  • which mistakes must never be repeated,
  • or which coding conventions are specific to this project.

Without project instructions, Claude has to discover these things repeatedly. With CLAUDE.md, the important project rules are available at the beginning of a session. The source calls the root CLAUDE.md the agent's “constitution” and primary source of truth for the codebase.

New session Read CLAUDE.md Understand rules Work on project

3. The Big Mistake: Writing an Encyclopedia

A beginner may think:

"I should put everything about my project into CLAUDE.md."

That is the wrong direction. A huge file consumes context before Claude even starts doing the actual task. The source specifically warns against turning CLAUDE.md into an encyclopedia and notes that Boris's team keeps its core rules file around roughly 2,500 tokens.

Simple rule: CLAUDE.md should contain the rules Claude cannot reliably guess, not everything Claude could discover by reading your code.

4. Guardrails, Not Manuals

The recommended strategy is to start small and grow the file from real mistakes.

Claude makes mistake Record the lesson Add a rule Mistake becomes less likely

This creates a useful feedback loop. Instead of guessing what rules might be needed, you add rules when the project gives you evidence that they are needed.

Best mental model: Do not write a giant rulebook on Day 1. Build a small guardrail system from real experience.

5. What Actually Belongs in CLAUDE.md?

The source gives a very useful test:

If Claude can figure it out from the code, don't write it.
If Claude cannot reasonably guess it, write it.

Write ThisUsually Don't Write This
Custom Bash/build commands Claude cannot guess“This is a React project” when the code already makes that obvious
Project-specific code style preferencesNormal language conventions Claude already knows
Test commands and preferred testing frameworkFull API documentation pasted into the file
Architectural decisions and their contextFrequently changing information
Development-environment quirksFile-by-file descriptions Claude can discover
Common mistakes and how to avoid themGeneric filler such as “write clean code”

This distinction is directly based on the source's “Write This / Don't Write This” guidance.

6. Good Rules vs. Weak Rules

Weak rule

Never use X.

Better rule

Do not use the -foo-bar flag; use -baz instead.

Why is the second better? It gives Claude a replacement path. A rule should not merely block an action when the correct alternative can be stated clearly.

Avoid vague guardrails: “Never do this” without explaining what Claude should do instead can leave the agent stuck.

7. Don't @ Import Huge Documents

CLAUDE.md supports an @ import syntax for pulling other files into the instruction context:

# CLAUDE.md @docs/coding-standards.md @docs/api-conventions.md

But the source warns that referenced files can be fully embedded into context. Import only short files that genuinely need to be available every session. For a large document, it is better to point Claude to the path and tell it when to read that document.

Rule of thumb: Small, always-needed file → @ import can make sense. Large reference document → keep it outside the always-loaded context and reference its path.

8. CLAUDE.md Has a Hierarchy

CLAUDE.md is not limited to one file. The source describes a layered structure:

LevelExamplePurpose
Global~/.claude/CLAUDE.mdPersonal preferences shared across projects
Project./CLAUDE.mdProject rules shared with the team
Subdirectory./src/CLAUDE.mdRules for a particular module
Deeper directory./src/api/CLAUDE.mdMore specific rules for a nested area

The hierarchy is especially useful in monorepos where frontend and backend areas may need different conventions.

How to think about the levels

Global
“How I generally like to work.”
Project
“How this team/project works.”
Subdirectory
“How this specific module works.”
Deeper directory
“Rules specific to this smaller area.”

9. A Good Project-Level CLAUDE.md

The book provides a concise example. The important idea is not to copy it blindly, but to understand its structure.

# MyApp # Architecture - Next.js 15 + TypeScript + Tailwind CSS - Database: PostgreSQL + Drizzle ORM - Auth: Better Auth - State management: Zustand (do not use Redux) # Dev Commands - Start dev server: pnpm dev - Run tests: pnpm test - Type check: pnpm typecheck - Lint: pnpm lint # Code Style - Use functional components, not class components - Use Tailwind for styling, no CSS files - Use server components for data fetching - Use error.tsx boundaries for error handling # Common Pitfalls - After migrations, regenerate types - Restart the dev server after changing environment variables # Don't - Don't install new dependencies without approval - Don't modify critical configuration files - Don't call the database directly from client components

The source's actual example is intentionally short: architecture, commands, code style, pitfalls, and “don't” rules.

Important: The example is a teaching pattern, not a universal template. Your own CLAUDE.md should grow from your own project's actual decisions and mistakes.

10. Use CLAUDE.md to Simplify Your Project

There is a deeper lesson in the chapter: if a command is so complicated that it takes several paragraphs to explain in CLAUDE.md, the command itself may be too complicated.

The source suggests creating a simple Bash wrapper with a clean interface and documenting that wrapper instead. In other words, good documentation can reveal bad interfaces.

Example idea:
Instead of documenting a long, fragile deployment command with many flags, create a project command such as ./scripts/deploy.sh and teach Claude that one clear command.

11. Auto Memory: What Claude Remembers Automatically

The book also describes an automatic memory system that works alongside the CLAUDE.md you write yourself.

When you correct Claude with preferences such as “use English for commit messages” or “put tests in a particular directory,” the source says Claude can save such preferences automatically for future sessions. These memories are stored under:

~/.claude/projects/<project>/memory/ └── MEMORY.md

Auto Memory and CLAUDE.md serve different purposes.

Hand-written CLAUDE.mdAuto Memory
Team-shared rulesPersonal preferences
Checked into GitStored locally
You maintain itClaude maintains it automatically
Structured and deliberateInformal accumulated memory
Best combination: Put project/team rules in CLAUDE.md. Let personal habits and preferences be handled by Auto Memory.

12. The Iterative Flywheel

The most important long-term idea in this chapter is that CLAUDE.md becomes better through use.

Week 1 — Empty file
Basic architecture and commands. Claude still makes many mistakes.
Week 2 — Guardrails
You begin recording real mistakes as rules.
Month 1 — Flywheel
The rules become more useful and corrections decrease.
Beyond — Continuous iteration
Add useful rules, remove outdated ones, keep the file lean.
Mistake Rule Better future output Fewer corrections New lesson

The source's one-sentence summary is: start small, add a rule when something goes wrong, keep CLAUDE.md lean, and check it into Git when it contains team-shared project rules.

13. A Simple Workflow for Building Your CLAUDE.md

  1. Start with a small file.
  2. Add the project's key architecture and development commands.
  3. Add important coding conventions that are specific to your project.
  4. Add verification/testing commands.
  5. When Claude makes a repeatable mistake, turn the lesson into a rule.
  6. Remove rules that are no longer useful.
  7. Keep the file short enough that it does not become a context burden.
  8. For team rules, keep the project CLAUDE.md in Git.

Create one in a project

cd my-project claude # Inside Claude Code /init

The book's exercise specifically recommends running /init, opening the generated CLAUDE.md, and adding three rules of your own.

14. Example: Turning a Mistake Into a Rule

Suppose Claude repeatedly installs new dependencies without asking.

# First time Claude installs a package you did not approve. # You correct it "Do not install new dependencies without my approval." # Add the durable rule # Don't - Don't install new dependencies without my explicit approval.

Now the lesson does not need to live only inside one conversation. It becomes part of the project's durable instructions.

15. Common Beginner Mistakes

Mistake 1: Making CLAUDE.md thousands of lines long.
Fix: Keep only information Claude cannot reliably infer.
Mistake 2: Writing rules once and never updating them.
Fix: Treat the file as a living document.
Mistake 3: Adding generic advice like “write clean code.”
Fix: State concrete project-specific behavior.
Mistake 4: @ importing large documents.
Fix: Reference their path and load them when needed.
Mistake 5: Saying only “never do X.”
Fix: Explain the preferred alternative.
Mistake 6: Depending only on conversation instructions.
Fix: Put important, durable constraints in CLAUDE.md because conversation context can be compressed.

16. CLAUDE.md vs. Conversation

ConversationCLAUDE.md
Good for the current taskGood for durable project rules
Can become longShould stay concise
Context can be compressedRead fresh at session start
Temporary decisions can live hereImportant repeated decisions belong here
Easy rule: Temporary task → conversation. Repeated project rule → CLAUDE.md.

17. Interview / Revision Questions

  1. What is CLAUDE.md?
  2. Why is CLAUDE.md compared with a constitution or project map?
  3. Why should CLAUDE.md be short?
  4. What is the “if Claude can figure it out from the code” rule?
  5. Give three examples of things that belong in CLAUDE.md.
  6. Give three examples of things that generally should not be put there.
  7. What is the difference between global, project-level and subdirectory-level CLAUDE.md?
  8. Why should you be careful with @ imports?
  9. What is Auto Memory?
  10. How is Auto Memory different from handwritten CLAUDE.md?
  11. Explain the iterative flywheel.
  12. Why is a rule like “use X instead of Y” better than only “never use Y”?

18. Practice — Try It Yourself

Exercise 1 — Create your file

Open any project, run /init, and add three rules that are actually useful for that project.

Exercise 2 — Create a guardrail

Ask Claude to make a small change. If it makes a mistake, correct it and convert that correction into a CLAUDE.md rule.

Exercise 3 — Compare context

Start a fresh session and ask Claude about the project. Notice how much project knowledge is available through the project files and CLAUDE.md without repeating the same background.

19. Quick Memory Map

CLAUDE.md = Project Memory + Rules + Guardrails

What Claude can't guess + Project decisions + Commands + Style + Pitfalls

Keep it lean → learn from mistakes → update continuously.

20. Final Takeaway

CLAUDE.md changes the relationship between you and Claude Code. Instead of explaining the same project rules in every session, you build a persistent set of instructions that travels with the project.

The key is not to write the biggest possible file. The goal is to create the smallest useful set of guardrails: the commands Claude cannot guess, the decisions that matter, the project-specific conventions, and the lessons learned from real mistakes.

Over time, the file becomes more valuable because every useful rule captures a lesson. That is the chapter's central flywheel:

Build Mistake Rule Better Claude Less correction
One line to remember: CLAUDE.md is not a manual for your whole codebase; it is a concise, evolving set of instructions that helps Claude work correctly in your specific environment.