Cross-Session Memory (CSM)
A continuity runtime for AI coding assistants. Not just memory — a full pipeline that turns raw events into durable beliefs, with safety gates at every stage.
Backed by PostgreSQL + pgvector (default) or SQLite (lightweight alternative). 25 tables. 27 runtime tools. 728 tests.
Large language models are exceptionally capable, but every session begins with the same limitation: their working memory is temporary.
As projects grow, conversations become longer, tools generate thousands of lines of output, and important decisions disappear behind an ever-expanding context window.
CSM addresses this by separating long-term continuity from the model's limited working context.
Instead of treating every conversation as isolated, the engine continuously builds a structured knowledge base of your project, allowing AI systems to maintain continuity across sessions, conversations, and development cycles.
CSM gives an AI assistant long-term continuity. Without it, every session starts from zero. With it, the assistant remembers decisions, learns from mistakes, tracks its own capabilities, and maintains a living model of what it knows and doesn't know.
The key insight: memory alone isn't continuity. CSM is a pipeline — raw events flow through compaction, experience packets, candidate scanning, belief promotion, and advisory injection. Each stage has safety gates. Nothing gets promoted to durable memory without passing confidence thresholds, dedup checks, and contradiction detection.
Important information survives beyond a single conversation. The engine stores meaningful knowledge instead of forcing the model to relearn the same information every session.
Only relevant memories are brought back into context. Rather than injecting an entire history, CSM performs semantic retrieval to provide only the information needed for the current task.
Long conversations become efficient. Instead of keeping every tool call and every message forever, the engine intelligently compresses historical context into concise summaries while preserving the important information.
Every significant action can be recorded as structured knowledge. The system maintains an evolving record of work completed, architectural decisions, discoveries, failures, and successes.
Mistakes become permanent improvements. When an issue is solved once, the lesson can be preserved so future sessions avoid repeating the same problem.
The engine builds an understanding of your project over time. Architecture decisions, repository knowledge, workflows, documentation, and development history become searchable knowledge instead of disappearing into old conversations.
Major milestones can be saved and restored. Instead of relying on enormous conversation histories, AI systems can return to meaningful checkpoints with the necessary context already assembled.
The engine monitors context usage before it becomes a problem. As conversations grow, CSM manages information intelligently to help keep working context focused and efficient.
raw events
→ work journal (tool calls, decisions, errors)
→ compaction (token-budgeted compression, 90.8% total reduction)
→ experience packets (structured observations with internal state)
→ candidate scanning (pattern detection, belief extraction)
→ belief promotion (confidence-gated, dedup-checked)
→ durable memories (provenance-tracked, auditable)
→ advisory living state (context brief injection)
Each stage is optional. The pipeline degrades gracefully — if you only use memory save/search, everything downstream is inert.
Every tool call, decision, and session boundary is captured in real time. The journal is the raw material for everything downstream.
Context compression replaces raw tool output with distilled references. Status-tracked: compressed, skipped_under_budget, failed. 2B+ tokens saved globally across 10K+ compactions.
Structured observations derived from tool executions, errors, milestones, and session events. Each packet carries internal state (frustration, energy, stance, urgency) derived from 10 pure functions.
The belief promotion scanner reads experience packets, groups by pattern fingerprints, and maps to candidate types: belief, preference, worldview, drift warning, opinion. Confidence formula with contradiction penalty.
Conservative promotion engine. Only high-confidence, well-evidenced candidates become durable memories. Gates: min confidence (0.7), min reinforcement (3), min evidence refs (2), dedup, contradiction check. Provenance metadata on every promoted memory.
The living state advisor assembles an advisory block for the context brief. Shows recent experience, candidate deltas, self-model state, and belief knowledge. Labeled "preview, not durable truth" — never imperative, never absolutist.
Every stage has guards:
- Preview vs durable truth — Advisory blocks are labeled as previews. No behavior changes until explicitly enabled.
- Dry-run first — All maintenance tools default to dry-run. Nothing mutates without explicit action.
- Provenance tracking — Every promoted memory carries source refs, evidence sessions, confidence scores, and promotion timestamps.
- Threshold profiles — Production defaults (conf=0.7, rein=3, evid=2) vs relaxed mode (conf=0.3, rein=1, evid=1). Relaxed mode requires explicit flag.
- Dedup before insert — Exact content dedup prevents duplicate memories. Partial unique index on candidate queue.
- Contradiction detection — Candidates with contradicted_count > 0 are flagged
needs_review, not auto-promoted. - Budget trimming — Advisory block respects token budget. Preserves warnings longest: beliefs → capabilities → signals dropped first.
| Tool | Description |
|---|---|
csm_memory_save |
Save information to cross-session memory |
csm_memory_search |
Semantic search across memories |
csm_memory_list |
List memories with filters |
csm_memory_delete |
Delete a memory by ID |
csm_memory_context |
Get current session context brief |
csm_memory_lesson |
Save a lesson learned from mistakes |
csm_memory_transcript |
Get conversation transcript |
csm_memory_distill |
Distill tool-call activity into summaries |
csm_memory_distilled_view |
View distilled summaries |
csm_memory_compact |
Report on compaction savings |
| Tool | Description |
|---|---|
csm_memory_candidate_generate |
Generate maintenance candidates (advisory, dry-run) |
csm_memory_candidate_report |
Show candidate counts by type/status |
csm_memory_backfill_embeddings |
Repair missing embeddings |
csm_memory_dedup_detect |
Find duplicate memory clusters |
csm_memory_merge |
Merge exact content duplicates (dry-run first) |
csm_memory_archive_candidate_report |
Archive-candidate governance report |
| Tool | Description |
|---|---|
csm_memory_packets |
List recent experience packets with internal state |
| Tool | Description |
|---|---|
csm_belief_scan |
Scan packets for recurring patterns |
csm_belief_scan_report |
Show belief candidate counts |
csm_belief_promote |
Promote candidates to durable memories |
csm_belief_knowledge |
View consolidated belief knowledge |
csm_memory_governance_report |
Governance status with invariant checks |
| Tool | Description |
|---|---|
csm_self_model |
View capability confidence scores and drift warnings |
| Tool | Description |
|---|---|
csm_living_state_preview |
Preview advisory pipeline output |
csm_living_state_debug |
Diagnose advisory block assembly |
| Tool | Description |
|---|---|
csm_runtime_status |
Plugin status, DB connectivity, tool registry |
csm_compaction_audit |
Audit compaction telemetry for correctness |
25 tables across 7 schema subsystems:
distilled_summaries— Compressed tool-call activity with dedup indexcompaction_metrics— Per-compaction stats with status tracking (compressed | skipped_under_budget | failed)memory_candidates— Reviewable memory candidates from extractorproject_scopes— Project isolation boundaries
memories— The main memory store. 12 types: conversation, workspace, repo, preference, lesson, episodic, procedural, concept, code, config, error, self_continuitymemory_chunks— Chunked embeddings for long memoriesmemory_merges— Audit trail for dedup merges
sessions— OpenCode session recordsmemory_events— Event bus for memory operationssession_contexts— Cached context briefs
memory_candidate_queue— Unified queue for 10 candidate types (5 maintenance + 5 belief). Partial unique indexes for dedup.
experience_packets— Structured observations with internal statebelief_knowledge_store— Consolidated preferences, opinions, worldviewsself_model_capabilities— Per-capability confidence scores with evidence refsself_continuity_records— Cross-session identity tracking
checkpoints— Durable session summaries with raw capturescheckpoint_raw_captures— Recovery store for checkpoint contentcontext_cache— Session-scoped content for on-demand fetchcontext_compilation_log— Per-call compilation statscontext_rollover— Cumulative token trackergoals— User-declared session objectivesagent_work_journal— Real-time tool call capture
cross_session_causal_links— Causal edges between sessions (direct | inferred | gap)memory_recall_events— Hashed recall telemetry (no raw queries)
Key performance indexes: HNSW on memory_chunks (vector similarity), GIN on memories (tags, search_vector), partial unique on candidate queue (dedup), partial unique on distilled_summaries (dedup), active checkpoint lookup.
| Metric | Value |
|---|---|
| Test suite | 728/728 passing |
| Runtime tools | 27 (csm_ namespace) |
| Database tables | 25 |
| Memory types | 12 |
| Candidate types | 10 (5 maintenance + 5 belief) |
| Global tokens saved | 2.02B+ |
| Compaction reduction | 90.8% total weighted, 81.9% per-compaction average |
| Live memories | 46,000+ |
| Embeddings | 7,500+ |
| Lint baseline | 102 warnings (max-warnings=102) |
npm install
npm run build
npm run verify| Variable | Default | Description |
|---|---|---|
CSM_DATABASE_PROVIDER |
postgres |
postgres or sqlite |
CSM_SQLITE_PATH |
./csm.db |
SQLite file path |
CSM_EMBEDDING_PROVIDER |
ollama |
ollama or openai |
CSM_BELIEF_PROMOTION_ENABLED |
false |
Enable live belief promotion |
CSM_BELIEF_PROMOTION_RELAXED |
false |
Relaxed thresholds (dev only) |
CSM_LIVING_STATE_INJECT_ADVISORY |
false |
Inject advisory block into context |
$env:CSM_DATABASE_PROVIDER = "sqlite"
$env:CSM_SQLITE_PATH = "./csm.db"
npm run verifyDegraded: no vector ANN, no embedding index, text search fallback. All CRUD works. 26 contract tests pass on both backends.
Import ./codex-bridge to expose the memory harness to Codex-facing code. 49 bridge tools including memory CRUD, context compilation, checkpoints, governance, and goal tracking.
Using CSM allows AI systems to:
- Remember important information across sessions
- Dramatically reduce unnecessary token usage
- Maintain long-running software projects
- Preserve architectural decisions
- Reduce repeated explanations
- Improve consistency between sessions
- Retrieve relevant knowledge in seconds
- Scale to projects that would otherwise exceed model context limits
ClaudeX is the planned conversational interface for CSM's database layer. Instead of pgAdmin or DBeaver, you chat with your data:
- Lens system — Personal, Work, Code, Research, Creative contexts
- Memory recall — Surfaces relevant memories based on conversation context
- Advisory injection — Living state block shows what the system knows/doesn't know
- Provenance transparency — Every memory shows its source, confidence, and evidence
ClaudeX already runs against CSM's Postgres backend with 39K+ memories. The lens blend system biases context toward the active domain. The next phase is building the database management layer — schema exploration, query assistance, migration planning — all through conversation.
- docs/ARCHITECTURE.md — Module flow and dependency map
- docs/PHASE3G_SQLITE_MVP.md — SQLite adapter documentation
- docs/PHASE4FA_LIVING_STATE_PREVIEW.md — Living state pipeline
- docs/PHASE4FC_STAGED_ENABLEMENT.md — Advisory block staging
- docs/PHASE4EB_BELIEF_KNOWLEDGE_CONTRACT.md — Belief knowledge contract
- docs/PHASE4B5_PACKET_CONTRACT.md — Experience packet vocabulary
CSM is built around a simple idea:
Intelligence is amplified by continuity.
Models are already excellent at reasoning. What they lack is persistent experience.
CSM provides the missing layer between temporary reasoning and long-term knowledge, allowing AI systems to build on previous work instead of constantly starting over.
CSM isn't another chatbot memory feature.
It is a persistence and continuity platform designed to give AI systems a durable understanding of the work they've already done, enabling longer-lived, more capable, and more efficient assistants.
- Pipeline over storage — CSM is a processing system, not a database wrapper. Every stage adds value.
- Safety by default — Dry-run first, preview labels, conservative thresholds. Nothing promotes without gates.
- Provenance required — Every memory traces back to source events. No orphaned knowledge.
- Graceful degradation — SQLite works. Vector search falls back to text. Advisory blocks are opt-in.
- No raw telemetry — Recall events store hashed queries only. No user text in audit trails.