Architecture overview
Claude-Mem is a Claude Code plugin with persistent memory across sessions. It captures tool usage, compresses observations using the Claude Agent SDK, and injects relevant context into future sessions.System components
Claude-Mem operates as a Claude Code plugin built from five core components:Plugin hooks
Six lifecycle hooks capture events: SessionStart, UserPromptSubmit, PostToolUse, Stop, SessionEnd, and a UserMessage debugging hook.
Smart install
A cached dependency checker (
smart-install.js) that runs as a pre-hook before context-hook. Only executes when dependency versions change.Worker service
Long-running Express.js HTTP server on port 37777. Processes observations via the Claude Agent SDK and exposes 22 HTTP endpoints.
Database layer
SQLite 3 with the
bun:sqlite driver. FTS5 virtual tables for full-text search, ChromaDB for semantic vector search.MCP search tools
Four MCP tools (
search, timeline, get_observations, __IMPORTANT) following a 3-layer progressive disclosure workflow.Viewer UI
React + TypeScript web interface at
http://localhost:37777. Real-time memory stream via Server-Sent Events, packaged as a single viewer.html bundle.smart-install.js is a pre-hook dependency checker — not a lifecycle hook. It is called before context-hook via command chaining in hooks.json and only runs when dependencies need updating.Technology stack
Data flow
Memory pipeline
1
Input
Claude Code sends tool execution data via stdin to hooks.
2
Storage
Hooks write raw observations to the SQLite database.
3
Processing
The worker service reads queued observations and processes them via the Claude Agent SDK.
4
Output
Processed summaries and structured learnings are written back to the database.
5
Retrieval
The next session’s
context-hook reads summaries from the database and injects them as context.Search pipeline
1
User query
User asks naturally: “What bugs did we fix?”
2
MCP tools invoked
Claude recognizes the intent and invokes MCP search tools.
3
HTTP API
MCP tools call the HTTP endpoint (e.g.,
GET /api/search).4
SessionSearch
The worker service queries FTS5 virtual tables via the
SessionSearch service.5
Format
Results are formatted as a compact index and returned via MCP.
6
Return
Claude presents formatted results to the user, fetching full details only for selected IDs.
Session lifecycle
Directory structure
Component details
Plugin hooks (6 hooks)
Plugin hooks (6 hooks)
Worker service
Worker service
Express.js HTTP server on port 37777 (configurable via
CLAUDE_MEM_WORKER_PORT) with:- 22 HTTP API endpoints total
- Async observation processing via Claude Agent SDK
- Real-time updates via Server-Sent Events
- Auto-managed by Bun’s native
ProcessManager
Database layer
Database layer
SQLite 3 with
bun:sqlite driver featuring:- FTS5 virtual tables for full-text search
SessionStorefor CRUD operationsSessionSearchfor FTS5 queries- ChromaDB integration for vector/semantic search
- Location:
~/.claude-mem/claude-mem.db
MCP search tools
MCP search tools
Four MCP tools following the 3-layer progressive disclosure workflow:
__IMPORTANT— Always-visible workflow instructionssearch— Step 1: compact index with IDs (~50–100 tokens/result)timeline— Step 2: chronological context around a resultget_observations— Step 3: full details for selected IDs only
Viewer UI
Viewer UI
React + TypeScript web interface at
http://localhost:37777 featuring:- Real-time memory stream via Server-Sent Events
- Infinite scroll pagination with automatic deduplication
- Project filtering and settings persistence
- GPU-accelerated animations
- Theme toggle (light/dark mode, v5.1.2+)
- Self-contained HTML bundle (
viewer.html)