Course navigation
Claude CodeLesson 12 of 25

Memory Management

The previous lesson covered project memory with CLAUDE.md. 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.

LevelLocationScope
User memory~/.claude/CLAUDE.mdEvery project on this machine
Project memoryCLAUDE.md (project root)This project only — shared via git
Imported files@path/to/file in your promptOn demand, for a specific task

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.

~/.claude/CLAUDE.mdMarkdown
## 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
Create it once and your personal preferences load in every project — you never have to add them to individual project CLAUDE.md files again.

How to create it

Terminal
Create the ~/.claude directory if it doesn't exist
$mkdir -p ~/.claude
Create or open the global CLAUDE.md
$code ~/.claude/CLAUDE.md
Opened ~/.claude/CLAUDE.md in VS Code

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, and dev commands.

CLAUDE.mdMarkdown
## 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
Project memory is team memory. Commit CLAUDE.md to git and every developer on the team benefits from it automatically.

Imported memory files

Pull any file into context on demand using the @ prefix in your prompt. The file contents are inserted as additional context for that session — no permanent change to CLAUDE.md needed.

PromptWhat it loads
@docs/api-spec.md — Implement the /users endpoint as describedAPI spec into context for this task
@prisma/schema.prisma — Add a Post model with title, body, and authorIdCurrent schema before Claude adds to it
@memory/stripe-setup.md — Set up checkout using the same pattern as beforePersonal notes file with your preferred Stripe pattern
Keep a personal memory/ folder in your home directory with Markdown files for recurring patterns. 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.

  1. User memory loaded ~/.claude/CLAUDE.md: personal style, language, habits
  2. Project memory loaded CLAUDE.md: stack, folder structure, conventions, commands
  3. Imported files loaded (if any @): task-specific context you explicitly requested
  4. Your message — Claude responds with full awareness of all layers above
If user memory and project memory conflict, project memory wins for that project — it is more specific. Imported files are the most specific and take highest precedence.

Choosing the right level

A quick reference for deciding which memory level to use for a given piece of context.

Context typeWhere to put itWhy
Preferred response style, language~/.claude/CLAUDE.mdPersonal preference — applies everywhere
No-console-log rule for all my code~/.claude/CLAUDE.mdUniversal habit, not project-specific
This project uses Next.js + PrismaCLAUDE.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 promptOne-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/CLAUDE.mdMarkdown
## My Preferences
- Always explain briefly before writing code
- Prefer const/let over var
- Use full variable names, not abbreviations
- Default language: English

CLAUDE.md — project memory

CLAUDE.mdMarkdown
## Stack
Next.js 15 App Router, TypeScript, Tailwind, Prisma
## Folder Structure
- Components: src/components/
- API routes: src/app/api/
## Commands
- Dev: npm run dev
- Test: npm run test

Prompt with @ import — task-specific memory

Claude Code prompt
> @docs/payments-spec.md Implement the POST /api/checkout endpoint described in that spec. Use the existing Stripe client in src/lib/stripe.ts.

Before your message, Claude sees: personal style from user memory, project stack and conventions from CLAUDE.md, and the full contents of docs/payments-spec.md from the import.

Before you continue

  • Three memory levels: user (~/.claude/CLAUDE.md), project (CLAUDE.md), and @ imports.
  • They stack — user first, then project, then any imported files.
  • Put personal habits in user memory; put team conventions in project memory.
  • Use @ imports for one-off task context you do not need every session.
  • Next lesson: Understanding Sub-Agents.

What's Next

Memory management keeps Claude context-aware across long sessions. Next: Sub-Agents — how Claude delegates tasks to specialised agents.