✻Founding-member pricing: every lesson for $19/mo. The first 3 lessons are free. Start lesson 1 →
Unit 3 · Configure Claude · Lesson 12 of 40

A CLAUDE.md That Claude Actually Follows

Write a lean, high-signal CLAUDE.md that Claude reliably follows: what earns a line, path-scoped rules in .claude/rules, and auditing with /doctor.

ACADEMY11 min+72 XP4-question quiz

🎯 By the end of this lesson you'll be able to

  • Apply a test for what earns a line in CLAUDE.md
  • Split area-specific guidance into .claude/rules with paths
  • Recognize when a line should become a hook
  • Audit and trim an existing CLAUDE.md

Why long CLAUDE.md files get ignored

Lesson 7 introduced CLAUDE.md. Now let's make it work. The most common failure isn't a missing instruction. It's a file so long and generic that the important lines drown. Every line competes for attention, on every request.

The test for every line

Keep a line only if all three are true:

  1. Claude can't easily discover it by reading the repo (or would get it wrong).
  2. It matters in most sessions, not just one rare task.
  3. It's specific enough to act on. "Write clean code" fails. "Money is integer cents; never floats" passes.

Good candidates: build and test commands, misleading spots in the code, decisions made outside the repo, and anything you've had to correct twice.

◎Keep it in CLAUDE.md?pick the best fit
"Run pnpm test -- <file> for a single test file."
A non-obvious command used in most sessions.
"Our architecture uses a layered approach with controllers, services and repositories…" (40 lines)
Claude can read the code. Architecture essays waste context.
"The 12-step procedure for cutting a release."
An occasional procedure belongs in a skill with disable-model-invocation: true.
"src/legacy/ is generated. Edit schema/ and run pnpm gen instead."
A trap Claude would otherwise fall into.
"Please write good, clean, well-tested code."
Too generic to change any behavior.

Path-scoped rules: guidance that loads only where it applies

For instructions about one part of the codebase, use .claude/rules/. Each .md file there loads every session, or, with paths frontmatter, only when Claude touches matching files:

.claude/rules/api.md
---
paths:
  - "src/api/**/*.ts"
---
# API rules
- Every handler validates input with the zod schema in `src/api/schemas/`.
- Return errors as `{ error: { code, message } }`, never bare strings.

Your React rules don't need to load while Claude fixes a SQL migration, and with path scoping they won't.

When emphasis means "make it a hook"

If you catch yourself adding IMPORTANT, ALL CAPS or "NEVER EVER" to a line, that line is telling you something: it needs enforcement, not a sterner request. Convert it to a hook (Unit 7) or a permission deny rule (Lesson 15).

✻
The correction loop

Every time you correct Claude, ask: "Will this come up again?" If yes, say "add that to CLAUDE.md" (shared) or "remember that" (auto memory). Over a few weeks your file turns into a precise record of your project's sharp edges.

Audit and trim

  • /context all shows exactly which memory files loaded.
  • /doctor flags oversized instruction files and suggests trims, especially content Claude could derive from the code.
  • /memory opens every memory file for editing.

A healthy project CLAUDE.md is usually well under 200 lines. Many great ones are under 50.

CLAUDE.md (a lean example)
# Acme Web

## Commands
- Dev: `pnpm dev` · Test one file: `pnpm test -- <path>` · Types: `pnpm tsc --noEmit`

## Must-knows
- Feature flags live in `flags.ts`; never hardcode `if (env === "prod")`.
- `packages/ui` is published to npm. Changes need a changeset (`pnpm changeset`).
- E2E tests need `pnpm db:seed` first.

## Done means
- Typecheck clean, affected tests pass, and you've said what you verified.
☑Trim your CLAUDE.mdsaved on this device

Check your understanding

?Lesson quiz10 XP per correct answer · +25 for a perfect score
QUESTION 1 OF 4

Which line most deserves a place in CLAUDE.md?

Why: It's specific, non-obvious and prevents a real mistake.
QUESTION 2 OF 4

What does paths frontmatter in a .claude/rules file do?

Why: Path-scoped rules keep area-specific guidance out of unrelated sessions.
QUESTION 3 OF 4

You keep adding 'IMPORTANT!!' to a rule Claude sometimes breaks. What should you do?

Why: Rules that can't have exceptions need enforcement, not emphasis.
QUESTION 4 OF 4

Which command suggests trims for oversized instruction files?

Why: /doctor checks your setup, including instruction file size.
0 / 4 correct
Academy lesson

Unlock lesson 12 and the next 28

You've finished the free lessons. Join the Academy for $19/month to unlock every lesson, quiz, terminal simulation and puzzle, plus the final exam and your certificate of completion.

  • All 40 lessons across 9 units
  • 165+ quiz questions
  • Final exam + certificate
  • New lessons as Claude Code evolves
  • XP, streaks and badges
  • Cancel anytime

Already a member? Log in to continue.

Key takeaways

  • Every CLAUDE.md line must be non-obvious, frequently relevant and specific.
  • Use .claude/rules/ with paths for area-specific guidance.
  • Emphasis is a smell. Rules that can't bend belong in hooks or deny rules.
  • Audit with /context all, /doctor and /memory.

Nice work. Lesson 12 done?

Mark it complete to earn +72 XP, keep your streak alive and unlock badges.

Written by Curtis Cornell from Anthropic's public Claude Code documentation. Last reviewed November 14, 2026. Claude Code changes fast; if something here differs from your version, the official docs win.

Start lesson 1 free →