Claude Code forgets everything between sessions. Memory files fix that. This guide covers all three memory systems: project CLAUDE.md, personal auto-memory, and global user memory.
TL;DR
CLAUDE.md in your repo root is for team-shared project knowledge: architecture, commands, conventions. Auto-memory at ~/.claude/projects/ is for personal, per-project notes Claude accumulates across sessions. ~/.claude/CLAUDE.md is for global preferences that apply to all projects.
The Three Memory Systems
| System | Location | Shared | Auto-loaded | Content |
|---|---|---|---|---|
| CLAUDE.md | ./CLAUDE.md | Yes (committed) | Full file | Architecture, commands, conventions |
| Auto-memory | ~/.claude/projects/<path>/memory/ | No (personal) | MEMORY.md (200 lines) | Learned patterns, preferences, corrections |
| User memory | ~/.claude/CLAUDE.md | No (personal) | Full file | Global preferences, workflow rules |
All three are loaded into the system prompt at session start. They stack: global user memory applies everywhere, then project CLAUDE.md layers on project-specific context, then auto-memory adds your personal session history for that project.
CLAUDE.md (Project Memory)
The most important memory file. It lives at your project root and is committed to the repo. Every developer on the team, and every CI run, gets the same context.
Minimal CLAUDE.md
# CLAUDE.md
## Commands
```bash
bun install # Install dependencies
bun run dev # Dev server on port 3000
bun run build # Production build
bun run test # Run tests
bun run lint # ESLint
```
## Architecture
- Next.js 15 App Router, React 19, TypeScript
- Database: PostgreSQL with Drizzle ORM
- Auth: Clerk
- Payments: Stripe
## Conventions
- Server Components by default. Client components only for interactivity.
- All mutations via server actions in `actions.ts` files.
- Database operations through Drizzle ORM only.
- Run `bun run typecheck:fast` before committing.This gives Claude everything it needs to work in your project: how to build, what the stack is, and what patterns to follow. 40 lines, loaded into every session.
For detailed examples of CLAUDE.md files for different project types, see the CLAUDE.md examples page.
Auto-Memory
Auto-memory is Claude's scratchpad. It lives at ~/.claude/projects/<project-path>/memory/ and persists across sessions. Claude writes to it during conversations when it learns something worth remembering.
Example auto-memory MEMORY.md
## Lessons
- Always run `bun run typecheck:fast` after editing, not `tsc --noEmit` (project alias is faster).
- The request_type for WarpGrep in the DB is 'warpgrep', not 'warp_grep'.
## Agent Preferences
- Prefer agent teams over task agents for complex work.
## Project Quirks
- The Stripe webhook handler at /api/webhooks/stripe needs raw body parsing. Don't add JSON middleware.
- Drizzle migrations are in /drizzle, not /migrations.Key behaviors:
- MEMORY.md is auto-loaded (first 200 lines) into every session. Keep it concise.
- Topic files (e.g.,
debugging.md,patterns.md) can be created for detailed notes. Claude reads them on demand, not automatically. - Claude self-maintains it. When you correct Claude or confirm a pattern, it updates MEMORY.md. You can also say "remember this" or "forget that".
- Not shared with team. Auto-memory is in your home directory, not the project repo.
200-Line Limit
Only the first 200 lines of MEMORY.md are loaded into context. Lines beyond 200 are truncated. For large memory, split into topic files and link to them from MEMORY.md. Claude will read topic files when needed.
User Memory (~/.claude/CLAUDE.md)
Global preferences that apply to every project. Put things here that are always true about how you work:
Example ~/.claude/CLAUDE.md
# Global Preferences
## Tools
- Always use bun, never npm or yarn.
- Use edit_file over full file writes when possible.
## Style
- No emojis in code comments or commit messages.
- Commit messages in imperative mood: "Add feature" not "Added feature".
## Workflow
- Always commit and push when done with a task.
- Run builds/tests to verify work before reporting done.This file is loaded into every session across all projects. Keep it short, 20-50 lines. Project-specific rules belong in the project CLAUDE.md, not here.
What to Put Where
| Content | File | Why |
|---|---|---|
| Build/test/lint commands | CLAUDE.md | Team needs this |
| Architecture overview | CLAUDE.md | Team needs this |
| Coding conventions | CLAUDE.md | Team-enforced standards |
| "Always use bun" | ~/.claude/CLAUDE.md | Personal preference, all projects |
| Commit message style | ~/.claude/CLAUDE.md | Personal preference |
| "DB column is X not Y" | Auto-memory | Learned from session, may be wrong |
| Debugging insights | Auto-memory topic files | Detailed, personal, evolving |
Structuring CLAUDE.md
The best CLAUDE.md files share a pattern: they are short (under 200 lines), start with commands, describe the architecture in one paragraph, and list conventions as bullet points.
- Commands first. Claude uses these every session. Build, test, lint, dev server.
- Architecture second. Tech stack, key directories, data flow. One paragraph, not a whitepaper.
- Conventions third. Naming, file organization, patterns to follow. Bullet points.
- Gotchas last. Things that have tripped Claude up before. "Don't use X, use Y instead."
Avoid putting full API documentation or long code examples in CLAUDE.md. It consumes context tokens on every session. Link to docs instead: Claude can read them when needed.
Memory and Context Window
Memory files consume context tokens. A 150-line CLAUDE.md uses roughly 3,000-4,000 tokens. With auto-memory MEMORY.md (200 lines) and user memory (50 lines), you're spending 5,000-8,000 tokens before the first message.
On Claude Opus 4.6 with its 200K context window, this is 2.5-4% of the total. Acceptable. On Haiku with a shorter window, the percentage is higher. If you notice context rot (degraded output quality late in sessions), trim your memory files first.
Context Budget Rule
Keep combined memory files under 10,000 tokens. That is roughly 400 lines of markdown across all three sources. If you need more, use auto-memory topic files (loaded on demand) instead of putting everything in the auto-loaded files.
Memory Files vs MCP Memory Servers
MCP memory servers (like memory-bank-mcp) provide structured, queryable memory with embedding-based retrieval. They are more powerful than flat files but add setup complexity.
| Memory Files | MCP Memory Server | |
|---|---|---|
| Setup | Zero (built in) | Install + configure in settings.json |
| Retrieval | Full file loaded at start | Semantic search, on-demand |
| Scale | Hundreds of lines | Thousands of entries |
| Team sharing | CLAUDE.md via git | Depends on server |
| Best for | 90% of projects | Very large, evolving knowledge bases |
Start with memory files. If you find yourself maintaining a MEMORY.md over 200 lines with increasingly niche details, consider an MCP memory server. For details on MCP setup, see the MCP servers guide.
FAQ
Can I have multiple CLAUDE.md files in subdirectories?
Yes. Claude reads CLAUDE.md from the project root and from subdirectories relevant to the current task. A monorepo can have a root CLAUDE.md for shared conventions and per-package CLAUDE.md files for package-specific details.
How do I see what Claude remembers?
Check ~/.claude/projects/<your-project-path>/memory/MEMORY.md for auto-memory. Open your project's CLAUDE.md for project memory. Run cat ~/.claude/CLAUDE.md for global memory. These are plain text files. Read them, edit them, delete entries that are wrong.
Does memory affect other AI tools?
No. CLAUDE.md and auto-memory are specific to Claude Code. Cursor uses .cursorrules, Copilot uses .github/copilot-instructions.md. The concepts are similar but the files are separate.
Use Morph with Claude Code Memory
Memory files work identically through Morph's API proxy. Get faster file edits with the fast apply model while keeping all your memory context. One environment variable change.