Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

wolverin0/claude-memory-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

1 Commit

Repository files navigation

Claude Memory System (CMS)

Unified context-gathering and learning system for Claude Code. Merges the best parts of cc-dejavu, homunculus, claude-mem, and serena into a single SQLite-based tool with frecency ranking and instinct learning.

Features

  • Session Sync - Indexes your Claude Code session history (JSONL files)
  • Command Extraction - Every bash command with description, output, and working directory
  • Pattern Detection - Automatically creates "instincts" (learned behaviors) from Claude's thinking
  • Frecency Search - Full-text search with BM25 ranking + frequency x recency scoring
  • Context Injection - Hooks for Claude Code to inject relevant context into prompts
  • Telemetry - Track context hit rates and latency percentiles
  • Evidence-Based Validation - External signals (tests, builds, commits) validate patterns
  • Durability - WAL mode, snapshots, and integrity checks

Quick Start

# Navigate to the project
cd ~/.claude/claude-memory-system
# Install dependencies (via WSL on Windows)
wsl -e bash -lc "cd ~/.claude/claude-memory-system && bun install"
# Sync your Claude Code sessions
wsl -e bash -lc "cd ~/.claude/claude-memory-system && bun run src/cli.ts sync"
# View status
wsl -e bash -lc "cd ~/.claude/claude-memory-system && bun run src/cli.ts status"
# Search for commands
wsl -e bash -lc "cd ~/.claude/claude-memory-system && bun run src/cli.ts search 'docker'"

Commands

Command Description
sync Sync Claude Code session files to database
sync --force Full resync (ignore previous progress)
search <query> Search commands, observations, instincts
search <query> -t command Search only commands
search <query> -t instinct Search only instincts
status Show database statistics and telemetry
instincts List instinct domains
instincts -d <domain> List instincts for a specific domain
decay --days N Decay instincts unused for N days (default: 30)
prune Remove weak instincts (confidence <15%, never applied)
context "prompt" Generate context for a prompt (test hooks)
telemetry [--hours N] Show context retrieval telemetry (default: 24h)
snapshot Create database backup
snapshot list List existing snapshots
integrity Run SQLite integrity check

Command Options

-h, --help Show help message
-f, --force Force full resync (ignore byte offsets)
-t, --type Filter by type: command, observation, instinct, all
-p, --project Filter by project path
-n, --limit Maximum results (default: 20)
-d, --domain Filter instincts by domain
-j, --json Output as JSON
--days Days for decay threshold (default: 30)
--hours Hours for telemetry window (default: 24)

What Gets Extracted

Commands

Every bash command Claude ran, with:

  • The command itself
  • Description (what Claude said it does)
  • Working directory
  • Output (stdout/stderr)
  • Timestamp
  • Frequency count

Instincts

Patterns detected from Claude's thinking blocks:

Domain Examples
deployment docker cp, volume mounts, scp patterns
known_issue bugs, workarounds
reminder important notes, critical warnings
architecture structure, design patterns
best_practice always/never do X
prerequisite need X before Y
error_fix solution patterns
code_style naming, formatting
testing test requirements
git commit, branch, merge patterns

Telemetry

Context retrieval performance metrics:

  • Hit rate (context found vs missed)
  • Latency percentiles (P50, P90, P99)
  • Timeout tracking (>100ms)

Architecture

~/.claude/claude-memory-system/
├── src/
│ ├── cli.ts # CLI entry point
│ ├── db/
│ │ ├── schema.ts # Database tables and types
│ │ ├── connection.ts # SQLite connection + durability
│ │ ├── frecency.ts # Frecency ranking algorithm
│ │ └── telemetry.ts # Telemetry recording
│ ├── sync/
│ │ └── sync.ts # Session file syncing
│ ├── search/
│ │ └── search.ts # FTS5 search with BM25
│ ├── patterns/
│ │ └── detector.ts # Pattern detection from thinking
│ ├── evolution/
│ │ └── reinforcement.ts # Decay and pruning
│ └── hooks/
│ └── context.ts # Claude Code hook handlers
├── package.json
└── tsconfig.json
~/.claude-memory-system/
├── memory.db # SQLite database (auto-created)
└── memory-snapshot-*.db # Backup snapshots

Database Schema

Core Tables

  • sessions - Claude Code session metadata
  • commands - Extracted bash commands with FTS5
  • observations - Thinking block extracts with FTS5
  • instincts - Learned patterns with FTS5
  • indexed_files - Sync progress tracking
  • summaries - Session summaries

Evidence & Telemetry (from debate recommendations)

  • pattern_evidence - External validation signals (test_pass, build_ok, user_commit)
  • quarantined_patterns - Provisional patterns awaiting validation
  • telemetry - Context retrieval metrics (hits, misses, latency)

Integration with Claude Code

Add to ~/.claude/settings.json:

{
 "hooks": {
 "SessionStart": [
 {
 "command": "wsl -e bash -lc 'cd ~/.claude/claude-memory-system && bun run src/hooks/hook.ts'",
 "type": "script"
 }
 ],
 "UserPromptSubmit": [
 {
 "command": "wsl -e bash -lc 'cd ~/.claude/claude-memory-system && bun run src/hooks/hook.ts'",
 "type": "script"
 }
 ]
 }
}

This injects relevant context (commands and instincts) into your prompts automatically with a 100ms soft-block and async fallback.

Example Usage

Find deployment commands

bun run src/cli.ts search "docker cp" -t command

Find learned patterns about deployment

bun run src/cli.ts instincts -d deployment

Get context for a task

bun run src/cli.ts context "deploy the whatsapp bot"

Check telemetry

bun run src/cli.ts telemetry --hours 48

Create a backup

bun run src/cli.ts snapshot
bun run src/cli.ts snapshot list

Verify database health

bun run src/cli.ts integrity

Design Decisions

This architecture was validated through a 6-round debate between Gemini, Codex, and Claude. Key consensus points:

  1. SQLite + FTS5 - Right choice for single-user, low-write workload
  2. Unified Approach - Merging 4 tools reduces complexity vs maintaining separate systems
  3. Frecency Ranking - Frequency x recency is good but needs evidence-based validation
  4. 100ms Soft-Block - Context injection must not block user prompts
  5. Evidence Schema - External signals (tests, commits) validate patterns
  6. WAL + Snapshots - Durability without complexity of replication

See ARCHITECTURE.md for the full debate synthesis.

Data Location

  • Database: ~/.claude-memory-system/memory.db
  • Snapshots: ~/.claude-memory-system/memory-snapshot-*.db
  • Source: ~/.claude/projects/*/ (Claude Code sessions)

Requirements

  • Bun runtime (via WSL on Windows)
  • Claude Code with session logging enabled

License

MIT

About

Unified context-gathering and learning system for Claude Code with frecency ranking and instinct learning

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors

AltStyle によって変換されたページ (->オリジナル) /