Documentation Index
Fetch the complete documentation index at: https://docs.claude-mem.ai/llms.txt
Use this file to discover all available pages before exploring further.
Worker Service
The worker service is a long-running HTTP API built with Express.js and managed natively by Bun. It processes observations through the Claude Agent SDK separately from hook execution to prevent timeout issues.Overview
- Technology: Express.js HTTP server
- Runtime: Bun (auto-installed if missing)
- Process Manager: Native Bun process management via ProcessManager
- Port: Per-user default
37700 + (uid % 100)(override withCLAUDE_MEM_WORKER_PORT). The active port is stored in~/.claude-mem/settings.jsonand reported byGET /api/health. - Location:
src/services/worker-service.ts - Built Output:
plugin/scripts/worker-service.cjs - Model: Configurable via
CLAUDE_MEM_MODEL(default:claude-haiku-4-5-20251001)
REST API Endpoints
The worker service exposes 22 HTTP endpoints organized into six categories:Viewer & Health Endpoints
1. Viewer UI
- Real-time memory stream visualization
- Infinite scroll pagination
- Project filtering
- SSE-based live updates
- Theme toggle (light/dark mode) as of v5.1.2
2. Health Check
port value is the actual worker port for the current user — per-user default 37700 + (uid % 100), or whatever CLAUDE_MEM_WORKER_PORT is set to. The example above is illustrative; your value will differ.
3. Server-Sent Events Stream
observation-created: New observation addedsession-summary-created: New summary generateduser-prompt-created: New prompt recorded
Data Retrieval Endpoints
4. Get Prompts
project(optional): Filter by project namelimit(default: 20): Number of resultsoffset(default: 0): Pagination offset
5. Get Observations
project(optional): Filter by project namelimit(default: 20): Number of resultsoffset(default: 0): Pagination offset
6. Get Summaries
project(optional): Filter by project namelimit(default: 20): Number of resultsoffset(default: 0): Pagination offset
7. Get Observation by ID
id(required): Observation ID
8. Get Observations by IDs (Batch)
ids(required): Array of observation IDsorderBy(optional): Sort order -date_descordate_asc(default:date_desc)limit(optional): Maximum number of results to returnproject(optional): Filter by project name
400 Bad Request:{"error": "ids must be an array of numbers"}400 Bad Request:{"error": "All ids must be integers"}
get_observations MCP tool to efficiently retrieve multiple observations in a single request, avoiding the overhead of multiple individual requests.
9. Get Session by ID
id(required): Session ID
10. Get Prompt by ID
id(required): Prompt ID
12. Get Stats
13. Get Projects
Settings Endpoints
14. Get Settings
15. Save Settings
Queue Management Endpoints
16. Get Pending Queue Status
pending: Message queued, not yet processedprocessing: Message currently being processed by SDK agentprocessed: Message completed successfullyfailed: Message failed after max retry attempts (3 by default)
processing status for >5 minutes are considered stuck and included in stuckCount
Use Case: Check queue health after worker crashes or restarts to identify unprocessed observations
17. Trigger Manual Recovery
sessionLimit(optional): Maximum number of sessions to process (default: 10, max: 100)
totalPendingSessions: Total sessions with pending messages in databasesessionsStarted: Number of sessions we started processing this requestsessionsSkipped: Sessions already actively processing (not restarted)startedSessionIds: Database IDs of sessions started
- Processes up to
sessionLimitsessions with pending work - Skips sessions already actively processing (prevents duplicate agents)
- Starts non-blocking SDK agents for each session
- Returns immediately with status (processing continues in background)
bun scripts/check-pending-queue.ts) to maintain explicit control over reprocessing.
Session Management Endpoints
19. Initialize Session
20. Add Observation
21. Generate Summary
22. Session Status
23. Delete Session
Bun Process Management
Overview
The worker is managed by the nativeProcessManager class which handles:
- Process spawning with Bun runtime
- PID file tracking at
~/.claude-mem/worker.pid - Health checks with automatic retry
- Graceful shutdown with SIGTERM/SIGKILL fallback
Commands
Auto-Start Behavior
The worker service auto-starts when the SessionStart hook fires. Manual start is optional.Bun Requirement
Bun is required to run the worker service. If Bun is not installed,npx claude-mem install (and npx claude-mem repair) installs it globally during setup, with a visible clack spinner:
- Windows:
powershell -c "irm bun.sh/install.ps1 | iex" - macOS/Linux:
curl -fsSL https://bun.sh/install | bash
winget install Oven-sh.Bun(Windows)brew install oven-sh/bun/bun(macOS)
Claude Agent SDK Integration
The worker service routes observations to the Claude Agent SDK for AI-powered processing:Processing Flow
- Observation Queue: Observations accumulate in memory
- SDK Processing: Observations sent to Claude via Agent SDK
- XML Parsing: Responses parsed for structured data
- Database Storage: Processed observations stored in SQLite
SDK Components
- Prompts (
src/sdk/prompts.ts): Builds XML-structured prompts - Parser (
src/sdk/parser.ts): Parses Claude’s XML responses - Worker (
src/sdk/worker.ts): Main SDK agent loop
Model Configuration
Set the Claude model used for compression via environment variable or~/.claude-mem/settings.json:
claude-haiku-4-5-20251001- default, fast and cheap (best for compression)claude-sonnet-4-6- balanced quality and costclaude-opus-4-7- highest quality, most expensive
Port Allocation
The worker uses a per-user default port so different OS users on the same machine never collide:- Default:
37700 + (uid % 100)(set insrc/shared/SettingsDefaultsManager.ts) - Override: Set
CLAUDE_MEM_WORKER_PORT(env or~/.claude-mem/settings.json) - Discovery:
GET /api/healthreturns the active port;~/.claude-mem/settings.jsonstores the configured value
CLAUDE_MEM_WORKER_PORT and restart.
Data Storage
The worker service stores data in the user data directory:Error Handling
The worker implements graceful degradation:- Database Errors: Logged but don’t crash the service
- SDK Errors: Retried with exponential backoff
- Network Errors: Logged and skipped
- Invalid Input: Validated and rejected with error response
Performance
- Async Processing: Observations processed asynchronously
- In-Memory Queue: Fast observation accumulation
- Batch Processing: Multiple observations processed together
- Connection Pooling: SQLite connections reused

