Claude-Mem: Give Claude Code Permanent Memory Across Sessions
Every Claude Code user knows the pain. You spend hours building something, close the session, open a new one, and Claude has zero memory of what you did. You explain the same architecture, point to the same files, re-establish the same context.
Claude-Mem fixes this. Itβs a plugin that automatically captures everything Claude does, compresses it with AI, and injects relevant context back into future sessions. No manual intervention. No copy-pasting. Just continuity.
Photo by Shubham Dhage on Unsplash
The Problem: Sessions Are Ephemeral
Claude Code is powerful. But every session starts from scratch:
- π§ No memory of previous sessions
- π You re-explain project structure every time
- π Context is lost when the window closes
- πΈ Tokens wasted on re-establishing knowledge
Some developers work around this with CLAUDE.md files or manual context docs. But these are static β you have to maintain them yourself, and they canβt capture the nuances of actual work sessions.
The Solution: Claude-Mem
Claude-Mem is an open-source plugin (AGPL-3.0) by Alex Newman that gives Claude Code persistent memory through automatic capture and AI-powered compression.
Key Features
| Feature | Description |
|---|---|
| π§ Persistent Memory | Context survives across sessions automatically |
| π Progressive Disclosure | Layered memory retrieval β fetch only whatβs needed |
| π Semantic Search | Query your project history with natural language |
| π₯οΈ Web Viewer UI | Real-time memory stream at localhost:37777 |
| π Privacy Control | Tag-based exclusion for sensitive content |
| βοΈ Zero Configuration | Works out of the box after install |
| π§ͺ Beta Channel | Experimental features like Endless Mode |
Installation (2 Commands)
Open a Claude Code session and run:
/plugin marketplace add thedotmack/claude-mem
/plugin install claude-mem
Restart Claude Code. Done. The plugin automatically:
- Downloads prebuilt binaries (no compilation)
- Installs all dependencies including SQLite
- Configures lifecycle hooks
- Auto-starts the worker service on first session
System Requirements
- Node.js: 18.0.0+
- Claude Code: Latest version with plugin support
- Bun: Auto-installed if missing
- SQLite 3: Bundled
How It Works
Claude-Mem hooks into Claude Codeβs lifecycle at 5 key points:
The Session Lifecycle
ββββββββββββββββββββββββββββββββββββββββββββββββ
β 1. Session Starts β Context Hook β
β Injects context from previous sessions β
ββββββββββββββββββββββββββββββββββββββββββββββββ€
β 2. User Types Prompt β New Session Hook β
β Creates session in database β
ββββββββββββββββββββββββββββββββββββββββββββββββ€
β 3. Claude Uses Tools β PostToolUse Hook β
β Captures every tool execution (100+ times)β
ββββββββββββββββββββββββββββββββββββββββββββββββ€
β 4. Claude Stops β Summary Hook β
β Generates session summary β
ββββββββββββββββββββββββββββββββββββββββββββββββ€
β 5. Session Ends β Cleanup Hook β
β Marks session complete β
ββββββββββββββββββββββββββββββββββββββββββββββββ
What Gets Captured
Every tool usage is recorded:
- Read β file reads and content access
- Write β new file creation
- Edit β file modifications
- Bash β command executions
- Glob β file pattern searches
- Grep β content searches
- All other Claude Code tools
How Itβs Processed
The worker service (running on Bun at port 37777) processes each observation using the Claude Agent SDK and extracts:
- Title β brief description of what happened
- Narrative β detailed explanation
- Facts β key learnings as bullet points
- Concepts β relevant tags and categories
- Type β classification (decision, bugfix, feature, refactor, discovery)
- Files β which files were read or modified
Session Summaries
When Claude finishes responding, a summary is automatically generated:
- Request β what you asked for
- Investigated β what Claude explored
- Learned β key discoveries
- Completed β what was accomplished
- Next Steps β what to do next
Progressive Disclosure: The Smart Part
This is where Claude-Mem really shines. Traditional approaches dump all context upfront β wasting tokens on irrelevant history. Claude-Mem uses a 3-layer progressive disclosure strategy:
Layer 1: Compact Index (~800 tokens)
At session start, Claude sees a lightweight index:
### Feb 3, 2026
| ID | Time | T | Title | Tokens |
|-------|---------|----|--------------------------------|--------|
| #2586 | 2:15 PM | π‘ | Fixed auth middleware timeout | ~105 |
| #2587 | 2:30 PM | π’ | Added rate limiting to API | ~155 |
| #2589 | 3:00 PM | π΄ | CORS gotcha with credentials | ~80 |
Each observation shows what it is and how much it costs to retrieve.
Layer 2: On-Demand Details (MCP Tools)
When Claude needs more context, it fetches specific observations:
// Step 1: Search for relevant observations
search(query="authentication bug", type="bugfix", limit=10)
// Step 2: Get full details for relevant IDs only
get_observations(ids=[2586, 2589])
Layer 3: Source Code Access
If needed, Claude reads original source files directly.
The Token Math
| Approach | Tokens Used | Relevant |
|---|---|---|
| Traditional (dump everything) | ~35,000 | ~6% |
| Claude-Mem (progressive) | ~920 | ~100% |
Thatβs roughly ~10x more efficient token usage. Your context window stays clean for actual work.
Observation Type Icons
Claude-Mem categorizes observations with visual markers:
| Icon | Type | Description |
|---|---|---|
| π― | session-request | Userβs original goal |
| π΄ | gotcha | Critical edge case or pitfall |
| π‘ | problem-solution | Bug fix or workaround |
| π΅ | how-it-works | Technical explanation |
| π’ | what-changed | Code/architecture change |
| π£ | discovery | Learning or insight |
| π | why-it-exists | Design rationale |
| π€ | decision | Architecture decision |
| βοΈ | trade-off | Deliberate compromise |
Configuration
Settings live in ~/.claude-mem/settings.json (auto-created on first run):
{
"CLAUDE_MEM_MODEL": "sonnet",
"CLAUDE_MEM_PROVIDER": "claude",
"CLAUDE_MEM_CONTEXT_OBSERVATIONS": 50,
"CLAUDE_MEM_WORKER_PORT": 37777,
"CLAUDE_MEM_LOG_LEVEL": "INFO"
}
Key Settings
| Setting | Default | Description |
|---|---|---|
CLAUDE_MEM_MODEL |
sonnet |
AI model for processing (haiku/sonnet/opus) |
CLAUDE_MEM_PROVIDER |
claude |
Provider: claude, gemini, or openrouter |
CLAUDE_MEM_CONTEXT_OBSERVATIONS |
50 |
Observations injected per session (1-200) |
CLAUDE_MEM_WORKER_PORT |
37777 |
Worker service port |
CLAUDE_MEM_SKIP_TOOLS |
(several) | Tools to exclude from capture |
Using Alternative Providers
Want to save on API costs? Claude-Mem supports Gemini (with a free tier!) and OpenRouter (100+ models):
{
"CLAUDE_MEM_PROVIDER": "gemini",
"CLAUDE_MEM_GEMINI_API_KEY": "your-key-here",
"CLAUDE_MEM_GEMINI_MODEL": "gemini-2.5-flash-lite"
}
Web Viewer UI
Claude-Mem includes a real-time web viewer at http://localhost:37777:
- Live memory stream via Server-Sent Events
- Infinite scroll with automatic deduplication
- Project filtering across multiple repos
- Settings panel with live Terminal Preview
- Version channel switching (stable β beta)
The viewer shows exactly what context will be injected at the start of your next session.
Privacy Controls
Claude-Mem captures everything by default, but you can exclude sensitive content:
- Use privacy tags in your code/comments to prevent capture
- Configure
CLAUDE_MEM_SKIP_TOOLSto exclude specific tool types - Filter by observation type in context injection settings
- All data stays local in
~/.claude-mem/claude-mem.db
The Tech Stack
| Layer | Technology |
|---|---|
| Language | TypeScript (ES2022) |
| Runtime | Node.js 18+ / Bun |
| Database | SQLite 3 + FTS5 |
| Vector Store | ChromaDB (optional, semantic search) |
| HTTP Server | Express.js |
| Real-time | Server-Sent Events |
| UI | React + TypeScript |
| AI SDK | @anthropic-ai/claude-agent-sdk |
Claude-Mem vs. Manual Context Files
| Feature | Manual (CLAUDE.md) | Claude-Mem |
|---|---|---|
| Capture | Manual | Automatic |
| Compression | None | AI-powered |
| Search | grep/find | Semantic + FTS5 |
| Token Efficiency | Low (dumps everything) | High (progressive disclosure) |
| Maintenance | You do it | Self-maintaining |
| Cross-session | Static file | Dynamic, session-aware |
| Privacy | Manual redaction | Tag-based exclusion |
Practical Tips
1. Let It Run
Donβt micro-manage Claude-Mem. Install it and forget about it. The magic is in the automation.
2. Check the Web Viewer
Visit localhost:37777 periodically to see whatβs being captured. Itβs surprisingly insightful to see your work patterns.
3. Tune the Observation Count
If Claude Code feels slow at startup, reduce CLAUDE_MEM_CONTEXT_OBSERVATIONS from 50 to 25. If you need more history, increase it up to 200.
4. Use Natural Language Search
Donβt memorize search syntax. Just ask Claude naturally:
βWhat bugs did we fix last week?β βHow did we implement the auth middleware?β βShow me recent changes to worker-service.tsβ
Claude automatically invokes the MCP search tools.
5. Try the Beta Channel
Endless Mode (available in beta) uses a biomimetic memory architecture for extended sessions. Switch via the web viewer settings.
Who Should Use This?
Use Claude-Mem if you:
- Use Claude Code regularly for the same projects
- Hate re-explaining project context every session
- Want to search your coding history semantically
- Care about token efficiency
Skip it if you:
- Only use Claude Code occasionally
- Work on many unrelated one-off projects
- Prefer manual context management
Getting Started
/plugin marketplace add thedotmack/claude-mem
/plugin install claude-mem
Two commands. Thatβs it. Your next Claude Code session will already start building memory.
Links: