Claude Code: Memory System
Last updated: 2026-08-31
The memory system ensures Claude Code doesn't start from scratch every time — it remembers your preferences, project conventions, and past decisions.
💡 Tip: Claude Code's memory has three layers: session (current conversation), project (CLAUDE.md), and personal (global preferences). Cross-session memory mainly relies on CLAUDE.md.
📋 Prerequisites: Chapter 14 - Plugin System
1. What You'll Learn
- Three-layer memory architecture
- Session memory mechanics
- Project memory (CLAUDE.md) best practices
- Personal memory configuration
- Memory management strategies
2. Three-Layer Memory Model
| Layer | Persistence | Scope | Storage Location |
|---|---|---|---|
| Personal memory | Permanent | All projects | ~/.claude/CLAUDE.md |
| Project memory | Permanent | Current project | project/CLAUDE.md |
| Session memory | Temporary | Current session | Memory (not persisted) |
Memory Priority
TEXT
📖 Display only
Project memory > Personal memory > Session memory
When project CLAUDE.md conflicts with global, project wins.
▶ Example 1: Three-Layer Memory Cooperation
TEXT
📖 Display only
# Global memory (~/.claude/CLAUDE.md)
"I prefer TypeScript strict mode, functions under 20 lines"
# Project memory (project/CLAUDE.md)
"This project uses JavaScript (not TypeScript), functions up to 50 lines"
# Result: Claude Code generates JavaScript code, functions under 50 lines
# Project memory overrides personal memory
3. Session Memory
(1) Conversation History Management
| Operation | Command | Description |
|---|---|---|
| View history | /history |
View current session's conversation log |
| Compress history | /compact |
Compress conversation to reduce Tokens |
| Clear history | /clear |
Clear conversation, start fresh |
| Resume session | claude --resume |
Resume last session |
(2) In-Session Memory Features
TEXT
📖 Display only
# Claude Code remembers previous conversation within a session
> Create a UserService
[Created]
> Add password reset functionality to it
[Claude Code remembers where UserService is, modifies directly]
> Add email verification too
[Still remembers UserService context]
(3) Session Memory Limitations
TEXT
📖 Display only
# After session ends, conversation history is not retained
# Session 1: "I prefer functional programming style"
# Session 2: May generate non-functional code — doesn't remember preference
# Solution: Write preferences into CLAUDE.md
4. Project Memory (CLAUDE.md)
(1) CLAUDE.md as Memory Carrier
MARKDOWN
# CLAUDE.md
## Project Conventions (Persistent Memory)
- Use TypeScript strict mode
- API response format: { code, data, message }
- Errors use AppError class
- Test framework: Vitest
## Completed Work (Progress Memory)
- ✅ User authentication module (JWT)
- ✅ Role permission system (RBAC)
- 🔄 Order management module (in progress)
- ❌ Payment integration (not started)
## Technical Decision Records (Decision Memory)
- 2026-08-15: Chose Redis cache over in-memory (need cluster support)
- 2026-08-20: Using Prisma over TypeORM (better type safety)
- 2026-08-25: Amounts use cents integer (avoid floating point errors)
▶ Example 2: Have Claude Code Remember Decisions
TEXT
📖 Display only
> Remember: Payment module uses Stripe SDK, not direct REST API calls
Claude Code:
→ Updating CLAUDE.md...
→ Added: "Payment integration uses Stripe SDK (not direct REST calls)"
# In later sessions:
> Implement payment refund functionality
Claude Code:
→ [Read from CLAUDE.md] Using Stripe SDK
→ Creating payment.service.ts using Stripe SDK ✅
5. Personal Memory
(1) Global Preference Configuration
MARKDOWN
<!-- ~/.claude/CLAUDE.md -->
## Coding Preferences
- TypeScript strict mode
- Prefer const, avoid let and var
- Functions no longer than 30 lines
- Add JSDoc comments
- Use ES Module
## Testing Preferences
- describe/it style (not test())
- Test naming: should + verb + condition
- Mock external dependencies, not internal modules
## Git Preferences
- Commit format: conventional commits
- Each feature point separate commit
## Dislikes
- ❌ Don't use any type
- ❌ Don't use console.log for debugging
- ❌ Don't ignore TypeScript errors
6. Memory Management Strategy
(1) Memory Maintenance Checklist
| Frequency | Operation | Description |
|---|---|---|
| Each time | Write important decisions to CLAUDE.md | Tech choices, architecture decisions |
| Weekly | Update progress memory | Completed/in-progress/not started |
| Monthly | Clean outdated memory | Remove no-longer-applicable conventions |
| Project switch | Check project CLAUDE.md | Ensure conventions match reality |
❓ FAQ
Q Does Claude Code automatically remember what I say?
A Only within the current session. Cross-session requires writing to CLAUDE.md. You can say "remember this preference" and Claude Code will try to update CLAUDE.md.
Q Does long CLAUDE.md affect performance?
A Yes. CLAUDE.md loads every session; keep under 150 lines. Move irrelevant content to other docs.
Q How do multiple developers share project CLAUDE.md?
A Commit project CLAUDE.md to git for team sharing. Personal preferences go in global CLAUDE.md, not committed.
Q Can memory be lost?
A Session memory disappears when session ends. CLAUDE.md persists in the file system unless deleted.
Q How to define the boundary between personal and project memory?
A Personal memory: coding style and tool preferences (project-agnostic). Project memory: tech stack and business rules (project-specific).
📖 Summary
- Three-layer memory: Personal (global preferences), Project (CLAUDE.md), Session (conversation history)
- Session memory is temporary; project/personal memory is persistent
- CLAUDE.md is the most important memory carrier for project conventions and technical decisions
- Project memory > Personal memory > Session memory
- Regularly maintain: write decisions, update progress, clean outdated content
📝 Exercises
- Basic (⭐): Configure global CLAUDE.md with 3 coding preferences, verify in a new project.
- Intermediate (⭐⭐): Maintain technical decision records in project CLAUDE.md, compare with/without decision memory.
- Advanced (⭐⭐⭐): Design memory management strategy ensuring 5 team members' CLAUDE.md don't conflict and stay synchronized.