Why Split Memory?
As projects grow, a single CLAUDE.md becomes unwieldy:Single File Problems
- 500+ lines loaded every session
- Package-specific details pollute root context
- Team members fight over conventions
- Context budget wasted on irrelevant info
Split Memory Benefits
- Only load what’s needed
- Package-specific knowledge isolated
- Personal preferences separate from team rules
- Agent-specific memory for specialized tasks
The Three Memory Layers
Project Memory (CLAUDE.md)
Shared conventions and build commandsLocation: Root and package directoriesLoaded: Automatically based on working directory
Personal Memory (CLAUDE.local.md)
Your preferences and shortcutsLocation: Same as CLAUDE.md, but gitignoredLoaded: Every session in that directory
Pattern 1: Monorepo Split
Before (Single File)
After (Split by Package)
Root CLAUDE.md (60 lines)
Root CLAUDE.md (60 lines)
packages/api/CLAUDE.md (120 lines)
packages/api/CLAUDE.md (120 lines)
packages/api/CLAUDE.local.md (gitignored)
packages/api/CLAUDE.local.md (gitignored)
Pattern 2: Agent-Specific Memory
Agents withmemory: user, memory: project, or memory: local maintain their own MEMORY.md.
Debugger Agent with Project Memory
~/.claude/agent-memory/debugger/MEMORY.md
What it learns:
- Common bug patterns in this project
- Flaky tests and their causes
- Performance hotspots
- Error messages and their fixes
The agent auto-curates this file. You don’t manually edit it.
Example Debugger MEMORY.md
Pattern 3: Multi-Agent with Split Skills
Different agents need different knowledge. Don’t load everything for everyone.- Planner Agent
- Reviewer Agent
- Scout Agent
- CLAUDE.md from current directory
- Skills: architecture-patterns, project-structure
- Memory: Past planning decisions
- API implementation details
- Test configuration
- Deployment scripts
Memory Scope Comparison
| Scope | Location | Lifespan | Use Case |
|---|---|---|---|
user | ~/.claude/agent-memory/<agent>/ | Permanent (all projects) | Cross-project learnings |
project | <project-root>/.claude/agent-memory/<agent>/ | Per project | Project-specific patterns |
local | <current-dir>/.claude/agent-memory/<agent>/ | Per directory | Package-specific knowledge |
Loading Order and Priority
When Claude Code starts, memory loads in this order:Optimization Checklist
Root CLAUDE.md < 60 lines
Root CLAUDE.md < 60 lines
- Only shared conventions
- Build commands (1-2 lines each)
- High-level architecture
- Links to package-level docs
Package CLAUDE.md < 150 lines
Package CLAUDE.md < 150 lines
- Package-specific build/test commands
- Local architecture details
- Gotchas and quirks
- Dependencies and integrations
CLAUDE.local.md < 30 lines
CLAUDE.local.md < 30 lines
- Personal shortcuts
- Editor preferences
- Local environment config
Agent Memory Auto-Curated
Agent Memory Auto-Curated
- Agent manages this automatically
- First 200 lines loaded
- Creates topic files when memory grows
- Links from MEMORY.md to topic files
Skills: Preload vs On-Demand
Skills: Preload vs On-Demand
- Preload (agent frontmatter): always in context
- On-demand (user-invocable): loaded when called
- Heavy skills: use
context: forkfor isolation
Real-World Example
Scenario: Working on API endpoint
You runclaude from packages/api/src/routes/
What loads:
packages/web/CLAUDE.md(sibling package)packages/mobile/CLAUDE.md(sibling package)- Other agents’ memory files
Scenario: Using planner agent
You run/planner with the agent configured as:
Migration Guide
Extract package-specific content
Move API details to
packages/api/CLAUDE.mdMove frontend patterns to packages/web/CLAUDE.mdKeep root minimal
Root CLAUDE.md should only have:
- Shared build commands
- Cross-package conventions
- Links to package docs
Troubleshooting
Claude doesn't see my package CLAUDE.md
Claude doesn't see my package CLAUDE.md
Cause: You’re running from root, and haven’t accessed files in that package yet.Solution: Either:
- Run
claudefrom within the package directory - Or access a file in that package (triggers descendant loading)
Agent memory not updating
Agent memory not updating
Cause: Agent memory is auto-managed. Manual edits get overwritten.Solution: Let the agent learn naturally. Use CLAUDE.md for manual rules.
Context still too large
Context still too large
Cause: Too many skills preloaded or CLAUDE.md files too long.Solution:
- Move skills from agent frontmatter to on-demand (user-invocable)
- Split large CLAUDE.md into smaller files
- Use
context: forkfor heavy skills
Changes in root CLAUDE.md not reflected
Changes in root CLAUDE.md not reflected
Cause: Session started before changes, context not refreshed.Solution:
- Start a new session
- Or run
/compactto reload memory files