Two Types of Memory
In-session context
The full conversation history, tool results, and file reads live in the LLM’s context window for the duration of a session. When the session ends, this is gone unless you use
/resume.Persistent memory
Key facts, preferences, and project context are written as Markdown files under
~/.claude/. These are loaded automatically into every future session so Claude “remembers” you.Persistent Memory: The ~/.claude/ Directory
Persistent memory lives in a file-based system rooted at ~/.claude/ (or the path set by CLAUDE_CODE_REMOTE_MEMORY_DIR for remote sessions).
The auto-memory directory for a project is resolved in this order:
CLAUDE_COWORK_MEMORY_PATH_OVERRIDEenv var (used by Cowork and SDK deployments).autoMemoryDirectoryinsettings.json(trusted sources: policy, local, or user settings — not project settings, for security).<memoryBase>/projects/<sanitized-git-root>/memory/— the default, scoped to the canonical git root so all worktrees of a repo share one memory directory.
MEMORY.md — The Index File
MEMORY.md is the entrypoint for the memory system. It acts as an index — a concise list of pointers to individual topic files, not a place to write memory content directly.
MEMORY.md is loaded into the system prompt at startup. It is capped at 200 lines and 25,000 bytes — content beyond these limits is truncated with a warning so Claude always starts with a bounded context cost.
Each entry in MEMORY.md follows this pattern:
user, feedback, project, and reference. Content derivable from the codebase (architecture, patterns, git history) is explicitly excluded to prevent stale or redundant memories.
The /memory Command
The/memory slash command opens a full-screen editor for viewing and editing your memory files directly.
- Browse all memory files in the current project’s memory directory.
- Edit any file using your configured editor.
- Add new memory entries.
- Delete outdated or incorrect memories.
Claude will also update memory proactively during conversations. If you ask Claude to “remember” something it saves it immediately; if you ask it to “forget” something it finds and removes the relevant entry.
Auto Memory Extraction
TheextractMemories service (src/services/extractMemories/) runs as a background agent at the end of turns (when the EXTRACT_MEMORIES feature flag is active). It reviews the conversation and automatically extracts facts worth keeping — user preferences, corrections, project decisions — and writes them to the appropriate memory files.
The background agent skips ranges where the main agent already wrote memories (hasMemoryWritesSince check), so there is no duplication.
Auto memory can be disabled per-project or globally:
Project-Level Memory: CLAUDE.md
In addition to the~/.claude/ memory directory, Claude Code reads CLAUDE.md files from the project itself. These are checked into source control and shared with your whole team:
CLAUDE.md files are loaded as nested memory attachments (nestedMemoryAttachmentTriggers) — injected into context when Claude navigates into or works within the corresponding directory. This makes project conventions, coding standards, and architectural decisions available automatically without occupying the main context window permanently.
Context Compression: /compact
When a long session fills the context window, use/compact to compress conversation history while preserving the essential facts.
compact service (src/services/compact/) produces a compressed summary of the conversation history. The summary replaces the raw message history, freeing context space for continued work. A pre_compact hook fires before compression and a post_compact hook fires after, allowing custom processing.
Compact works on the current session only. Past session transcripts are preserved on disk for searching via the memory system’s “Searching past context” feature.
Session Resume: /resume
Claude Code records session transcripts to disk. Use/resume to restore a previous session and continue from where you left off.
src/screens/Resume) lists available past sessions. Selecting one replays the transcript into the UI and restores the conversation state, including any compact boundaries that were recorded.
Team Memory Sync
When theTEAMMEM feature flag is active, a team memory directory is maintained alongside the personal auto-memory directory:
teamMemorySync service (src/services/teamMemorySync/) synchronizes the team/ subdirectory across team members. Both the personal and team memory directories are loaded into context and presented to Claude as separate namespaced memory systems, so Claude can distinguish between individual preferences and shared team knowledge.