What Is Memory?
Memory in Claude Code is persistent context stored inCLAUDE.md files:
- Project guidance (conventions, architecture, standards)
- Domain knowledge (how the codebase works)
- Workflow instructions (testing, deployment, debugging)
- Rules and constraints (what to avoid, preferred patterns)
Memory files use markdown format and are named
CLAUDE.md (or CLAUDE.local.md for personal overrides).Why Memory Matters
Memory enables:- Consistent behavior: Claude follows project conventions automatically
- Reduced repetition: No need to re-explain architecture every session
- Team alignment: Shared context in version control
- Monorepo support: Component-specific instructions load on-demand
- Personal customization: Local overrides for individual preferences
Memory Scopes
Claude Code loads CLAUDE.md files from three scopes:Global
Location:
~/.claude/CLAUDE.mdScope: All Claude Code sessionsUse for: Personal preferences, coding styleProject
Location:
<project>/CLAUDE.mdScope: This project onlyUse for: Team-shared conventions, architectureLocal
Location:
<project>/CLAUDE.local.mdScope: This project, you only (git-ignored)Use for: Personal overrides for this projectLoading Behavior
Claude Code uses two mechanisms for loading CLAUDE.md files:Ancestor Loading (UP)
When you start Claude Code, it walks upward from your current directory to the filesystem root and loads every CLAUDE.md it finds. Loaded at startup: All ancestor CLAUDE.md filesDescendant Loading (DOWN)
CLAUDE.md files in subdirectories below your current directory are NOT loaded at startup. They’re loaded lazily when you read/edit files in those subdirectories. Loaded on-demand: Only when working in that subdirectory- Scenario 1: Root Directory
- Scenario 2: Component Directory
Working directory:
/mymonorepo/| File | Loaded at Launch? | Reason |
|---|---|---|
/mymonorepo/CLAUDE.md | ✓ Yes | Current working directory |
/mymonorepo/frontend/CLAUDE.md | ✗ No | Loaded when you work in frontend/ |
/mymonorepo/backend/CLAUDE.md | ✗ No | Loaded when you work in backend/ |
/mymonorepo/api/CLAUDE.md | ✗ No | Loaded when you work in api/ |
Why This Design Works
Shared instructions propagate down
Shared instructions propagate down
Component-specific instructions stay isolated
Component-specific instructions stay isolated
Frontend developers don’t need backend-specific instructions cluttering their context, and vice versa.
Context is optimized
Context is optimized
By lazily loading descendant CLAUDE.md files, Claude Code avoids loading potentially hundreds of kilobytes of irrelevant instructions at startup.
Writing a Good CLAUDE.md
Keep it under 150 lines
“CLAUDE.md should not exceed 150+ lines.” — Best Practice RepoClaude’s adherence degrades with longer files. For large projects, use multiple CLAUDE.md files in subdirectories.
Humanlayer Guide
Comprehensive guide to writing effective CLAUDE.md files (60 lines recommended)
Real Example from Repository
FromCLAUDE.md in the best practice repository:
Monorepo Structure Example
frontend/):
Best Practices
Put shared conventions in root CLAUDE.md
Put shared conventions in root CLAUDE.md
Put component-specific instructions in component CLAUDE.md
Put component-specific instructions in component CLAUDE.md
Framework-specific patterns, component architecture, testing conventions unique to that component.
Use CLAUDE.local.md for personal preferences
Use CLAUDE.local.md for personal preferences
Add it to
.gitignore for instructions that shouldn’t be shared with the team.Don't use CLAUDE.md as a TODO list
Don't use CLAUDE.md as a TODO list
CLAUDE.md is for persistent knowledge, not ephemeral tasks. Use
/todos or a task management system instead.Use @path imports for large contexts
Use @path imports for large contexts
Instead of pasting large code blocks, reference files:
Memory vs Rules
Claude Code also supports aCLAUDE.rules file for organizing rules separately:
CLAUDE.md (broad context):
Both files are loaded into context. Use
CLAUDE.rules to separate constraints from general guidance.Managing Memory
- View Memory
- Manual Memory Updates
- Auto Memory (Experimental)
Troubleshooting
Claude isn't following CLAUDE.md
Claude isn't following CLAUDE.md
- Check file size — keep under 150 lines
- Use clear, imperative language
- Add “Critical:” or “Important:” prefixes
- Repeat critical instructions in multiple sections
- Try
/memoryto verify file is loaded
CLAUDE.md not loading
CLAUDE.md not loading
- Ensure file is named exactly
CLAUDE.md(case-sensitive) - Check file is in project root or ancestor directory
- Restart Claude Code if you just created it
Too much context loaded
Too much context loaded
- Split into multiple CLAUDE.md files in subdirectories
- Use CLAUDE.local.md for personal preferences (git-ignored)
- Remove outdated or unused sections
Cross-Links
Settings
Configure memory-related settings
Subagents
Agents can have persistent memory too
Memory Best Practice
Writing good CLAUDE.md files and monorepo patterns
Agent Memory Report
Persistent memory scopes for subagents
