claude-mem-lite 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +18 -0
- package/.claude-plugin/plugin.json +19 -0
- package/.mcp.json +9 -0
- package/LICENSE +21 -0
- package/README.md +486 -0
- package/README.zh-CN.md +486 -0
- package/commands/mem.md +34 -0
- package/dispatch-feedback.mjs +139 -0
- package/dispatch-inject.mjs +147 -0
- package/dispatch.mjs +692 -0
- package/haiku-client.mjs +165 -0
- package/hook-context.mjs +176 -0
- package/hook-episode.mjs +222 -0
- package/hook-llm.mjs +358 -0
- package/hook-semaphore.mjs +84 -0
- package/hook-shared.mjs +174 -0
- package/hook.mjs +849 -0
- package/hooks/hooks.json +77 -0
- package/install.mjs +948 -0
- package/package.json +69 -0
- package/registry/preinstalled.json +279 -0
- package/registry-indexer.mjs +172 -0
- package/registry-retriever.mjs +372 -0
- package/registry-scanner.mjs +253 -0
- package/registry.mjs +350 -0
- package/resource-discovery.mjs +189 -0
- package/schema.mjs +267 -0
- package/scripts/post-tool-use.sh +60 -0
- package/scripts/setup.sh +83 -0
- package/server-internals.mjs +195 -0
- package/server.mjs +938 -0
- package/skill.md +35 -0
- package/tool-schemas.mjs +56 -0
- package/utils.mjs +594 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "sdsrss",
|
|
3
|
+
"owner": {
|
|
4
|
+
"name": "sdsrss"
|
|
5
|
+
},
|
|
6
|
+
"metadata": {
|
|
7
|
+
"description": "Plugins by sdsrss",
|
|
8
|
+
"homepage": "https://github.com/sdsrss/claude-mem-lite"
|
|
9
|
+
},
|
|
10
|
+
"plugins": [
|
|
11
|
+
{
|
|
12
|
+
"name": "claude-mem-lite",
|
|
13
|
+
"version": "2.0.0",
|
|
14
|
+
"source": ".",
|
|
15
|
+
"description": "Lightweight persistent memory system for Claude Code — FTS5 search, episode batching, error-triggered recall"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "claude-mem-lite",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Lightweight persistent memory system for Claude Code — FTS5 search, episode batching, error-triggered recall",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "sdsrss"
|
|
7
|
+
},
|
|
8
|
+
"repository": "https://github.com/sdsrss/claude-mem-lite",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"memory",
|
|
12
|
+
"context",
|
|
13
|
+
"persistence",
|
|
14
|
+
"hooks",
|
|
15
|
+
"mcp",
|
|
16
|
+
"sqlite",
|
|
17
|
+
"fts5"
|
|
18
|
+
]
|
|
19
|
+
}
|
package/.mcp.json
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-2026 sdsrss
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
[English](README.md) | [中文](README.zh-CN.md)
|
|
2
|
+
|
|
3
|
+
# claude-mem-lite
|
|
4
|
+
|
|
5
|
+
Lightweight persistent memory system for [Claude Code](https://docs.anthropic.com/en/docs/claude-code). Automatically captures coding observations, decisions, and bug fixes during sessions, then provides full-text search to recall them later.
|
|
6
|
+
|
|
7
|
+
Built as an [MCP server](https://modelcontextprotocol.io/) + Claude Code hooks. Zero external services, single SQLite database, minimal overhead.
|
|
8
|
+
|
|
9
|
+
## Why claude-mem-lite?
|
|
10
|
+
|
|
11
|
+
A ground-up redesign of [claude-mem](https://github.com/thedotmack/claude-mem), replacing its heavyweight architecture with a smarter, leaner approach.
|
|
12
|
+
|
|
13
|
+
### Architecture comparison
|
|
14
|
+
|
|
15
|
+
| | claude-mem (original) | claude-mem-lite |
|
|
16
|
+
|---|---|---|
|
|
17
|
+
| **LLM calls** | Every tool use triggers a Sonnet call | Only on episode flush (5-10 ops batched) |
|
|
18
|
+
| **LLM input** | Raw `tool_input` + `tool_output` JSON | Pre-processed action summaries |
|
|
19
|
+
| **Conversation** | Multi-turn, accumulates full history | Stateless single-turn extraction |
|
|
20
|
+
| **Noise filtering** | LLM decides via "WHEN TO SKIP" prompt | Deterministic code-level Tier 1 filter |
|
|
21
|
+
| **Runtime** | Long-running worker process (1.8MB .cjs) | On-demand spawn, exits immediately |
|
|
22
|
+
| **Dependencies** | Bun + Python/uv + Chroma vector DB | Node.js only (3 npm packages) |
|
|
23
|
+
| **Source size** | ~2.3MB compiled bundles | ~50KB readable source |
|
|
24
|
+
| **Data directory** | `~/.claude-mem/` | `~/.claude-mem-lite/` (hidden, auto-migrates) |
|
|
25
|
+
|
|
26
|
+
### Token & cost efficiency
|
|
27
|
+
|
|
28
|
+
For a typical 50-tool-call session:
|
|
29
|
+
|
|
30
|
+
| | claude-mem | claude-mem-lite | Ratio |
|
|
31
|
+
|---|---|---|---|
|
|
32
|
+
| LLM calls | ~50 (every tool use) | ~5-8 (per episode) | **7-10x fewer** |
|
|
33
|
+
| Tokens per call | 1,000-5,000 (raw JSON + history) | 200-500 (summaries only) | **5-10x smaller** |
|
|
34
|
+
| Total tokens | ~100K-250K | ~1K-4K | **50-100x less** |
|
|
35
|
+
| Model cost | Sonnet ($3/$15 per M) | Haiku ($0.25/$1.25 per M) | **12x cheaper** |
|
|
36
|
+
| Combined savings | | | **600x+ lower cost** |
|
|
37
|
+
|
|
38
|
+
### Quality comparison
|
|
39
|
+
|
|
40
|
+
| Dimension | Winner | Why |
|
|
41
|
+
|---|---|---|
|
|
42
|
+
| **Classification accuracy** | Tie | Both produce correct type/title/narrative |
|
|
43
|
+
| **Noise filtering** | **lite** | Code-level filtering is deterministic; LLM "WHEN TO SKIP" is unreliable |
|
|
44
|
+
| **Observation coherence** | **lite** | Episode batching groups related edits into one coherent observation |
|
|
45
|
+
| **Code-level detail** | original | Sees full diffs, but rarely useful for memory search |
|
|
46
|
+
| **Search recall** | Tie | Users search semantic concepts ("auth bug"), not code lines |
|
|
47
|
+
| **Hook latency** | **lite** | Async background workers; original blocks 2-5s per hook |
|
|
48
|
+
|
|
49
|
+
### Design philosophy
|
|
50
|
+
|
|
51
|
+
The original sends **everything to the LLM and hopes it filters well**. claude-mem-lite **filters first with code, then sends only what matters** to a smaller model. This is not a downgrade; it's a smarter architecture that produces equivalent search quality at a fraction of the cost.
|
|
52
|
+
|
|
53
|
+
## Features
|
|
54
|
+
|
|
55
|
+
- **Automatic capture** -- Hooks into Claude Code lifecycle (PostToolUse, PreToolUse, SessionStart, Stop, UserPromptSubmit) to record observations without manual effort
|
|
56
|
+
- **FTS5 search** -- BM25-ranked full-text search across observations, session summaries, and user prompts with importance weighting
|
|
57
|
+
- **Timeline browsing** -- Navigate observations chronologically with anchor-based context windows
|
|
58
|
+
- **Episode batching** -- Groups related file operations into coherent episodes before LLM encoding
|
|
59
|
+
- **Error-triggered recall** -- Automatically searches memory when Bash errors occur, surfacing relevant past fixes
|
|
60
|
+
- **Proactive file history** -- When editing a file, automatically shows relevant past observations for that file
|
|
61
|
+
- **Session summaries** -- LLM-generated summaries at session end (via background workers using `claude -p`)
|
|
62
|
+
- **Project-scoped context** -- Injects recent memory into `CLAUDE.md` and session startup for immediate context
|
|
63
|
+
- **Observation types** -- Categorized as `decision`, `bugfix`, `feature`, `refactor`, `discovery`, or `change`
|
|
64
|
+
- **Importance grading** -- LLM assigns 1-3 importance levels (routine / notable / critical) to each observation
|
|
65
|
+
- **Observation relations** -- Bidirectional links between related observations based on file overlap
|
|
66
|
+
- **User prompt capture** -- Records user prompts via UserPromptSubmit hook for intent tracking
|
|
67
|
+
- **Read file tracking** -- Tracks files read during sessions for richer episode context
|
|
68
|
+
- **Zero data loss** -- If LLM fails, observations are saved with degraded (inferred) metadata instead of being discarded
|
|
69
|
+
- **Two-tier dedup** -- Jaccard similarity (5-minute window) + MinHash signatures (7-day cross-session window) prevent duplicates
|
|
70
|
+
- **Synonym expansion** -- Abbreviations like `K8s`, `DB`, `auth` automatically expand to full forms in FTS5 search (48+ pairs)
|
|
71
|
+
- **Pseudo-relevance feedback (PRF)** -- Top results seed expansion queries for broader recall
|
|
72
|
+
- **Concept co-occurrence** -- Shared concepts across observations expand search to related topics
|
|
73
|
+
- **Context-aware re-ranking** -- Active file overlap boosts relevance (exact match + directory-level half-weight)
|
|
74
|
+
- **Superseded detection** -- Marks older observations as outdated when newer ones cover the same files with higher importance
|
|
75
|
+
- **Adaptive time windows** -- Session startup recall uses velocity-based time windows (high/medium/low activity tiers)
|
|
76
|
+
- **Token-budgeted context** -- Greedy knapsack algorithm selects session-start context within a 2,000-token budget, prioritizing by recency and importance
|
|
77
|
+
- **Observation compression** -- Old low-value observations can be compressed into weekly summaries to reduce noise
|
|
78
|
+
- **Secret scrubbing** -- Automatic redaction of API keys, tokens, PEM blocks, connection strings, and 15+ credential patterns
|
|
79
|
+
- **Atomic writes** -- All file writes (episodes, CLAUDE.md) use write-to-tmp + rename to prevent corruption on crash
|
|
80
|
+
- **Robust locking** -- PID-aware lock files with automatic stale/orphan cleanup (>30s timeout or dead PID)
|
|
81
|
+
- **Stale session cleanup** -- Sessions active for >24h are automatically marked as abandoned on next start
|
|
82
|
+
- **Intelligent dispatch** -- 3-tier progressive dispatch system automatically recommends the right skill or agent for the current task, triggered on SessionStart, UserPromptSubmit, and PreToolUse
|
|
83
|
+
- **Resource registry** -- Indexes installed skills and agents with FTS5 search, composite scoring, and invocation tracking
|
|
84
|
+
- **Unified resource discovery** -- Shared filesystem traversal layer (`resource-discovery.mjs`) used by both runtime scanner and offline indexer, supporting flat directories, plugin nesting, and loose `.md` files
|
|
85
|
+
- **Closed-loop feedback** -- Tracks whether recommendations were adopted and whether sessions succeeded, improving future dispatch quality
|
|
86
|
+
- **Bilingual intent recognition** -- Understands user intent in both English and Chinese (15+ EN + 12+ CN intent categories)
|
|
87
|
+
- **Domain synonym expansion** -- Dispatch queries expand to domain synonyms (e.g., "fix" → debug, bugfix, troubleshoot, diagnose, repair)
|
|
88
|
+
- **DB-persisted cooldown** -- 5-minute cross-session cooldown and per-session dedup prevent repeated recommendations
|
|
89
|
+
- **Dual LLM mode** -- Auto-detects `ANTHROPIC_API_KEY` for direct API calls; falls back to `claude -p` CLI when no key is available
|
|
90
|
+
- **Haiku circuit breaker** -- After 3 consecutive LLM failures, disables Haiku dispatch for 5 minutes to prevent cascading latency
|
|
91
|
+
- **Negation-aware intent** -- Handles complex prompts like "don't test, just fix the bug" — correctly excludes negated intents even in mixed English/Chinese input
|
|
92
|
+
- **Configurable LLM model** -- Switch between Haiku (fast/cheap) and Sonnet (deeper analysis) via `CLAUDE_MEM_MODEL` env var
|
|
93
|
+
- **DB auto-recovery** -- Detects and cleans corrupted WAL/SHM files on startup; periodic WAL checkpoints prevent unbounded growth
|
|
94
|
+
- **Schema auto-migration** -- Idempotent `ALTER TABLE` migrations run on every startup, safely adding new columns and indexes without data loss
|
|
95
|
+
- **Exploration bonus** -- New resources in the registry get a fair chance in composite ranking; zombie resources (high recommend, zero adopt) are penalized
|
|
96
|
+
- **LLM concurrency control** -- File-based semaphore limits background workers to 2 concurrent LLM calls, preventing resource contention
|
|
97
|
+
- **stdin overflow protection** -- Hook input truncated at 256KB with regex-based action salvage for oversized tool outputs
|
|
98
|
+
|
|
99
|
+
## Platform Support
|
|
100
|
+
|
|
101
|
+
| Platform | Status | Notes |
|
|
102
|
+
|----------|--------|-------|
|
|
103
|
+
| **Linux** | Supported | Primary development and testing platform |
|
|
104
|
+
| **macOS** | Supported | Fully compatible (Intel and Apple Silicon) |
|
|
105
|
+
| **Windows** | Not supported | Uses POSIX shell scripts (`post-tool-use.sh`, `setup.sh`) and Unix file locking; WSL2 may work but is untested |
|
|
106
|
+
|
|
107
|
+
## Requirements
|
|
108
|
+
|
|
109
|
+
- **Node.js** >= 18
|
|
110
|
+
- **Claude Code** CLI installed and configured (`claude` command available)
|
|
111
|
+
- **SQLite3** support (provided by `better-sqlite3`, compiled on install)
|
|
112
|
+
- **Platform**: Linux or macOS (see [Platform Support](#platform-support))
|
|
113
|
+
|
|
114
|
+
## Installation
|
|
115
|
+
|
|
116
|
+
### Method 1: Plugin Marketplace (recommended)
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
/plugin marketplace add sdsrss/claude-mem-lite
|
|
120
|
+
/plugin install claude-mem-lite
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
The plugin system handles everything: hooks, MCP server, and dependency installation (via Setup hook). Dependencies are installed automatically on first run.
|
|
124
|
+
|
|
125
|
+
### Method 2: npx (one-liner)
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
npx github:sdsrss/claude-mem-lite
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Source files are automatically copied to `~/.claude-mem-lite/` for persistence.
|
|
132
|
+
|
|
133
|
+
### Method 3: git clone
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
git clone https://github.com/sdsrss/claude-mem-lite.git
|
|
137
|
+
cd claude-mem-lite
|
|
138
|
+
node install.mjs install
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Source files stay in the cloned repo. Update via `git pull && node install.mjs install`.
|
|
142
|
+
|
|
143
|
+
### What happens during installation
|
|
144
|
+
|
|
145
|
+
1. **Install dependencies** -- `npm install --omit=dev` (compiles native `better-sqlite3`)
|
|
146
|
+
2. **Register MCP server** -- `mem` server with 7 tools (search, timeline, get, save, stats, delete, compress)
|
|
147
|
+
3. **Configure hooks** -- `PostToolUse`, `PreToolUse`, `SessionStart`, `Stop`, `UserPromptSubmit` lifecycle hooks
|
|
148
|
+
4. **Create data directory** -- `~/.claude-mem-lite/` (hidden) for database, runtime, and managed resource files
|
|
149
|
+
5. **Auto-migrate** -- If `~/.claude-mem/` (original claude-mem) or `~/claude-mem-lite/` (pre-v0.5 unhidden) exists, migrates database and runtime files to `~/.claude-mem-lite/`, preserving the original untouched
|
|
150
|
+
6. **Initialize database** -- SQLite with WAL mode, FTS5 indexes created on first server start
|
|
151
|
+
|
|
152
|
+
Restart Claude Code after installation to activate.
|
|
153
|
+
|
|
154
|
+
### Migration
|
|
155
|
+
|
|
156
|
+
All installation methods auto-detect and migrate from previous versions:
|
|
157
|
+
|
|
158
|
+
**From claude-mem (original `~/.claude-mem/`):**
|
|
159
|
+
- Copy `claude-mem.db` → `~/.claude-mem-lite/claude-mem-lite.db` (renamed)
|
|
160
|
+
- Copy the `runtime/` directory
|
|
161
|
+
- **Original `~/.claude-mem/` is preserved** (no deletion, no overwrite)
|
|
162
|
+
|
|
163
|
+
**From pre-v0.5 unhidden directory (`~/claude-mem-lite/`):**
|
|
164
|
+
- Entire directory is moved to `~/.claude-mem-lite/` (hidden)
|
|
165
|
+
|
|
166
|
+
**In-place rename:**
|
|
167
|
+
- Existing `claude-mem.db` in `~/.claude-mem-lite/` is automatically renamed to `claude-mem-lite.db`
|
|
168
|
+
|
|
169
|
+
Remove old directories manually after confirming:
|
|
170
|
+
```bash
|
|
171
|
+
rm -rf ~/.claude-mem/ # original claude-mem
|
|
172
|
+
rm -rf ~/claude-mem-lite/ # pre-v0.5 unhidden (if not auto-moved)
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Directory Structure
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
~/.claude-mem-lite/
|
|
179
|
+
claude-mem-lite.db # SQLite database — memory (WAL mode)
|
|
180
|
+
resource-registry.db # SQLite database — skill/agent registry
|
|
181
|
+
runtime/
|
|
182
|
+
session-<project> # Active session state
|
|
183
|
+
ep-<project>.json # Episode buffer
|
|
184
|
+
ep-flush-*.json # Flushed episodes awaiting processing
|
|
185
|
+
reads-<project>.txt # Read file paths (collected on flush)
|
|
186
|
+
managed/
|
|
187
|
+
skills/ # Standalone skills (flat layout)
|
|
188
|
+
agents/ # Agent plugins (nested: agents/*.md + skills/*/SKILL.md)
|
|
189
|
+
repos/ # Shallow-cloned source repos
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Usage
|
|
193
|
+
|
|
194
|
+
### MCP Tools (used automatically by Claude)
|
|
195
|
+
|
|
196
|
+
| Tool | Description |
|
|
197
|
+
|------|-------------|
|
|
198
|
+
| `mem_search` | FTS5 full-text search with BM25 ranking. Filters by type, project, date range, importance level. |
|
|
199
|
+
| `mem_timeline` | Browse observations chronologically around an anchor point. |
|
|
200
|
+
| `mem_get` | Retrieve full details for specific observation IDs (includes importance and related_ids). |
|
|
201
|
+
| `mem_save` | Manually save a memory/observation. |
|
|
202
|
+
| `mem_stats` | View statistics: counts, type distribution, top projects, daily activity. |
|
|
203
|
+
| `mem_delete` | Delete observations by ID with preview/confirm workflow. FTS5 cleanup is automatic. |
|
|
204
|
+
| `mem_compress` | Compress old low-value observations into weekly summaries to reduce noise. |
|
|
205
|
+
|
|
206
|
+
### Skill Commands (in Claude Code chat)
|
|
207
|
+
|
|
208
|
+
```
|
|
209
|
+
/mem search <query> # Full-text search across all memories
|
|
210
|
+
/mem recent [n] # Show recent N observations (default 10)
|
|
211
|
+
/mem save <text> # Save a manual memory/note
|
|
212
|
+
/mem stats # Show memory statistics
|
|
213
|
+
/mem timeline <query> # Browse timeline around a match
|
|
214
|
+
/mem <query> # Shorthand for search
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Efficient Search Workflow
|
|
218
|
+
|
|
219
|
+
```
|
|
220
|
+
1. mem_search(query="auth bug") -> compact ID index
|
|
221
|
+
2. mem_timeline(anchor=12345) -> surrounding context
|
|
222
|
+
3. mem_get(ids=[12345, 12346]) -> full details
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Database Schema
|
|
226
|
+
|
|
227
|
+
Four core tables with FTS5 virtual tables for search:
|
|
228
|
+
|
|
229
|
+
**observations** -- Individual coding observations (decisions, bugfixes, features, etc.)
|
|
230
|
+
```
|
|
231
|
+
id, memory_session_id, project, type, title, subtitle,
|
|
232
|
+
text, narrative, concepts, facts, files_read, files_modified,
|
|
233
|
+
importance, related_ids, created_at, created_at_epoch
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
**session_summaries** -- LLM-generated session summaries
|
|
237
|
+
```
|
|
238
|
+
id, memory_session_id, project, request, investigated,
|
|
239
|
+
learned, completed, next_steps, files_read, files_edited, notes
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
**sdk_sessions** -- Session tracking
|
|
243
|
+
```
|
|
244
|
+
id, content_session_id, memory_session_id, project,
|
|
245
|
+
started_at, completed_at, status, prompt_counter
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
**user_prompts** -- User prompts captured via UserPromptSubmit hook
|
|
249
|
+
```
|
|
250
|
+
id, content_session_id, prompt_text, prompt_number
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
FTS5 indexes: `observations_fts`, `session_summaries_fts`, `user_prompts_fts`
|
|
254
|
+
|
|
255
|
+
## How It Works
|
|
256
|
+
|
|
257
|
+
### Hook Pipeline
|
|
258
|
+
|
|
259
|
+
```
|
|
260
|
+
SessionStart
|
|
261
|
+
-> Generate session ID
|
|
262
|
+
-> Mark stale sessions (>24h active) as abandoned
|
|
263
|
+
-> Clean orphaned/stale lock files
|
|
264
|
+
-> Query recent observations (24h)
|
|
265
|
+
-> Inject context into CLAUDE.md + stdout
|
|
266
|
+
-> Dispatch: recommend skill/agent based on user prompt (Tier 0→1→2→3)
|
|
267
|
+
|
|
268
|
+
PostToolUse (every tool execution)
|
|
269
|
+
-> Bash pre-filter skips noise in ~5ms (Read paths tracked to reads file)
|
|
270
|
+
-> Detect Bash significance (errors, tests, builds, git, deploys)
|
|
271
|
+
-> Accumulate into episode buffer
|
|
272
|
+
-> Proactive file history: show past observations for edited files
|
|
273
|
+
-> Flush when: buffer full (10 entries) | 5min gap | context change
|
|
274
|
+
-> Collect Read file paths into episode on flush
|
|
275
|
+
-> Spawn LLM episode worker for significant episodes
|
|
276
|
+
-> Error-triggered recall: search memory for related past fixes
|
|
277
|
+
|
|
278
|
+
PreToolUse (before tool execution)
|
|
279
|
+
-> Dispatch: recommend skill/agent based on current action context (Tier 0→1→2)
|
|
280
|
+
|
|
281
|
+
UserPromptSubmit
|
|
282
|
+
-> Capture user prompt text to user_prompts table
|
|
283
|
+
-> Increment session prompt counter
|
|
284
|
+
-> Dispatch: recommend skill/agent based on user's actual prompt (Tier 0→1→2)
|
|
285
|
+
-> Primary dispatch point — user intent is clearest here
|
|
286
|
+
|
|
287
|
+
Stop
|
|
288
|
+
-> Flush final episode buffer
|
|
289
|
+
-> Collect dispatch feedback: adoption detection + outcome scoring
|
|
290
|
+
-> Mark session completed
|
|
291
|
+
-> Spawn LLM summary worker (poll-based wait)
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### Intelligent Dispatch
|
|
295
|
+
|
|
296
|
+
The dispatch system proactively recommends skills and agents during coding sessions via a 3-tier progressive architecture:
|
|
297
|
+
|
|
298
|
+
```
|
|
299
|
+
Tier 0: Fast Filter (<1ms)
|
|
300
|
+
-> Skip read-only tools (Read, Glob, Grep, LSP...)
|
|
301
|
+
-> Skip simple Bash queries (ls, cat, git status...)
|
|
302
|
+
-> Skip when Claude already chose a Skill or Task agent
|
|
303
|
+
-> Skip MCP-internal tools
|
|
304
|
+
|
|
305
|
+
Tier 1: Context Signal Extraction (<1ms)
|
|
306
|
+
-> Intent: extract from user prompt (test, fix, deploy, review...)
|
|
307
|
+
-> Tech stack: infer from recent file extensions (.ts → typescript)
|
|
308
|
+
-> Action: infer from tool name (Edit → edit, Bash+jest → test)
|
|
309
|
+
-> Error domain: classify errors (type-error, test-fail, build-fail...)
|
|
310
|
+
|
|
311
|
+
Tier 2: FTS5 Retrieval (<5ms)
|
|
312
|
+
-> Expand signals with domain synonyms (15+ EN, 12+ CN categories)
|
|
313
|
+
-> BM25-ranked search over resource registry
|
|
314
|
+
-> Composite scoring: BM25 (40%) + repo stars (15%) + success rate (15%) + adoption rate (10%)
|
|
315
|
+
|
|
316
|
+
Tier 3: Haiku Semantic Dispatch (~500ms, SessionStart only)
|
|
317
|
+
-> Activated when FTS5 confidence is low or top results are ambiguous
|
|
318
|
+
-> LLM generates semantic search query for refined retrieval
|
|
319
|
+
-> Disabled for PreToolUse (2s hook timeout insufficient)
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
**Dispatch triggers:**
|
|
323
|
+
|
|
324
|
+
| Hook | Budget | Tiers | Use case |
|
|
325
|
+
|------|--------|-------|----------|
|
|
326
|
+
| SessionStart | 10s | 0→1→2→3 | Analyze previous session's next_steps, suggest skill/agent upfront |
|
|
327
|
+
| UserPromptSubmit | 2s | 0→1→2 | Primary dispatch point — user's actual prompt has clearest intent |
|
|
328
|
+
| PreToolUse | 2s | 0→1→2 | React to current action context in real-time |
|
|
329
|
+
|
|
330
|
+
**Feedback loop (Stop hook):**
|
|
331
|
+
|
|
332
|
+
At session end, the system reviews all recommendations made during the session:
|
|
333
|
+
- **Adoption detection** -- Did Claude actually use the recommended skill (`Skill` tool) or agent (`Task` tool)?
|
|
334
|
+
- **Outcome detection** -- Was the session successful (edits without errors), partial (errors then fixes), or failed?
|
|
335
|
+
- **Score calculation** -- Adopted + success = 1.0, adopted + partial = 0.5, adopted + failure = 0.2
|
|
336
|
+
- Stats feed back into composite scoring, improving future dispatch quality over time
|
|
337
|
+
|
|
338
|
+
**Injection templates:**
|
|
339
|
+
|
|
340
|
+
| Resource type | Location | Template |
|
|
341
|
+
|---------------|----------|----------|
|
|
342
|
+
| Skill | `~/.claude/skills/` (native) | Short hint: use `/skill <name>` |
|
|
343
|
+
| Skill | managed directory | Full skill content injected (up to 3KB) |
|
|
344
|
+
| Agent | any | Agent definition injected for `Task` tool delegation |
|
|
345
|
+
|
|
346
|
+
### Episode Encoding
|
|
347
|
+
|
|
348
|
+
Episodes are batched related operations (edits to the same file group) that get processed by a background LLM worker:
|
|
349
|
+
|
|
350
|
+
```
|
|
351
|
+
Episode buffer -> Flush to JSON -> claude -p --model haiku -> Structured observation -> SQLite
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
Each observation includes type, title, narrative, concepts, facts, importance (1-3), and is automatically deduplicated via two tiers: Jaccard similarity (>70% within 5 minutes) and MinHash signatures (>80% within 7 days across sessions). If the LLM call fails, a degraded observation is saved with inferred metadata (zero data loss). Related observations are linked via `related_ids` based on FTS5 title similarity and file overlap.
|
|
355
|
+
|
|
356
|
+
## Management Commands
|
|
357
|
+
|
|
358
|
+
```bash
|
|
359
|
+
# Plugin install:
|
|
360
|
+
/plugin install claude-mem-lite # Install / update
|
|
361
|
+
/plugin uninstall claude-mem-lite # Uninstall
|
|
362
|
+
|
|
363
|
+
# git clone install:
|
|
364
|
+
node install.mjs install # Install and configure
|
|
365
|
+
node install.mjs uninstall # Remove (keep data)
|
|
366
|
+
node install.mjs uninstall --purge # Remove and delete all data
|
|
367
|
+
node install.mjs status # Show current status
|
|
368
|
+
node install.mjs doctor # Diagnose issues
|
|
369
|
+
|
|
370
|
+
# npx install:
|
|
371
|
+
npx claude-mem-lite # Install / reinstall
|
|
372
|
+
npx claude-mem-lite uninstall # Remove (keep data)
|
|
373
|
+
npx claude-mem-lite doctor # Diagnose issues
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
### doctor
|
|
377
|
+
|
|
378
|
+
Checks Node.js version, dependencies, server/hook files, database integrity, FTS5 indexes, and stale processes.
|
|
379
|
+
|
|
380
|
+
### status
|
|
381
|
+
|
|
382
|
+
Shows MCP registration, hook configuration, and database stats (observation/session counts).
|
|
383
|
+
|
|
384
|
+
## Uninstall
|
|
385
|
+
|
|
386
|
+
```bash
|
|
387
|
+
# Plugin:
|
|
388
|
+
/plugin uninstall claude-mem-lite
|
|
389
|
+
|
|
390
|
+
# git clone:
|
|
391
|
+
cd claude-mem-lite
|
|
392
|
+
node install.mjs uninstall # Keeps ~/.claude-mem-lite/ data
|
|
393
|
+
node install.mjs uninstall --purge # Deletes ~/.claude-mem-lite/ and all data
|
|
394
|
+
|
|
395
|
+
# npx:
|
|
396
|
+
npx claude-mem-lite uninstall
|
|
397
|
+
npx claude-mem-lite uninstall --purge
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
Data in `~/.claude-mem-lite/` is preserved by default. Delete manually if needed:
|
|
401
|
+
```bash
|
|
402
|
+
rm -rf ~/.claude-mem-lite/
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
## Project Structure
|
|
406
|
+
|
|
407
|
+
```
|
|
408
|
+
claude-mem-lite/
|
|
409
|
+
.claude-plugin/
|
|
410
|
+
plugin.json # Plugin manifest
|
|
411
|
+
marketplace.json # Marketplace catalog
|
|
412
|
+
.mcp.json # MCP server definition (plugin mode)
|
|
413
|
+
hooks/
|
|
414
|
+
hooks.json # Hook definitions (plugin mode)
|
|
415
|
+
commands/
|
|
416
|
+
mem.md # /mem command definition
|
|
417
|
+
server.mjs # MCP server: tool definitions, FTS5 search, database init
|
|
418
|
+
server-internals.mjs # Extracted search helpers: re-ranking, PRF, concept expansion
|
|
419
|
+
hook.mjs # Claude Code hooks: episode capture, error recall, session management
|
|
420
|
+
hook-llm.mjs # Background LLM workers: episode extraction, session summaries
|
|
421
|
+
hook-shared.mjs # Shared hook infrastructure: session management, DB access, LLM calls
|
|
422
|
+
hook-context.mjs # CLAUDE.md context injection and token budgeting
|
|
423
|
+
hook-episode.mjs # Episode buffer management: atomic writes, pending entry merging
|
|
424
|
+
hook-semaphore.mjs # LLM concurrency control: file-based semaphore for background workers
|
|
425
|
+
schema.mjs # Database schema: single source of truth for tables, migrations, FTS5
|
|
426
|
+
tool-schemas.mjs # Shared Zod schemas for MCP tool validation
|
|
427
|
+
utils.mjs # Shared utilities: FTS5 query building, MinHash dedup, secret scrubbing
|
|
428
|
+
# Intelligent dispatch
|
|
429
|
+
dispatch.mjs # 3-tier dispatch orchestration: fast filter, context signals, FTS5, Haiku
|
|
430
|
+
dispatch-inject.mjs # Injection template rendering for skill/agent recommendations
|
|
431
|
+
dispatch-feedback.mjs # Closed-loop feedback: adoption detection, outcome tracking
|
|
432
|
+
registry.mjs # Resource registry DB: schema, CRUD, FTS5, invocation tracking
|
|
433
|
+
registry-retriever.mjs # FTS5 retrieval with synonym expansion and composite scoring
|
|
434
|
+
registry-scanner.mjs # Filesystem scanner: reads content + hashes, delegates discovery
|
|
435
|
+
resource-discovery.mjs # Shared discovery layer: flat dirs, plugin nesting, loose .md files
|
|
436
|
+
haiku-client.mjs # Unified Haiku LLM wrapper: direct API or CLI fallback
|
|
437
|
+
# Install & config
|
|
438
|
+
install.mjs # CLI installer: setup, uninstall, status, doctor (npx/git clone mode)
|
|
439
|
+
skill.md # MCP skill definition (npx/git clone mode)
|
|
440
|
+
package.json # Dependencies and metadata
|
|
441
|
+
scripts/
|
|
442
|
+
setup.sh # Setup hook: npm install + migration (hidden dir + old dir)
|
|
443
|
+
post-tool-use.sh # Bash pre-filter: skips noise in ~5ms, tracks Read paths
|
|
444
|
+
convert-commands.mjs # Converts command .md → SKILL.md in managed plugins
|
|
445
|
+
index-managed.mjs # Offline indexer for managed resources
|
|
446
|
+
# Test & benchmark (dev only)
|
|
447
|
+
tests/ # Unit, property, integration, contract, E2E, pipeline tests (581 tests)
|
|
448
|
+
benchmark/ # BM25 search quality benchmarks + CI gate
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
## Search Quality
|
|
452
|
+
|
|
453
|
+
Benchmarked on 200 observations across 30 queries (standard + hard-negative categories):
|
|
454
|
+
|
|
455
|
+
| Metric | Score |
|
|
456
|
+
|--------|-------|
|
|
457
|
+
| Recall@10 | 0.88 |
|
|
458
|
+
| Precision@10 | 0.96 |
|
|
459
|
+
| nDCG@10 | 0.95 |
|
|
460
|
+
| MRR@10 | 0.95 |
|
|
461
|
+
| P95 search latency | 0.15ms |
|
|
462
|
+
|
|
463
|
+
The benchmark suite runs as a CI gate (`npm run benchmark:gate`) to prevent search quality regressions.
|
|
464
|
+
|
|
465
|
+
## Development
|
|
466
|
+
|
|
467
|
+
```bash
|
|
468
|
+
npm run lint # ESLint static analysis
|
|
469
|
+
npm test # Run all 581 tests (vitest)
|
|
470
|
+
npm run test:smoke # Run 5 core smoke tests
|
|
471
|
+
npm run test:coverage # Run tests with V8 coverage (≥70% lines/functions, ≥60% branches)
|
|
472
|
+
npm run benchmark # Run full search quality benchmark
|
|
473
|
+
npm run benchmark:gate # CI gate: fails if metrics regress beyond 5% tolerance
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
## Environment Variables
|
|
477
|
+
|
|
478
|
+
| Variable | Description | Default |
|
|
479
|
+
|----------|-------------|---------|
|
|
480
|
+
| `CLAUDE_MEM_DIR` | Custom data directory. All databases, runtime files, and managed resources are stored here. | `~/.claude-mem-lite/` |
|
|
481
|
+
| `CLAUDE_MEM_MODEL` | LLM model for background calls (episode extraction, session summaries, dispatch). Accepts `haiku` or `sonnet`. | `haiku` |
|
|
482
|
+
| `CLAUDE_MEM_DEBUG` | Enable debug logging (`1` to enable). | _(disabled)_ |
|
|
483
|
+
|
|
484
|
+
## License
|
|
485
|
+
|
|
486
|
+
MIT
|