Context-rot-resistant memory MCP server for Claude Code. Gives Claude persistent memory that survives across sessions, with automatic staleness detection when source code changes.
- Persistent Storage - Facts survive across sessions in SQLite with FTS5 full-text search
- Source Tracking - Link facts to source files (
file:line); detect when code changes invalidate them
- Smart Retrieval - Time-weighted search ranks recent, high-confidence facts higher
- Project Isolation - Facts auto-scoped to git repository; cross-project queries supported
- Contradiction Detection - Automatic warnings when new facts conflict with existing ones
- Session Tracking - Know what was learned in the current conversation
- Fact Versioning - Track history of changes to facts over time
- Topic Extraction - Auto-extract topics from content using hashtags and keywords
- Confidence Decay - Unused facts lose confidence over time
- Confidence Boost - Frequently accessed facts gain confidence (+2% per access)
- Auto-Maintenance - Light decay runs on server startup
- Pruning - Remove or archive old, low-confidence facts
- Consolidation - Find and merge similar/duplicate facts
- Fact Linking - Connect facts with typed relations (depends_on, contradicts, elaborates, etc.)
- Supersedes - Track when facts replace older versions
- Category Summaries - View facts grouped by category
Context Memory uses a daemon architecture for concurrent session support. Multiple Claude Code sessions can safely share the same memory database.
ββββββββββββββββββββ ββββββββββββββββββββ ββββββββββββββββββββ
β Claude Code #1 β β Claude Code #2 β β Claude Code #3 β
β β β β β β
β MCP (stdio) β β MCP (stdio) β β MCP (stdio) β
ββββββββββ¬ββββββββββ ββββββββββ¬ββββββββββ ββββββββββ¬ββββββββββ
β β β
βΌ βΌ βΌ
ββββββββββββββββββββ ββββββββββββββββββββ ββββββββββββββββββββ
β Client Process β β Client Process β β Client Process β
β (stdio bridge) β β (stdio bridge) β β (stdio bridge) β
ββββββββββ¬ββββββββββ ββββββββββ¬ββββββββββ ββββββββββ¬ββββββββββ
β β β
ββββββββββββββββββββββββΌβββββββββββββββββββββββ
β
Unix Socket β (~/.claude/context-memory/daemon.sock)
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Daemon Process β
β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β MCP Server β β MCP Server β β MCP Server β β
β β (session 1) β β (session 2) β β (session 3) β β
β ββββββββ¬βββββββ ββββββββ¬βββββββ ββββββββ¬βββββββ β
β βββββββββββββββββΌββββββββββββββββ β
β βΌ β
β βββββββββββββββββββββββ β
β β Shared Storage β β
β β (Connection Pool) β β
β ββββββββββββ¬βββββββββββ β
βββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββ
β
βΌ
~/.claude/context-memory/memory.db
How it works:
- Client mode (default): Spawned by Claude Code, bridges stdio β daemon socket
- Daemon mode (
--daemon): Long-running process accepting concurrent connections
- Auto-start: Client auto-starts daemon if not running
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Context Memory Server β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Tool Router (rmcp) β β
β β β β
β β remember recall forget verify link decay prune merge ... β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β βΌ β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Tool Handler β β
β β β β
β β β’ Input validation β’ Contradiction detection β β
β β β’ Topic extraction β’ Session ID injection β β
β β β’ Source hash computation β’ Confidence management β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β βΌ β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Storage Layer β β
β β β β
β β βββββββββββββββ βββββββββββββββ βββββββββββββββ ββββββββββββββ β β
β β β facts β β relations β βfact_history β β facts_fts β β β
β β β β β β β β β (FTS5) β β β
β β β β’ content β β β’ from_id β β β’ version β β β β β
β β β β’ source β β β’ to_id β β β’ content β β Full-text β β β
β β β β’ confidenceβ β β’ type β β β’ changed_atβ β search β β β
β β β β’ topics β β β’ metadata β β β β index β β β
β β β β’ session_idβ β β β β β β β β
β β βββββββββββββββ βββββββββββββββ βββββββββββββββ ββββββββββββββ β β
β β β β
β β SQLite + WAL Mode β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β remember ββββββΆβ Validate Input ββββββΆβ Extract Topics β
β (new fact) β β Check Length β β from Content β
βββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β
ββββββββββββββββββββ βΌ
β Check for ββββββββββββββββββββββββββ
β Contradictions β β Compute Source β
β (topic overlap) β β Hash (SHA256) β
ββββββββββββββββββββ βββββββββββββββββββ
β
βΌ
βββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Return ID βββββββ Store in SQLite βββββββ Add Session ID β
β + Warnings β β + FTS5 Index β β + Project Path β
βββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
βββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β recall ββββββΆβ Sanitize Query ββββββΆβ Build SQL with β
β (search) β β (FTS5 injection) β β Filters β
βββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β
ββββββββββββββββββββ βΌ
β Boost Confidence ββββββββββββββββββββββββββ
β (+2% per access) β β Time-Weighted β
ββββββββββββββββββββ β Scoring β
β βββββββββββββββββββ
βΌ
ββββββββββββββββββββ
β Return Ranked β
β Facts β
ββββββββββββββββββββ
Fact
βββ id (UUID)
βββ content (the fact itself)
βββ project_path (git root - for project isolation)
βββ session_id (conversation tracking)
βββ source (file:line reference)
βββ source_content_hash (SHA256 for staleness)
βββ confidence (0.0-1.0)
βββ importance (critical/high/normal/low)
βββ certainty (definite/likely/uncertain/speculative)
βββ category (architecture/decision/pattern/bug/todo/...)
βββ scope (global/project/branch/task)
βββ topics[] (tags)
βββ evidence[] (supporting observations)
βββ access_count
βββ last_accessed
βββ stale (boolean)
βββ archived (boolean)
Fact History
βββ fact_id
βββ version
βββ content (snapshot)
βββ confidence (snapshot)
βββ changed_at
βββ change_reason
Relations
βββ from_id β to_id
βββ type (depends_on/contradicts/elaborates/related_to/part_of/supersedes)
βββ metadata
- Rust 1.70+ (for building)
- Claude Code CLI
# Clone and build
git clone https://github.com/praneethpuligundla/context-memory
cd context-memory
cargo build --release
# Add to Claude Code MCP config (~/.claude/.mcp.json)
{
"mcpServers": {
"context-memory": {
"command": "/absolute/path/to/context-memory/target/release/context-memory",
"args": []
}
}
}
# Restart Claude Code
> What memory tools do you have?
Claude should list: remember, recall, forget, verify, decay, prune, etc.
| Tool |
Description |
Key Parameters |
remember |
Store a fact |
content, source?, topics?, category?, importance? |
recall |
Search facts |
query, all_projects?, session_id?, topics?, category?, min_confidence?, limit? |
forget |
Delete a fact |
fact_id |
forget_observation |
Remove evidence |
fact_id, observation |
| Tool |
Description |
Key Parameters |
verify |
Check if source changed |
fact_id |
get_stale |
List stale facts |
threshold_hours? |
refresh_all |
Batch verify all |
- |
| Tool |
Description |
Key Parameters |
link |
Connect facts |
fact_a, fact_b, relation_type, metadata? |
unlink |
Remove connection |
fact_a, fact_b, relation_type |
get_related |
Find connected facts |
fact_id |
find_contradictions |
Detect conflicts |
- |
| Tool |
Description |
Key Parameters |
get_session_facts |
Facts from current/specific session |
session_id?, limit? |
get_fact_history |
Version history of a fact |
fact_id |
| Tool |
Description |
Key Parameters |
list_topics |
List all topics |
- |
summarize |
Facts on a topic |
topic, limit? |
get_category_summary |
Facts grouped by category |
category?, limit_per_category? |
stats |
Memory statistics |
- |
| Tool |
Description |
Key Parameters |
decay |
Reduce old confidence |
threshold_days? (30), decay_factor? (0.9) |
prune |
Remove unused facts |
days_unused? (90), min_confidence? (0.5), archive? (true) |
consolidate |
Find similar facts |
similarity_threshold? (0.5) |
merge_facts |
Combine two facts |
fact_a, fact_b, merged_content? |
archive |
Soft-delete |
fact_id |
unarchive |
Restore archived |
fact_id |
get_archived |
List archived |
limit? |
score = confidence Γ importance_weight Γ time_decay
where:
importance_weight = { critical: 4, high: 2, normal: 1, low: 0.5 }
time_decay = 1 / (1 + days_since_access / 30)
When a fact references a source file (e.g., src/auth.rs:42):
- Computes SHA256 hash of file content on store
- On
verify(), recomputes hash and compares
- Marks fact as
stale: true if changed
When storing new facts:
- Finds existing facts with >50% topic overlap (Jaccard similarity)
- Analyzes content for negation words (
not, never, don't, etc.)
- Checks for opposite value pairs (
true/false, enabled/disabled, etc.)
- Returns warnings but still stores the fact
- Auto-creates
contradicts relation for high-confidence conflicts
| Variable |
Default |
Description |
CONTEXT_MEMORY_DECAY_DAYS |
7 |
Days of inactivity before decay |
CONTEXT_MEMORY_DECAY_FACTOR |
0.95 |
Decay multiplier (0.95 = 5% decay) |
CONTEXT_MEMORY_SKIP_MAINTENANCE |
0 |
Set to "1" to skip startup maintenance |
| Path |
Description |
~/.claude/context-memory/memory.db |
SQLite database |
~/.claude/context-memory/daemon.sock |
Unix socket for clientβdaemon IPC |
~/.claude/context-memory/daemon.pid |
PID file for daemon process |
context-memory # Run in client mode (default, used by Claude Code)
context-memory --daemon # Run as daemon (auto-started by client if needed)
- Path Traversal Prevention - Source paths are canonicalized
- FTS5 Query Sanitization - Prevents query injection
- Input Validation - Length limits on all text fields
- SQLite Security - foreign_keys, secure_delete, WAL mode enabled
cargo test # Run tests
cargo build # Build debug
cargo build --release # Build release
RUST_LOG=debug ./target/debug/context-memory # Run with logging
MIT