loading…
Search for a command to run...
loading…
Persistent, self-evolving memory plugin for Claude Code. Background miner extracts durable lessons (decisions, conventions, bug fixes) from completed sessions v
Persistent, self-evolving memory plugin for Claude Code. Background miner extracts durable lessons (decisions, conventions, bug fixes) from completed sessions via Claude Haiku, stores them as human-readable markdown in an Obsidian vault, and assembles query-tailored context briefings at session start. Local-first, no cloud, no API keys. Self-healing install via uv bootstrap shim, /cortex-doctor preflight, graceful FTS-only degraded mode when claude CLI missing. MIT.
Persistent, self-evolving memory for Claude Code. Stop re-explaining your project every session.
CI memem MCP server License: MIT Python 3.11+
For LLM/AI tool discovery, see llms.txt.
███╗ ███╗███████╗███╗ ███╗███████╗███╗ ███╗
████╗ ████║██╔════╝████╗ ████║██╔════╝████╗ ████║
██╔████╔██║█████╗ ██╔████╔██║█████╗ ██╔████╔██║
██║╚██╔╝██║██╔══╝ ██║╚██╔╝██║██╔══╝ ██║╚██╔╝██║
██║ ╚═╝ ██║███████╗██║ ╚═╝ ██║███████╗██║ ╚═╝ ██║
╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
persistent memory for Claude Code
memem is a Claude Code plugin that gives Claude persistent memory across sessions. A background miner extracts durable lessons (decisions, conventions, bug fixes, preferences) from your completed sessions, stores them as markdown in an Obsidian vault, and automatically surfaces relevant ones at the start of each new session via a query-tailored briefing.
It's local-first: no cloud services, no API keys required, no vendor lock-in. Everything lives in ~/obsidian-brain/memem/memories/ as human-readable markdown.
Use memem if:
CLAUDE.md is a single hand-edited file per project. memem gives you:
memem uses a 3-tier recall workflow inspired by claude-mem and mem0. Instead of dumping full memory content on every recall, it lets Claude progressively drill into relevant memories:
Session start
┌─────────────────────────────┐
│ SessionStart hook injects: │
│ • L0 full content (~20) │
│ • Compact index of rest │
└──────────┬──────────────────┘
│
▼
During session
┌─────────────────────────────┐
│ 1. memory_search(query) │ → compact index (50 tok/result)
│ 2. memory_get(ids=[...]) │ → full content (500 tok/result)
│ 3. memory_timeline(id) │ → chronological thread
└─────────────────────────────┘
│
▼
┌─────────────────────────────┐
│ UserPromptSubmit hook │ → always runs active slice
│ (active_slice engine) │ and refreshes working state
└─────────────────────────────┘
Memory layers (auto-classified at mining time):
| Layer | Purpose | Injection |
|---|---|---|
| L0 | Project identity — tech stack, repo structure, core conventions | Full content at session start |
| L1 | Generic conventions — testing, style, commit patterns | Compact index at session start |
| L2 | Domain-specific — most memories (default) | Compact index at session start |
| L3 | Rare/archival — niche failure modes, one-off lessons | Compact index at session start |
Token efficiency: session start injects ~50 tokens per L1-L3 memory (ID + title + snippet) instead of full content. Claude drills into specific memories via memory_get(ids=[...]) only when it needs full detail.
Active Memory Slice runtime kernel:
For ongoing work, active_memory_slice(query, scope_id) sits above recall. It
uses memory_search/FTS/graph/playbooks/transcripts as candidate generation,
then activates a structured working state:
Memory Vault
→ Candidate Generation
→ Activation Judgement
→ Active Memory Slice
→ Delta Proposals
→ Memory Vault
The slice explicitly separates goals, constraints, background, decisions, preferences, failure patterns, artifacts, open tensions, and candidate deltas. Delta proposals are advisory in v1 and are not auto-committed to the vault.
Opt-in features:
MEMEM_SHOW_BANNER=1 — show a one-line status banner at session start (off by default)MEMEM_PRETOOL_GATING=1 — enrich Read tool calls with memories about the target file (off by default)MEMEM_TOPIC_SHIFT_THRESHOLD=0.3 — keyword overlap threshold for topic-shift re-firing (default 0.3)Copy-paste:
claude plugin marketplace add TT-Wang/memem
claude plugin install memem@memem-marketplace
If you already added the marketplace once, future installs only need the second command.
Then:
That's it. On first run, bootstrap.sh self-heals everything:
uv python install 3.11 if your system Python is too olduv if missing (via the official Astral installer).venv (hash-cached against uv.lock)~/.memem/ and ~/obsidian-brain/~/.memem/.capabilities (used for degraded-mode decisions)First run: ~5 seconds. Every run after: ~100ms. No separate pip install step.
Nothing mines until you opt in. memem is strictly opt-in as of v0.9.0 — install does not start the miner or touch your sessions. Type /memem to see status and choose what to do next. You can start mining two ways:
/memem-mine — mine new sessions only (from now on)/memem-mine-history — mine everything, including past history (uses Haiku API credits)Or just tell Claude "start mining new sessions" / "start mining everything including history" — it knows what to do.
/memem-mine if you only want memory from new sessions going forward/memem-mine-history if you want memem to process your old Claude Code sessions tooIf you are unsure, start with /memem-mine. It is the safer and cheaper default.
You type your first message. The UserPromptSubmit hook fires and sees zero memories (you just installed it), so it injects a welcome banner into Claude's context. Claude reads the banner, tells you memem is active, and — if you have pre-existing Claude Code sessions — offers to mine them via /memem-mine-history.
You work normally. The miner daemon runs silently in the background. When your session ends and settles for 5 minutes, the miner extracts memories from the transcript using Claude Haiku and writes them to your vault.
During the session: every user prompt goes through active_memory_slice, which builds a structured working-state briefing from the relevant memories, playbooks, transcripts, and graph neighbors. You see an active slice prompt with goals, constraints, background, decisions, failure patterns, open tensions, and artifacts. Claude starts with the current working state instead of a generic briefing.
claude plugin marketplace add TT-Wang/memem
claude plugin install memem@memem-marketplace
Then in Claude Code:
/memem
And choose one:
/memem-mine
or
/memem-mine-history
It saves durable knowledge, not session logs:
tests/ not spec/", "commit messages use imperative mood", "never import from internal/ outside its package")bcrypt.compare is async — must await", "timezone math must use dayjs.utc() or DST shifts the result by an hour")JWT_SECRET defaults to 'secret' if unset — tracked in #123", "pnpm install hangs on corporate VPN, use --network-timeout=600000")nvm use", "Redis must be running on :6380 not :6379")repo/ layer, never raw SQL in handlers")It does NOT save:
transcript_search, not stored as memories)| Store | Path | Purpose |
|---|---|---|
| Memories | ~/obsidian-brain/memem/memories/*.md |
Source of truth (human-readable markdown) |
| Playbooks | ~/obsidian-brain/memem/playbooks/*.md |
Per-project curated briefings |
| Search DB | ~/.memem/search.db |
SQLite FTS5 index (machine-fast lookup) |
| Graph DB | ~/.memem/graph.db |
Rebuildable typed/scored memory-edge index |
| Telemetry | ~/.memem/telemetry.json |
Access tracking (atomic writes) |
| Event log | ~/.memem/events.jsonl |
Append-only audit trail |
| Capabilities | ~/.memem/.capabilities |
Degraded-mode flags written by bootstrap |
| Bootstrap log | ~/.memem/bootstrap.log |
First-run diagnostics |
You can point memem elsewhere via MEMEM_DIR and MEMEM_OBSIDIAN_VAULT env vars.
| Tool | What it does |
|---|---|
memory_save(content, title, tags) |
Store a lesson. Security-scanned for prompt injection and credential exfil before writing. |
memory_recall(query, limit) |
Search memories. FTS5 + temporal decay + access reinforcement + importance weighting. |
memory_list(scope_id) |
List all memories with stats, grouped by project. |
memory_import(source_path) |
Bulk import from files, directories, or chat exports. |
transcript_search(query) |
Search raw Claude Code session JSONL logs (not the mined memories). |
context_assemble(query, project) |
On-demand query-tailored briefing from playbooks + memories + transcripts. |
memory_graph(memory_id) |
Inspect typed/scored graph neighbors for one memory. |
memory_graph_audit() |
Report graph quality issues: orphans, dead links, hubs, stale edges. |
memory_graph_rebuild(scope_id) |
Rebuild the graph side index from the Obsidian vault. |
active_memory_slice(query, scope_id) |
Build a structured runtime working state for current work. |
/memem — welcome, status, help/memem-status — memory count, projects, search DB size, miner health/memem-doctor — preflight health check with fix instructions for any blocker/memem-mine — start the miner daemon manually (normally auto-starts)/memem-mine-history — opt-in: mine all your pre-install Claude Code sessionsclaude CLI isn't on my PATH?memem enters degraded mode — it still works, just without Haiku-powered context assembly and smart recall. You get FTS-only keyword recall instead of query-tailored briefings. Every session shows [memem] N memories · miner OK · assembly degraded (claude CLI missing — FTS-only recall) at the top of the context, so you know why.
This is by design: missing optional dependencies should degrade, not fail.
Run /memem-doctor. It runs the same preflight the bootstrap shim runs (Python version, mcp importable, claude CLI on PATH, directory writability, uv available), then prints a report labelled HEALTHY, DEGRADED, or FAILING with explicit fix instructions for each blocker.
For deeper debugging:
tail -f ~/.memem/bootstrap.log # first-run shim log
tail -f ~/.memem/miner.log # miner daemon log
cat ~/.memem/events.jsonl # memory operation audit trail
bash "${CLAUDE_PLUGIN_ROOT:-.}/bootstrap.sh" --status # detailed status dump
Session ends → miner daemon sees the JSONL file in ~/.claude/projects/
→ Waits 5 minutes for the file to "settle" (no more writes)
→ Filters to human messages + assistant prose (strips tool calls, system reminders)
→ One Haiku call with the full context: "extract durable lessons"
→ Haiku returns JSON array of memory candidates
→ Each candidate runs: security scan → dedup check → contradiction detection → save
→ Index rebuilt, per-project playbooks grown and refined
→ Session marked COMPLETE in ~/.memem/.mined_sessions
First message in a new session → auto-recall.sh hook fires
→ Reads ~/.memem/.capabilities for status banner
→ Builds an active memory slice from recall candidates + graph/playbook/transcript context
→ Emits a structured "Active Memory Slice" prompt block
→ If the slice engine is unavailable → falls back to compact recall
→ Either way, Claude starts its reply with active work-state context already loaded
memem is split into small, focused modules:
models.py — data types, path constantssecurity.py — prompt injection + credential exfil scanningtelemetry.py — access tracking, event log (atomic writes, fcntl-locked)search_index.py — SQLite FTS5 indexgraph_index.py — typed/scored related-memory graph side indexactive_slice.py — active slice schemas and markdown projectionactivation.py — heuristic + bounded LLM activation judgementboundaries.py — scope/deprecated/budget/redundancy filtersdelta.py — non-mutating candidate delta proposalsactive_slice_engine.py — candidate generation and slice orchestrationobsidian_store.py — memory I/O, dedup scoring, contradiction detectionplaybook.py — per-project playbook grow + refineassembly.py — context assembly via Haikucapabilities.py — runtime feature detection for degraded modestorage.py — server-lifecycle helpers (PID management, miner auto-start)server.py — thin MCP entrypoint (FastMCP imported lazily)cli.py — command dispatcher for non-MCP entrypointsmining.py — session mining pipelineMulti-signal recall scoring:
Related-memory graph:
The Obsidian markdown files remain the source of truth. The related: [...]
frontmatter stays intentionally simple so memories are portable and readable.
memem also builds ~/.memem/graph.db, a local SQLite side index with typed,
scored edges such as same_topic, supports, depends_on, supersedes, and
contradicts. Recall uses this graph when available and falls back to the
Markdown related field if the graph has not been built yet.
Useful maintenance commands:
memem graph rebuild
memem graph audit
memem graph stats
memem graph neighbors <memory-id>
Memory schema (markdown frontmatter):
---
id: uuid
schema_version: 1
title: "descriptive title"
project: project-name
tags: [mined, project-name]
related: [id1, id2, id3]
created: 2026-04-13
updated: 2026-04-13
source_type: mined | user | import
source_session: abc12345
importance: 1-5
status: active | deprecated
valid_to: # set when deprecated
contradicts: [id1] # flagged conflicts
---
| Env var | Default | Purpose |
|---|---|---|
MEMEM_DIR |
~/.memem |
State directory (PID files, search DB, logs) |
MEMEM_OBSIDIAN_VAULT |
~/obsidian-brain |
Vault location |
MEMEM_EXTRA_SESSION_DIRS |
(none) | Colon-separated extra session dirs to mine |
MEMEM_MINER_SETTLE_SECONDS |
300 |
Seconds to wait before mining a completed session |
MEMEM_SKIP_SYNC |
0 |
Bootstrap skips uv sync when set to 1 (dev only) |
memem works without Obsidian — it just writes markdown. But Obsidian gives you graph view and backlinks for free:
~/obsidian-brain as a vaultmemem/memories/, playbooks in memem/playbooks/related fielduv (auto-installed by bootstrap.sh on first run)claude CLI on PATH (optional — required for Haiku-powered assembly; degraded mode works without it)git clone https://github.com/TT-Wang/memem.git
cd memem
pip install -e ".[dev]"
pytest # 54 tests
ruff check . # lint
mypy memem # type check (strict)
See CONTRIBUTING.md for the PR process and CHANGELOG.md for version history.
memory_save patterns land in memem's recall index, so next week's
run starts with last week's lessons already loaded.MIT
Добавь это в claude_desktop_config.json и перезапусти Claude Desktop.
{
"mcpServers": {
"tt-wang-cortex-plugin": {
"command": "npx",
"args": []
}
}
}PRs, issues, code search, CI status
Database, auth and storage
Reference / test server with prompts, resources, and tools.
Secure file operations with configurable access controls.