Memory Management
The previous lesson covered project memory with CLAUDE.md. But Claude Code actually has three distinct memory levels. Understanding all three lets you put the right context in the right place — and keep sessions focused.
Three levels of memory
Claude Code reads memory files from three scopes. All three are loaded before your first message. They stack — each level adds to the one above it.
~/.claude/CLAUDE.mdCLAUDE.md (project root)@path/to/file in your promptLevel 1 — User Memory
A CLAUDE.md file in your home directory is loaded for every project on your machine. Use it for personal preferences that should apply everywhere — not project-specific rules.
User-level memory
~/.claude/CLAUDE.mdScope: Every Claude Code session on this machine
Loaded globally, before any project CLAUDE.md. Ideal for your preferred coding style, language, response format, and habits you want in every project.
## My Preferences - Response language: English - Always explain what you're about to do before writing code - Prefer functional patterns over class-based ones - Use const/let, never var - When naming variables, prefer full words over abbreviations
How to create it
Level 2 — Project Memory
The project-level CLAUDE.md at your repo root — covered in detail in the previous lesson. It holds everything specific to this codebase: stack, conventions, folder structure, dev commands.
Project memory
CLAUDE.md (project root)Scope: This project only — shared with the whole team via git
Loaded after user memory. Overrides or supplements global preferences. Commit this file so every team member and CI pipeline gets the same context automatically.
## Stack Next.js 15, TypeScript, Tailwind CSS, Prisma ## Conventions - Use 'use client' only when needed - All DB queries go in src/lib/db/ ## Commands - Dev: npm run dev - Test: npm run test
CLAUDE.md to git and every developer on the team benefits from it automatically.Level 3 — Imported Memory Files
You can pull any file into context on demand using the @ prefix directly in your prompt. The file contents are inserted as additional context for that session — no permanent change to CLAUDE.md needed.
Using @ to import a file into context
memory/ folder in your home directory with Markdown files for recurring patterns you use across projects. Reference them with @~/memory/stripe.md whenever you need them.How All Three Levels Stack
When you open a project and send a message, Claude Code builds its context in this order. Each layer adds to the previous one — they do not override each other.
~/.claude/CLAUDE.mdYour personal preferences — style, language, habits
CLAUDE.mdStack, folder structure, conventions, commands for this repo
@docs/api-spec.mdTask-specific context you explicitly requested
Claude responds with full awareness of all layers above
Choosing the Right Level
A quick reference for deciding which memory level to use for a given piece of context.
| Context type | Where to put it | Why |
|---|---|---|
| Preferred response style, language | ~/.claude/CLAUDE.md | Personal preference — applies everywhere |
| No-console-log rule for all my code | ~/.claude/CLAUDE.md | Universal habit, not project-specific |
| This project uses Next.js + Prisma | CLAUDE.md (root) | Project-specific, shared with teammates |
| Our components go in src/components/ | CLAUDE.md (root) | Convention specific to this codebase |
| API spec for the task I'm building now | @ import in prompt | One-off task context, not always needed |
| Personal Stripe integration notes | @ import from ~/memory/ | Cross-project but optional — load on demand |
A Real Example — All Three Levels
Here is what the full memory setup looks like for a developer working on a Next.js SaaS app, with personal preferences, project conventions, and a task-specific import.
~/.claude/CLAUDE.md — user memory
CLAUDE.md — project memory
Prompt with @ import — task-specific memory
What Claude sees before your message
Memory Levels — Quick Reference
~/.claude/CLAUDE.md- ✦ Loaded for every project
- ✦ Personal style & habits
- ✦ Never committed to git
CLAUDE.md- ✦ This project only
- ✦ Stack, conventions, commands
- ✦ Commit to git — team shared
@ in prompt- ✦ On demand only
- ✦ Specs, schemas, notes
- ✦ Most specific — highest precedence
What's Next
Memory management keeps Claude context-aware across long sessions. Next: Sub-Agents — how Claude delegates tasks to specialised agents.