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
| Layer | Technology |
|---|---|
| Language | TypeScript (ES2022, ESNext modules) |
| Runtime | Node.js 18+ |
| Database | SQLite 3 with bun:sqlite driver |
| Vector store | ChromaDB (optional, for semantic search) |
| HTTP server | Express.js 4.18 |
| Real-time | Server-Sent Events (SSE) |
| UI framework | React + TypeScript |
| AI SDK | @anthropic-ai/claude-agent-sdk |
| Build tool | esbuild (bundles TypeScript) |
| Process manager | Bun |
| Testing | Node.js built-in test runner |
Data flow
Memory pipeline
Processing
The worker service reads queued observations and processes them via the Claude Agent SDK.
Search pipeline
Session lifecycle
Directory structure
Component details
Plugin hooks (6 hooks)
Plugin hooks (6 hooks)
| Hook file | Event | Responsibility |
|---|---|---|
context-hook.js | SessionStart | Starts Bun worker, injects context from previous sessions |
user-message-hook.js | UserMessage | Debugging hook |
new-hook.js | UserPromptSubmit | Creates session record, saves raw prompt |
save-hook.js | PostToolUse | Captures tool executions, queues for AI compression |
summary-hook.js | Stop | Generates final session summary |
cleanup-hook.js | SessionEnd | Marks session complete (never deletes) |
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)