Skip to main content

Database architecture

Claude-Mem uses SQLite 3 with the bun:sqlite native module for persistent storage. FTS5 virtual tables provide full-text search across observations, summaries, and user prompts.

Database location

The database runs in WAL (Write-Ahead Logging) mode for concurrent reads and writes.

Implementation

Primary: bun:sqlite (native SQLite module)
  • Used by SessionStore and SessionSearch
  • Synchronous API for better performance
  • WAL mode enabled: PRAGMA journal_mode = WAL
Database.ts using bun:sqlite is legacy code. The canonical implementation is SessionStore.ts and SessionSearch.ts.

Core tables

sdk_sessions

Tracks active and completed sessions.
Indexes:

observations

Individual tool executions with hierarchical AI-extracted structure.
Observation types: Indexes:

session_summaries

AI-generated session summaries. Multiple summaries can exist per session.
Indexes:

user_prompts

Raw user prompts with FTS5 search support (added in v4.2.0).
Indexes:

Legacy tables

The following tables exist for backward compatibility with v3.x installations and are no longer written to:
  • sessions — Legacy session tracking
  • memories — Legacy compressed memory chunks
  • overviews — Legacy session summaries
SQLite FTS5 virtual tables enable fast full-text search across observations, summaries, and user prompts.
FTS5 tables are maintained for backward compatibility but vector search via ChromaDB is now the primary search mechanism. FTS5 may be unavailable on some platforms (e.g., Bun on Windows). When unavailable, search falls back to ChromaDB and LIKE queries.

FTS5 virtual tables

observations_fts

session_summaries_fts

user_prompts_fts

Automatic synchronization

FTS5 tables stay synchronized with their source tables via SQL triggers:
Equivalent triggers exist for session_summaries_fts and user_prompts_fts.

FTS5 query syntax

FTS5 supports a rich query language:

Security

All FTS5 queries are escaped before processing to prevent injection attacks:
The FTS5 injection prevention has a test suite covering 332 attack patterns including special characters, SQL keywords, quote escaping, and boolean operators.

Database classes

SessionStore

CRUD operations for sessions, observations, summaries, and user prompts. Location: src/services/sqlite/SessionStore.ts
  • createSession() — Create a new SDK session record
  • getSession() — Retrieve session by ID
  • updateSession() — Update session fields (status, counters)
  • createObservation() — Store a processed observation
  • getObservations() — Retrieve observations with pagination and filters
  • createSummary() — Store an AI-generated session summary
  • getSummaries() — Retrieve summaries with pagination and filters
  • createUserPrompt() — Store a raw user prompt

SessionSearch

FTS5 full-text search with 8 specialized search methods. Location: src/services/sqlite/SessionSearch.ts

Migration history

Database schema is managed via src/services/sqlite/migrations.ts.

Data directory structure

Performance considerations

Indexes

All foreign keys and frequently queried columns have explicit indexes, avoiding full table scans.

FTS5

Full-text search is significantly faster than LIKE queries for text matching.

Triggers

Automatic FTS5 synchronization via triggers adds minimal overhead to write operations.

WAL mode

Write-Ahead Logging allows concurrent reads without blocking writes.