In-session context
Everything in the current conversation window — your messages, Claude’s replies, and tool results — is sent to the Anthropic API on each turn. This is the context window. The context window is finite. As a session grows, older messages consume capacity that could be used for new information. Claude Code manages this automatically, but you can also compress the context manually with/compact.
/compact — compress context
When the context window is getting full,/compact asks Claude to summarize the conversation so far into a compact representation and start fresh from that summary.
Persistent memory
Persistent memory is stored as Markdown files on disk and loaded into every new session automatically. It gives Claude facts that outlast a single conversation.Memory directory
By default, persistent memory lives at:MEMORY.md inside that directory. Claude reads this file at the start of each session (subject to a 200-line / 25 KB cap to keep it from dominating the context).
The memory directory location can be overridden with the
CLAUDE_CODE_REMOTE_MEMORY_DIR environment variable or the autoMemoryDirectory setting in settings.json.Memory types
Memories are classified into four types. Claude uses the type to decide where to look when recalling information and what to prioritize when writing new memories.| Type | Scope | What to store |
|---|---|---|
user | Always private | Your role, expertise level, preferences, working style |
feedback | Private (or team if project-wide) | Corrections and validated approaches from past sessions |
project | Team or private | Project goals, architecture decisions, conventions |
reference | Team or private | External facts, API endpoints, configuration values |
CLAUDE.md — project instructions
CLAUDE.md is a special Markdown file that Claude reads automatically at the start of every session in a project. Use it to give Claude persistent, project-specific instructions that every collaborator benefits from.
Where Claude looks for CLAUDE.md
Claude searches forCLAUDE.md files in multiple locations and merges them:
~/.claude/CLAUDE.md— your personal global instructionsCLAUDE.mdin the project root (git root)CLAUDE.mdin any parent directory up to the filesystem rootCLAUDE.mdin any subdirectory Claude visits during a session
Setting up project memory with CLAUDE.md
Create CLAUDE.md in your project root
Create a
CLAUDE.md file at the root of your repository (next to .git/).Add project-specific instructions
Write instructions in plain Markdown. Focus on things Claude cannot infer from the code — conventions, constraints, and context.
Commit CLAUDE.md to the repository
Checking
CLAUDE.md into version control means every team member and CI run gets the same project instructions automatically.The /memory command
/memory opens an interactive editor for your persistent memory files. Use it to view, add, or edit the facts Claude remembers about you and your projects.
$VISUAL or $EDITOR) with the relevant memory file. You can edit it like any Markdown file. Changes take effect in the next session (or after /compact).
If no editor is configured, Claude Code falls back to a built-in line editor. Set
$EDITOR or $VISUAL in your shell profile to use your preferred editor.Automatic memory extraction
At the end of each conversation turn, Claude Code can automatically extract key facts from the conversation and save them to your memory directory. This happens in a background agent so it does not block the main conversation. Facts are extracted for all four memory types: things you told Claude about yourself (user), feedback you gave (feedback), project context (project), and reference information (reference).
To disable automatic memory extraction:
settings.json:
Team memory sync
When multiple people work on the same project, shared memories can be stored in a team memory directory. Team memories are checked into version control or stored on a shared filesystem so every team member’s Claude session has access to the same project knowledge. Team memory is separate from private memory — facts like personal preferences or individual feedback are never written to the team directory. See the configuration guide for how to set up a shared team memory directory.Related pages
Configuration
Settings for memory directory paths and auto-memory behavior.
Commands: session management
/compact, /resume, and other session commands.
Architecture
How memory is loaded into the system prompt via QueryEngine.
Skills
Reusable workflows that can read and write memory.