Skip to main content

Module memory

Module memory 

Source
Expand description

Read-side access to Claude Code’s per-project memory directories.

Claude Code’s auto-memory persists facts per project under ~/.claude/projects/<slug>/memory/: a MEMORY.md index (one line per memory, loaded into context each session) plus one fact per <stem>.md file with YAML frontmatter. A typical fact file:

---
name: cluster-72-canonical-slot-crash
description: one-line summary used for recall relevance
metadata:
  type: project
---

The fact body, with [[wiki-style]] links to other memories.

This module is read-only on purpose, like the other introspection modules. The layout is undocumented Claude Code internal state (observed against CLI 2.1.219) and can change across CLI versions, so parsing is permissive: name, description, and the type under metadata: are typed (as plain strings); every other frontmatter key lands in Memory::extra verbatim.

YAML block scalars (>, >-, >+, |, |-, |+) are supported for any key, which is how multi-line descriptions are usually written. > folds the block into one line, | preserves the line breaks, and the chomping indicator controls the trailing newline. Continuation lines are part of the value even when they contain a colon.

Three levels of granularity:

§Example

use claude_wrapper::memory::MemoryRoot;

let root = MemoryRoot::home()?;
for project in root.list_projects_with_memory()? {
    println!("{}: {} memories", project.slug, project.entry_count);
    for m in root.list(&project.slug)? {
        println!("  {}: {}", m.name, m.description.as_deref().unwrap_or(""));
    }
}

Structs§

Memory
Full memory record returned by MemoryRoot::get.
MemoryRoot
Root directory of Claude Code’s per-project state. Defaults to ~/.claude/projects (memory directories live under each project slug); override with MemoryRoot::at for tests or non-default installs.
MemorySummary
Lightweight metadata for one memory file, returned by MemoryRoot::list. Strips the body to keep listings cheap.
ProjectMemorySummary
One project that has a memory directory, returned by MemoryRoot::list_projects_with_memory.