Skip to content

Claude Code Memory System Documentation

Complete usage guide and technical implementation documentation for the memory system


Documentation Index

01-usage-guide.md — Usage Guide

A comprehensive user-facing manual covering:

  • Four memory types: User (user profile), Feedback (behavioral feedback), Project (project context), Reference (external references)
  • Four trigger methods: Automatic extraction, explicit requests, /memory command, /remember command
  • Storage format: YAML frontmatter + Markdown content
  • Management operations: Forgetting, ignoring, manual editing, disabling, custom directories
  • Lifecycle: From learning to injection, freshness management

Target audience: All Claude Code users


02-implementation.md — Implementation Details

A deep technical analysis for developers, covering:

  • 5 core modules: Path resolution, prompt construction, memory scanning, intelligent retrieval, automatic extraction
  • Path resolution system: Priority chain, security validation, enable conditions
  • System prompt injection: loadMemoryPrompt() -> buildMemoryLines(), MEMORY.md truncation strategy
  • Automatic memory extraction: Forked agent, mutual exclusion mechanism, tool permissions, merge mechanism
  • Intelligent retrieval: scanMemoryFiles() -> Sonnet selection -> freshness warnings
  • Agent memory: Three-level scoping (user/project/local)
  • Team memory sync: Pull/Push API, merge semantics
  • Complete data flow: From session startup to context injection

Target audience: Contributors, architects, developers who want a deep understanding of the implementation


03-autodream.md — AutoDream Memory Consolidation

Claude's "dreaming" mechanism -- a deep dive into background silent memory consolidation, covering:

  • Core concept: Like how the human brain organizes memories during sleep, periodically reviewing multiple sessions to consolidate knowledge
  • Five-gate check: Feature toggle -> Time gate (24h) -> Scan throttle (10min) -> Session gate (5 sessions) -> Lock gate
  • Four-phase process: Orient -> Gather -> Consolidate -> Prune
  • Security restrictions: Read-only Bash, write operations limited to memory directory, PID lock file mutual exclusion
  • UI presentation: Bottom "dreaming" label, Shift+Down detail dialog, completion notification
  • Configuration control: settings.json local toggle + GrowthBook remote feature flag
  • Comparison with extractMemories: Taking notes during the day vs. organizing the notebook while sleeping

Target audience: Contributors, architects, developers interested in Claude's automated memory management


Illustrations

All illustrations use a dark background (#1a1a2e) + Anthropic brand copper-orange (#D97757) style, consistent with the official Claude Code documentation.

ImageDescriptionSize
01-memory-overview.pngMemory system overview -- four-layer architecture (trigger/type/storage/retrieval)632 KB
02-memory-types.pngFour memory types -- 2x2 grid showing User/Feedback/Project/Reference507 KB
03-memory-trigger.pngMemory trigger flow -- four paths from conversation to storage474 KB
04-memory-lifecycle.pngMemory lifecycle -- complete cycle flow + freshness checks1.0 MB
05-architecture-overview.pngImplementation architecture overview -- 5 core modules + auxiliary modules3.5 MB
06-path-resolution.pngPath resolution flow -- three-level priority + security validation1.0 MB
07-prompt-injection.pngPrompt injection flow -- loadMemoryPrompt dispatch logic1.1 MB
08-auto-extraction.pngAuto-extraction flow -- forked agent complete process1.2 MB
09-memory-retrieval.pngIntelligent retrieval flow -- Sonnet selection + freshness management816 KB
10-agent-memory.pngAgent memory scoping -- three-level nested structure523 KB
11-autodream-overview.pngAutoDream overview -- dreaming mechanism core architecture and human sleep analogy777 KB
12-autodream-trigger.pngAutoDream trigger flow -- five-gate check chain493 KB
13-autodream-phases.pngAutoDream four phases -- Orient/Gather/Consolidate/Prune602 KB

Quick Start

For Users

  1. Read the Usage Guide
  2. Learn about the four memory types and trigger methods
  3. Try the /memory and /remember commands

For Developers

  1. Read the Implementation Details
  2. Explore the source code:
    • src/memdir/paths.ts -- Path resolution
    • src/memdir/memdir.ts -- Prompt construction
    • src/memdir/memoryScan.ts -- Memory scanning
    • src/memdir/findRelevantMemories.ts -- Intelligent retrieval
    • src/services/extractMemories/ -- Automatic extraction
  3. Understand the data flow and module interactions

Core Concepts Quick Reference

ConceptDescription
MEMORY.mdIndex file, always loaded into context (max 200 lines / 25KB)
Topic files*.md files containing frontmatter + content
Auto-extractionRuns in the background after each response; a forked agent analyzes the conversation
AutoDreamTriggers after 24h + 5 sessions; consolidates/deduplicates/prunes all memories in the background
Intelligent retrievalSonnet model selects up to 5 relevant memories from the entire collection
Freshness<=1 day: no warning; >1 day: stale warning attached
Forked agentShares prompt cache, restricted tool permissions, max 5 turns
Three-level scopingAgent memory: user (global) > project (project-level) > local (local-level)

Released under the MIT License.