You explain your stack to Claude Code every morning, it forgets your conventions by the third prompt, and your two teammates get different output from the same repo. The fix is a well-tuned CLAUDE.md: persistent memory that loads at the start of every session so Claude follows your patterns without being re-told. Done badly, though, a CLAUDE.md becomes a 600-line wall the model quietly ignores.
CLAUDE.md files serve as Claude Code’s persistent memory system. Unlike conversation history that gets cleared, these files are automatically loaded at the start of every session, providing consistent context about your project.
Key Benefits
Persistent Context: Information persists across sessions and team members
Reduced Token Usage: No need to repeatedly explain project details
Team Alignment: Shared understanding of project conventions
Improved Output Quality: Claude follows your specific patterns and preferences
Faster Onboarding: New team members get up to speed quickly
CLAUDE.md files can be placed at multiple levels in your project hierarchy. Claude Code automatically discovers and prioritizes them based on specificity:
# In the repository (checked into version control)
project-root/
├── CLAUDE.md # Project-wide context
├── frontend/
│ └── CLAUDE.md # Frontend-specific guidelines
├── backend/
│ └── CLAUDE.md # Backend-specific patterns
└── src/
└── components/
└── CLAUDE.md # Component-level conventions
# In your home directory (NOT under the repo)
~/.claude/CLAUDE.md # Personal preferences across all projects
CLAUDE.md files are additive: every level that applies contributes its content to Claude’s context at once. There is no strict numbered ranking — when two files conflict, Claude uses judgment to reconcile them, and more specific instructions typically win over broader ones. The levels that can contribute:
Managed policy (org-wide, deployed by IT) — /Library/Application Support/ClaudeCode/CLAUDE.md on macOS
Project memory — root CLAUDE.md, plus any CLAUDE.md in parent directories of the file being edited
Project rules — ./.claude/rules/*.md (modular, topic-scoped; loaded as project memory)
User memory — ~/.claude/CLAUDE.md (your personal preferences for every project)
Project memory (local) — ./CLAUDE.local.md (git-ignored, just you on this repo)
Files in parent directories load in full at launch; files in child directories load on demand when Claude reads a file in that directory. (Strict, deterministic precedence — where one definition fully overrides another — applies to skills, subagents, and MCP servers, not to CLAUDE.md memory.)
Claude Code can automatically generate a comprehensive CLAUDE.md file by analyzing your project:
Terminal window
claude
/init
This command:
Scans your project structure
Identifies frameworks and libraries
Detects coding patterns
Analyzes existing documentation
Creates a tailored CLAUDE.md file
/init gives you a solid skeleton, but it tends to be generic. After generation, feed it the prompt below to ground it in how your repo actually works rather than what the file tree implies.
Run /init again periodically as the project evolves, then re-run the bootstrap prompt to refresh stale sections.
The cheapest time to write a memory rule is the moment you correct Claude. Two documented ways to do it without leaving the REPL:
# Just tell Claude directly, in plain language:
remember that we use pnpm, not npm
save to memory that API tests require a local Redis instance
# Or run the memory file selector to edit a file yourself:
/memory
When you ask Claude to remember something, it picks the most relevant memory file and appends the rule in the right section. Use /memory when you want to open the file and edit it by hand, including your auto-memory entrypoint.
Common uses:
Capturing a convention the moment you correct the model
Documenting a decision made during the current task
Recording a gotcha you just hit so the next session avoids it
Most CLAUDE.md files rot the same way: rules contradict each other, dead instructions linger after the code changed, and the file grows past the point where the model reliably follows it. Run these two prompts against your current file inside a fresh session (/clear first so prior context doesn’t bias the review).
Once you’ve reviewed the findings, have Claude do the rewrite — but constrain it, or it will pad the file back up.
Then start a new session and confirm the trimmed file is still being honored on a representative task.
CLAUDE.md is high-leverage, which means its failure modes are easy to miss until output quietly degrades. The usual culprits:
The file is too long, so Claude ignores rules. Past a few hundred lines, instructions buried in the middle stop being followed reliably. If a rule is being skipped, it’s often length, not the model. Run the compress prompt in Tip 25 and split anything topic-specific into ./.claude/rules/*.md.
Conflicting parent and child files. A child-directory CLAUDE.md (or a .claude/rules/ file) can contradict the root. More specific wins, so a forgotten frontend rule can silently override your project standard. When behavior is inconsistent across directories, audit the full chain, not just the root.
Stale instructions. A rule that pointed at pages/ after you migrated to app/, or a command that was renamed, sends Claude confidently in the wrong direction. Re-run the audit prompt whenever you finish a refactor or rename scripts.
Aspirational rules the code doesn’t follow. If CLAUDE.md says “100% test coverage” but the repo sits at 40%, Claude will either nag on every change or quietly ignore the rule. Document what’s true now; track goals elsewhere.
Formatting that confuses parsing. Decorative emoji headers, deeply nested lists, and giant fenced blocks dilute signal. Keep it plain markdown with imperative bullets — that is what the model reads most reliably.
With well-optimized CLAUDE.md files providing context, you’re ready to master the command-line interface. Continue to Command Line Mastery to learn essential commands and productivity shortcuts.