Skip to main content
Version: 7.0.0 (December 2025)
Target Audience: Developers building claude-mem integrations (VSCode extensions, IDE plugins, CLI tools)

Quick Reference

Worker Base URL

http://localhost:37777
Override with CLAUDE_MEM_WORKER_PORT

Health Check

GET /api/health
Returns { "status": "ok" }

Queue Observation

POST /api/sessions/observations
Pass claudeSessionId + tool data

SSE Stream

GET /stream
Real-time events for UI updates

Most Common Operations

Environment Variables

Build Commands (Local Development)

Worker Architecture

Request Flow

Domain Services

DatabaseManager

SQLite connection management, initialization

SessionManager

Event-driven session lifecycle, message queues

SearchManager

Search orchestration (FTS5 + Chroma)

SSEBroadcaster

Server-Sent Events for real-time updates

SDKAgent

Claude Agent SDK for generating observations/summaries

PaginationHelper

Query pagination utilities

SettingsManager

User settings CRUD

FormattingService

Result formatting (index vs full)

TimelineService

Unified timeline generation

Route Organization

  • Health check endpoint
  • Viewer UI (React app)
  • SSE stream for real-time updates
  • Session lifecycle (init, observations, summarize, complete)
  • Privacy checks and tag stripping
  • Auto-start SDK agent generators
  • Data retrieval (observations, summaries, prompts, stats)
  • Pagination support
  • Processing status
  • All search operations
  • Unified search API
  • Timeline context
  • Semantic shortcuts
  • User settings
  • MCP toggle
  • Git branch switching

API Reference

Session Lifecycle (SessionRoutes)

Create/Get Session + Queue Observation

Privacy Check: Skips if the user prompt was entirely wrapped in <private> tags.
Tag Stripping: Removes <private> and <claude-mem-context> tags before storage.
Auto-Start: Ensures SDK agent generator is running to process the queue.

Queue Summary

Complete Session

Effect: Stops SDK agent, marks session complete, broadcasts status change.

Legacy Endpoints (Still Supported)

New integrations should use /api/sessions/* endpoints with claudeSessionId.

Data Retrieval (DataRoutes)

Get Paginated Data

Response Format

Get by ID

Get Database Stats

Response

Get Projects List

Response

Get Processing Status

Response

Search Operations (SearchRoutes)

string
Search query text (optional, omit for filter-only)
string
default:"all"
"observations" | "sessions" | "prompts"
string
default:"index"
"index" | "full"
number
default:20
Number of results
string
Filter by project name
string
Filter by observation type: discovery, decision, bugfix, feature, refactor
string
Filter by concepts (comma-separated)
string
Filter by file paths (comma-separated)
string
ISO timestamp (filter start)
string
ISO timestamp (filter end)
Response
Format Options:
  • index: Minimal fields for list display (id, title, preview)
  • full: Complete entity with all fields

Unified Timeline

string
required
Anchor point (observation ID, "S123" for session, or ISO timestamp)
number
default:10
Records before anchor
number
default:10
Records after anchor
string
Filter by project
Response

Semantic Shortcuts

Decisions

Changes

How It Works

Search by Concept

Search by File Path

Search by Type

Get Recent Context

Response

Context Preview (for Settings UI)

Returns plain text with ANSI colors for terminal display.

Context Injection (for Hooks)

Returns a pre-formatted context string ready for display or system prompt injection.

Settings & Configuration (SettingsRoutes)

Get/Update User Settings

MCP Server Status/Toggle

Git Branch Operations

Viewer & Real-Time Updates (ViewerRoutes)

Health Check

Response

Viewer UI

Returns the HTML shell for the React viewer app.

SSE Stream

Server-Sent Events streamEvent Types:
  • processing_status: { type, isProcessing, queueDepth }
  • session_started: { type, sessionDbId, project }
  • observation_queued: { type, sessionDbId }
  • summarize_queued: { type }
  • observation_created: { type, observation }
  • summary_created: { type, summary }
  • new_prompt: { type, id, claude_session_id, project, prompt_number, prompt_text, created_at_epoch }

Data Models

Active Session (In-Memory)

Database Entities

Search Results

Timeline Item

Integration Patterns

Mapping Claude Code Hooks to Worker API

1

SessionStart Hook

Not needed for the new API — sessions are auto-created on the first observation.
2

UserPromptSubmit Hook

No API call needed — the user prompt is captured by the first observation in the prompt.
3

PostToolUse Hook

4

Summary Hook

5

SessionEnd Hook

VSCode Extension Integration

Language Model Tool Registration

Chat Participant Implementation

package.json (VSCode Extension)

Error Handling & Resilience

Connection Failures

Retry Logic with Exponential Backoff

Worker Health Check

Privacy Tag Handling

The worker automatically strips privacy tags before storage:
  • <private>content</private> — User-level privacy control
  • <claude-mem-context>content</claude-mem-context> — System-level tag (prevents recursive storage)
Privacy Check: Observations/summaries are skipped if the entire user prompt was wrapped in <private> tags.

Custom Error Classes

SSE Stream Error Handling

Development Workflow

Local Testing Loop

1

Terminal 1: Watch build

2

Terminal 2: Check worker status

3

Terminal 3: Test API manually

4

VSCode: Launch extension host

Press F5 to launch the extension host.

Complete WorkerClient Implementation

Testing Strategy

Manual Testing Checklist

  • Worker starts successfully (npm run worker:status)
  • Health endpoint responds (curl http://localhost:37777/api/health)
  • SSE stream connects (curl http://localhost:37777/stream)
  • Queue observation creates session
  • Observation appears in database
  • Privacy tags are stripped
  • Private prompts are skipped
  • Queue summary creates summary
  • Complete session stops processing
  • Search observations by query
  • Search sessions by query
  • Search prompts by query
  • Get recent context for project
  • Get timeline around observation
  • Semantic shortcuts (decisions, changes, how-it-works)
  • SSE broadcasts processing status
  • SSE broadcasts new observations
  • SSE broadcasts new summaries
  • SSE broadcasts new prompts
  • Graceful degradation when worker unavailable
  • Timeout handling for slow requests
  • Retry logic for transient failures

Critical Implementation Notes

sessionDbId vs claudeSessionId

Use claudeSessionId (string) for new API endpoints, not sessionDbId (number).
  • sessionDbId — Numeric database ID (legacy endpoints only)
  • claudeSessionId — String identifier from the Claude platform (new endpoints)

JSON String Fields

Fields like facts, concepts, and files_touched are stored as JSON strings and require parsing:

Timestamps

All created_at_epoch fields are in milliseconds, not seconds:

Asynchronous Processing

Workers process observations and summaries asynchronously. Results appear in the database 1–2 seconds after queuing. Use SSE events for real-time notifications.

Privacy Tags

Always wrap sensitive content in <private> tags to prevent storage:

Additional Resources

Documentation

Complete claude-mem documentation

GitHub

Source code and issue tracker

Worker Service

Worker architecture details

Database Schema

Database structure and queries