@spike1292/claude-memory 0.0.0-stage → 0.14.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.
Files changed (74) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +412 -2
  3. package/hooks/distill-session.mjs +74 -0
  4. package/hooks/graph-staleness-check.mjs +25 -0
  5. package/hooks/hooks.json +94 -0
  6. package/hooks/insights-surface.mjs +48 -0
  7. package/hooks/lib/distill-session.mjs +1560 -0
  8. package/hooks/lib/dupe-report.mjs +61 -0
  9. package/hooks/lib/env-shell.mjs +92 -0
  10. package/hooks/lib/graph-staleness-check.mjs +394 -0
  11. package/hooks/lib/hook-io.mjs +715 -0
  12. package/hooks/lib/insights-surface.mjs +165 -0
  13. package/hooks/lib/memory-link-lint.mjs +499 -0
  14. package/hooks/lib/memory-recall.mjs +219 -0
  15. package/hooks/lib/omp.mjs +103 -0
  16. package/hooks/lib/opencode.mjs +231 -0
  17. package/hooks/lib/paths.mjs +452 -0
  18. package/hooks/lib/semantic-index-refresh.mjs +155 -0
  19. package/hooks/lib/validate-note.mjs +218 -0
  20. package/hooks/lib/vault-env.sh +110 -0
  21. package/hooks/memory-link-lint.mjs +65 -0
  22. package/hooks/memory-recall.mjs +251 -0
  23. package/hooks/semantic-index-refresh.mjs +23 -0
  24. package/hooks/session-context.mjs +9 -0
  25. package/hooks/validate-note.mjs +52 -0
  26. package/hooks/vault-memory-sync.sh +154 -0
  27. package/omp/index.js +1 -0
  28. package/opencode/index.js +1 -0
  29. package/package.json +51 -4
  30. package/scripts/claude-memory.mjs +31 -0
  31. package/scripts/doctor-perf.mjs +121 -0
  32. package/scripts/doctor.sh +558 -0
  33. package/scripts/env.mjs +6 -0
  34. package/scripts/lib/claude-memory.mjs +168 -0
  35. package/scripts/lib/doctor-perf.mjs +434 -0
  36. package/scripts/lib/hook-stats.mjs +864 -0
  37. package/scripts/lib/lexical.mjs +85 -0
  38. package/scripts/lib/memory-adopt.mjs +69 -0
  39. package/scripts/lib/memory-audit-checks.mjs +344 -0
  40. package/scripts/lib/memory-eval.mjs +381 -0
  41. package/scripts/lib/memory-mark.mjs +135 -0
  42. package/scripts/lib/memory-mcp.mjs +142 -0
  43. package/scripts/lib/memory-merge.mjs +316 -0
  44. package/scripts/lib/memory-mine.mjs +108 -0
  45. package/scripts/lib/memory-promote.mjs +207 -0
  46. package/scripts/lib/memory-prune.mjs +84 -0
  47. package/scripts/lib/memory-semantic.mjs +999 -0
  48. package/scripts/lib/memory-setup.mjs +170 -0
  49. package/scripts/lib/memory-synth-vault.mjs +538 -0
  50. package/scripts/lib/model-default.mjs +7 -0
  51. package/scripts/lib/models.mjs +58 -0
  52. package/scripts/lib/prune-logs.mjs +130 -0
  53. package/scripts/lib/recall-stats.mjs +354 -0
  54. package/scripts/lib/share-modules.mjs +70 -0
  55. package/scripts/lib/slim-install.mjs +162 -0
  56. package/scripts/lib/vault-mcp.mjs +405 -0
  57. package/scripts/memory-adopt.mjs +160 -0
  58. package/scripts/memory-audit-checks.mjs +375 -0
  59. package/scripts/memory-eval.mjs +753 -0
  60. package/scripts/memory-mark.mjs +39 -0
  61. package/scripts/memory-mcp.mjs +35 -0
  62. package/scripts/memory-merge.mjs +55 -0
  63. package/scripts/memory-prune.mjs +44 -0
  64. package/scripts/memory-semantic.mjs +1192 -0
  65. package/scripts/memory-setup.mjs +33 -0
  66. package/scripts/memory-synth-vault.mjs +251 -0
  67. package/scripts/prune-logs.mjs +42 -0
  68. package/scripts/share-modules.mjs +79 -0
  69. package/scripts/slim-install.mjs +55 -0
  70. package/scripts/vault-mcp.mjs +50 -0
  71. package/stubs/onnxruntime-web/index.mjs +11 -0
  72. package/stubs/onnxruntime-web/package.json +12 -0
  73. package/stubs/sharp/index.mjs +11 -0
  74. package/stubs/sharp/package.json +12 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Henk Bakker
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 CHANGED
@@ -1,3 +1,413 @@
1
- # Temporary Holding Version
1
+ # claude-memory
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ An extension of [Claude Code](https://claude.com/claude-code)'s own memory, backed by a
4
+ plain-Markdown Obsidian vault.
5
+
6
+ Claude Code has auto memory, and it reads `~/.claude/projects/<project>/memory/MEMORY.md`. This
7
+ plugin fills that file well and adds every layer above it: per-project facts, session logs,
8
+ lessons distilled automatically from what actually happened, a codebase graph, and hybrid semantic
9
+ + lexical retrieval so a question phrased differently from the note still finds it. It does not
10
+ replace Claude Code's memory and does not compete with it — it is the vault behind it.
11
+
12
+ For software engineers working in a codebase. Why it is shaped this way, and what it refuses to
13
+ be: **[docs/vision.md](docs/vision.md)**. How to use it day to day: **[docs/usage.md](docs/usage.md)**.
14
+ How it compares to other memory systems, and where it loses: **[docs/comparison.md](docs/comparison.md)**.
15
+
16
+ Everything is plain Markdown on your disk. The embedding model runs locally via ONNX — **notes are
17
+ never sent anywhere.**
18
+
19
+ ## Install
20
+
21
+ ```
22
+ /plugin marketplace add spike1292/claude-memory
23
+ /plugin install memory@claude-memory
24
+ /memory:install
25
+ /memory:doctor
26
+ ```
27
+
28
+ `/memory:install` is not optional. Claude Code installs npm dependencies from the lockfile but
29
+ **skips lifecycle scripts**, and `onnxruntime-node` fetches its native binary in a postinstall — so
30
+ the package directory exists while the runtime is unusable. `/memory:install` closes that gap,
31
+ migrates any state from a previous install, and warms the model.
32
+
33
+ It also slims `node_modules` from 380 MB to 59 MB — the dependency tarballs carry every platform's
34
+ native runtime plus a browser WASM backend and an image pipeline that nothing here executes.
35
+
36
+ Without it, everything except semantic search still works.
37
+
38
+ ### Other harnesses
39
+
40
+ The same hooks run in GitHub Copilot CLI, OpenAI Codex CLI, opencode v2 and Oh My Pi (omp). What each one supports, and what it
41
+ cannot do, is the table in [docs/usage.md](docs/usage.md#harnesses). The vault and
42
+ `~/.claude-memory/config.json` are shared, so one config serves every harness.
43
+
44
+ **Codex CLI** (verified on 0.171.0):
45
+
46
+ ```sh
47
+ codex plugin marketplace add https://github.com/spike1292/claude-memory.git
48
+ codex plugin add memory@claude-memory
49
+ cd ~/.codex/plugins/cache/claude-memory/memory/local && npm ci # embedding runtime
50
+ ```
51
+
52
+ Then open `codex`, run `/hooks`, and trust the `memory` hooks. Codex runs a plugin hook only after
53
+ you trust it. Hooks are on by default (`[features] hooks = true`).
54
+
55
+ **opencode v2** (`@opencode/cli` 2.x; partly verified on 2.4.4, see the table): clone the repo, run
56
+ `npm ci` in it, and list its `opencode/` directory in `plugins` in `~/.config/opencode/opencode.jsonc`
57
+ or a project's `opencode.json`:
58
+
59
+ ```json
60
+ { "plugins": ["/path/to/claude-memory/opencode"] }
61
+ ```
62
+
63
+ **Oh My Pi (omp)** (verified on 19.0.1 with `-e`; the marketplace path is from omp's docs, not run):
64
+
65
+ ```sh
66
+ omp plugin marketplace add spike1292/claude-memory
67
+ omp plugin install memory@claude-memory
68
+ cd ~/.omp/plugins/cache/plugins/claude-memory___memory___<version> && npm ci # embedding runtime
69
+ ```
70
+
71
+ omp loads the extension from `package.json` `omp.extensions` on the next start. To load it from a
72
+ clone instead, add `/path/to/claude-memory/omp/index.js` to `extensions:` in
73
+ `~/.omp/agent/config.yml`, or pass `omp -e /path/to/claude-memory/omp/index.js`.
74
+
75
+ ### Requirements
76
+
77
+ | | |
78
+ | --- | --- |
79
+ | **Node ≥ 22.5** | hard requirement — the engine uses the built-in `node:sqlite` |
80
+ | `jq` | every hook parses its stdin payload with it |
81
+ | `claude` on PATH | distillation and graph refresh shell out to it headlessly; optional |
82
+ | macOS / Linux | bash + node; no Windows support |
83
+
84
+ There is **no Python dependency.** The session distiller was ported to Node on 2026-08-16 — Node
85
+ was already a hard requirement, so Python only added a second runtime that could be the wrong
86
+ version. It usually was: macOS ships 3.9, which cannot parse the `str | None` annotations the
87
+ distiller used, so on a stock Mac `Insights/` silently stopped being written.
88
+
89
+ `/memory:doctor` checks all of these and tells you what each one being absent costs you.
90
+
91
+ ### Optional integrations
92
+
93
+ **Not installed by this plugin, not required, and not on the plugin's retrieval path.**
94
+
95
+ | | What it adds | Without it |
96
+ | --- | --- | --- |
97
+ | `codebase-memory-mcp` server | the L4 `Graph/` layer and `/memory:graph-report` | no L4 digest; L1–L3 unaffected |
98
+
99
+ Setup, failure modes, and what its absence actually costs:
100
+ **[docs/optional-integrations.md](docs/optional-integrations.md)**.
101
+
102
+ ## Configuration
103
+
104
+ Settings live in **`~/.claude-memory/config.json`**:
105
+
106
+ ```json
107
+ {
108
+ "vault": "/absolute/path/to/your/Obsidian/vault",
109
+ "recall": true,
110
+ "model": "bge-m3"
111
+ }
112
+ ```
113
+
114
+ | Key | Default | What it does |
115
+ | --- | --- | --- |
116
+ | `vault` | `~/Documents/ClaudeVault` | vault root |
117
+ | `recall` | `false` | arm per-prompt recall |
118
+ | `crossProjectRecall` | `[]` | project keys whose recall searches **every** project's `Memory/` and `Insights/` notes, e.g. `["github.com-you-home-repo"]` for a home repo you reach other repos from. Hits are labelled with their project. Reads only — notes are still written under the session's own project. Recall then takes ~222 ms per prompt over 25 projects against ~73 ms for one (p50, warm server, 2026-12-02); other projects are unchanged. Env: `MEMORY_CROSS_PROJECT_RECALL` (comma-separated) |
119
+ | `model` | `bge-m3` | also `bge-small-en`, `e5-multi`. Changing it means a full re-index. |
120
+ | `logRetentionDays` | `30` | days of `logs/{recall,hooks}-<date>.jsonl` kept; older ones are deleted on the first log line of a new day. Clamped to 36500 (a century) — set it high to keep everything |
121
+ | `freshnessDays` | `90` | `/memory:health` warns on an `(as of YYYY-MM-DD)` stamp older than this. A number, or `{ "default": 90, "Memory/<project>": 30 }` — vault-relative folder prefixes, longest wins. Env: `MEMORY_FRESHNESS_DAYS`. [Why 90](docs/decisions/2026-10-12-freshness-window.md) |
122
+ | `gitAutoCommit` | `false` | when the vault is a git repo, commit the notes the distiller writes or merges at session end, in one commit, by path — never `git add -A`. See [Troubleshooting](#troubleshooting) for what counts as a no-op |
123
+
124
+ `/memory:install` writes this file. `/memory:doctor` prints which source each value came from, and
125
+ **hard-fails if you are pointed at an empty vault while a populated one exists** — the failure that
126
+ an "is the directory there?" check cannot see.
127
+
128
+ **Put configuration here, not in `~/.claude/settings.json`'s `env` block.** A config file is read
129
+ when the hook runs, so it does not depend on what a given process inherited or on when the value was
130
+ written — a `CLAUDE_VAULT` added to `settings.local.json` mid-session did not reach that session's
131
+ hooks, and the SessionStart hook duly built an empty vault at the default path. Both ponytail and
132
+ context-mode keep their settings in their own file for the same reason.
133
+
134
+ Environment overrides are still honoured where they do reach the process:
135
+ `CLAUDE_VAULT`, `MEMORY_RECALL_ENABLED=1`, `MEMORY_CROSS_PROJECT_RECALL`, `MEMORY_SEMANTIC_MODEL`, `MEMORY_LOG_RETENTION_DAYS`,
136
+ `MEMORY_GIT_AUTO_COMMIT=1`,
137
+ and `CLAUDE_MEMORY_HOME`
138
+ (which relocates the state directory itself, so it can only be an env var).
139
+
140
+ **Per-prompt recall ships inert on purpose.** Injecting retrieved notes into every prompt changes
141
+ how every session reads; that should be your decision, not a default.
142
+
143
+ ## What it does
144
+
145
+ ### Every session start
146
+
147
+ | Hook | What it does |
148
+ | --- | --- |
149
+ | `vault-memory-sync` | points this project's memory dir at its vault folder; emits the standing retrieval rules |
150
+ | `insights-surface` | surfaces recent `Mistakes/` titles, so past lessons are in context before similar work |
151
+ | `memory-link-lint` | names L1 notes reachable only from the MOC — an orphan in the note graph |
152
+ | `semantic-index-refresh` | refreshes the vector index in the background; a no-op costs a stat pass |
153
+ | `graph-staleness-check` | regenerates the codebase graph digest when commits have moved past it |
154
+
155
+ ### While you work
156
+
157
+ `memory-recall` (UserPromptSubmit, opt-in) injects a bounded brief of relevant notes, and abstains
158
+ when nothing scores well enough — silence is the default, not a guess.
159
+
160
+ `validate-note` (PostToolUse) warns on vault writes that break the note conventions: unquoted
161
+ colons in frontmatter, a metric with no provenance, "superseded" written in prose where no
162
+ mechanical check can see it. It warns; it never blocks.
163
+
164
+ ### Every session end
165
+
166
+ `distill-session` reads the transcript and extracts patterns, mistakes, and decisions into
167
+ `Insights/`, deduping against what is already there. `<private>…</private>` blocks are redacted
168
+ before extraction.
169
+
170
+ ## Commands
171
+
172
+ | | |
173
+ | --- | --- |
174
+ | `/memory:save` | write a session summary to `Logs/<project>/` |
175
+ | `/memory:resume` | restore context from the latest log |
176
+ | `/memory:health` | audit for contradictions, stale claims, orphans (asks before deleting) |
177
+ | `/memory:prune` | archive old logs, dedup notes, refresh both indexes |
178
+ | `/memory:synthesize` | consolidate a cluster of notes into one `permanent/` note |
179
+ | `/memory:challenge` | make the vault argue *against* a decision you are about to make |
180
+ | `/memory:eval` | measure retrieval: recall@k and MRR against a case set |
181
+ | `/memory:graph-report` | regenerate the codebase graph digest |
182
+ | `/memory:protocol` | the note conventions, as an on-demand skill |
183
+ | `/memory:install` · `/memory:doctor` | set up and diagnose |
184
+
185
+ ## Layout
186
+
187
+ ```
188
+ <vault>/
189
+ ├── Memory/<project>/ L1 — atomic facts, decisions; MEMORY.md is the MOC, auto-loaded
190
+ ├── Logs/<project>/ L2 — timestamped session summaries
191
+ ├── Insights/<project>/ L3 — auto-distilled Patterns / Mistakes / Decisions
192
+ ├── Graph/<project>/ L4 — codebase graph digest
193
+ └── permanent/ cross-project notes that graduated out of a single project
194
+
195
+ $CLAUDE_MEMORY_HOME/ never in the plugin — every version gets its own cache dir
196
+ ├── db/ models/ logs/ run/ eval/
197
+ ```
198
+
199
+ ## How project identity works
200
+
201
+ Vault folders are keyed on the **normalised git remote**, not the checkout path:
202
+
203
+ ```
204
+ git@gitlab.example.com:Group/Repo.git ─┐
205
+ https://gitlab.example.com/Group/Repo.git ─┼─→ gitlab.example.com-group-repo
206
+ https://user:token@gitlab.example.com/... ─┘ (credentials stripped)
207
+ ```
208
+
209
+ So the same project maps to one memory folder on every machine and from every checkout — and
210
+ `cd`-ing into a subdirectory does not fork a second, invisible memory. Repos with no remote fall
211
+ back to the directory name; non-git directories fall back to the path-slug.
212
+
213
+ `~/.claude/projects/<cwd-slug>/` keeps its own name — Claude Code owns that path — and only its
214
+ `memory` symlink is repointed.
215
+
216
+ ## Sharing
217
+
218
+ **This is the engine. Your vault is not in it and must never be.** Notes routinely contain
219
+ colleague names, account IDs, internal hostnames, and personal material. The same goes for eval
220
+ case sets, which are generated *from* the vault — that is why they live in
221
+ `$CLAUDE_MEMORY_HOME/eval/` and are gitignored here.
222
+
223
+ For team knowledge, do not share the vault — check the facts into the *project's own* repo under
224
+ `docs/`, where code review and CODEOWNERS apply. Personal vault, shared project docs.
225
+
226
+ ## Troubleshooting
227
+
228
+ **"embedding runtime not installed" at session start.** Claude Code installed the packages but
229
+ skipped `onnxruntime-node`'s postinstall, so the native binary is missing. `/memory:install`.
230
+
231
+ **Weights re-downloaded after a plugin update.** They should be in `$CLAUDE_MEMORY_HOME/models`,
232
+ outside the version-pinned plugin cache. `/memory:doctor` warns if they end up inside the plugin.
233
+
234
+ **Vault on iCloud / Dropbox / Synology: never put symlinks *inside* it.** Sync clients replace
235
+ *directory* symlinks with empty directories and rename the original to a `*_Conflict` entry. File
236
+ symlinks survive. A symlink pointing *into* the vault from outside is fine — that is how the memory
237
+ directory is wired.
238
+
239
+ **Vault is a git repo, not a cloud-synced folder.** The symlink hazard above does not exist under
240
+ git — a git checkout has no directory-symlink-replacement behaviour to worry about. It also does
241
+ not sync itself: a commit only exists locally until something pushes it. Setting `gitAutoCommit`
242
+ (off by default) makes the distiller commit, at session end, exactly the notes it wrote or merged
243
+ that run, in one commit, using the vault repo's own `git config user.name`/`user.email`. It never
244
+ runs `git add -A`, never pushes, and silently does nothing if the vault isn't a git repo, git isn't
245
+ installed, no identity is configured, or there's nothing to commit — a session never fails because
246
+ of it. `/memory:doctor` reports whether the resolved vault is git-backed or a plain directory.
247
+
248
+ **Pushing a git-backed vault.** The plugin never pushes, so `/memory:doctor` warns when the vault
249
+ is 20 or more commits ahead of its upstream (counted on the local tracking ref, no fetch). To push
250
+ on every commit — the distiller's and your own — add a `post-commit` hook to the vault repo:
251
+
252
+ ```sh
253
+ #!/bin/sh
254
+ (git pull -q --rebase --autostash origin "$(git branch --show-current)" >/dev/null 2>&1 || git rebase --abort >/dev/null 2>&1; git push -q origin HEAD >/dev/null 2>&1) &
255
+ ```
256
+
257
+ Save it as `<vault>/.git/hooks/post-commit` and `chmod +x` it. It uses your own git and SSH setup;
258
+ a failed pull or push (offline, a locked SSH agent) is silent and retried by the next commit. It
259
+ pulls the current branch with rebase first (`origin HEAD` would pull the remote's default branch)
260
+ because a second machine that pushes first makes every later plain push a non-fast-forward
261
+ rejection, silently, forever. `.git/hooks` is not versioned, so each clone needs
262
+ it again. **A rebase conflict is aborted, not resolved**: the vault stays diverged, nothing pushes,
263
+ and a human must run `git pull --rebase` in the vault. `/memory:doctor` warns when the vault is both
264
+ ahead and behind its upstream.
265
+
266
+ **Never point a hook at a throwaway vault on a live machine.** `vault-memory-sync.sh` repoints the
267
+ real `~/.claude/projects/*/memory` symlink to whatever `CLAUDE_VAULT` says. It copies rather than
268
+ moves (it used to move, which cost 24 notes once), but you will still have to repoint it back.
269
+ Isolate `HOME`, not just `CLAUDE_VAULT`, when testing.
270
+
271
+ **Duplicate notes keep reappearing after you merge them.** The distiller reconciles on write
272
+ (token-Jaccard ≥ 0.45, same folder) and updates the existing note instead of adding a near-duplicate.
273
+ If it recurs, the two titles score below the threshold; `hooks/distill-session.mjs` has the knob and
274
+ a self-test with real cases.
275
+
276
+ ## Known gaps
277
+
278
+ - **`MEMORY.md` is measured, not trimmed.** Claude Code loads its first 200 lines or 25 KB and drops
279
+ the rest, reporting nothing. The SessionStart lint and `/memory:doctor` report the size against
280
+ that cap from 80% up ([the decision](docs/decisions/2026-08-22-auto-memory.md)); deciding what
281
+ leaves the MOC is still a human act.
282
+ - **Notes have no expiry**, so phase-specific facts linger after the phase ends. `/memory:health`
283
+ warns on an `as of` stamp past its window (FRESH-2), but an unstamped claim still never ages.
284
+ - **The real-vault eval sets are small and self-authored** (28 EN, 15 NL), so one case is 3.6
285
+ points and the numbers measure one vault, not memory systems in general. Read MRR and direction,
286
+ not single moves.
287
+ - **The generated benchmark's English set is at its ceiling** — bge-m3 scores 100%, so it is a
288
+ tripwire for breakage, not an instrument for improvement. One hardening attempt failed, and the
289
+ stronger version was rejected because the acceptance test could not detect the ambiguity it would
290
+ introduce.
291
+ - **Secret redaction is opt-in** (`<private>…</private>`), not automatic.
292
+ - **Promotion to `permanent/` is still mostly unrun.** `--clusters` reports dozens of topics with no
293
+ consolidated note. The tooling finds them; writing them is judgement and takes time.
294
+ - **No Windows support.** bash and POSIX paths throughout.
295
+
296
+ ## Retrieval
297
+
298
+ `scripts/memory-semantic.mjs --query "..."` runs a vector arm and a keyword arm and rank-fuses
299
+ them, which is why it answers both "how long was the site down" and `WAF`.
300
+ Add `--all-projects` to search every project's notes at once, as `crossProjectRecall` does.
301
+
302
+ ### From any MCP agent
303
+
304
+ `scripts/memory-mcp.mjs` is a read-only stdio MCP server with one tool,
305
+ `memory_search(query, k?, slug?)`. It returns the same hybrid ranking, one line per hit:
306
+ `score [layer] note — snippet`. `slug` defaults to the project of the directory the agent starts
307
+ the server in. The server never loads the model itself: it asks the shared `--serve` process and
308
+ starts it on the first call. Until that process is ready, a call answers from the keyword arm and
309
+ says so.
310
+
311
+ - **Claude Code:** automatic. The plugin registers it as `memory`; the tool shows up as
312
+ `mcp__plugin_memory_memory__memory_search`.
313
+ - **Other agents:** install the CLI (next section) and register `claude-memory mcp`. Do not use
314
+ the path in `~/.claude-memory/plugin-root`: it changes on every plugin update.
315
+
316
+ ```bash
317
+ copilot mcp add memory -- claude-memory mcp # GitHub Copilot CLI
318
+ codex mcp add memory -- claude-memory mcp # Codex
319
+ ```
320
+
321
+ ### From the command line: `claude-memory`
322
+
323
+ ```bash
324
+ npm i -g @spike1292/claude-memory
325
+ claude-memory setup --vault ~/notes # config, state dirs, model download + check, index
326
+ claude-memory --help # every command; claude-memory <command> --help for its flags
327
+ claude-memory search "why is batch size one" -k 5
328
+ ```
329
+
330
+ It uses the same state as the plugin — `$CLAUDE_MEMORY_HOME` (default `~/.claude-memory`), its
331
+ `config.json`, the indexes and the model — so it searches the index the plugin built. It warns on
332
+ stderr, once, when its version differs from the installed plugin's.
333
+
334
+ `search` prints one hit per line, `score<TAB>layer<TAB>note path<TAB>snippet`, with no banner, so
335
+ it is cheap in tokens and works with `cut`, `grep` and `awk`. `--json` gives one JSON object per
336
+ query instead. TSV paths escape backslashes, tabs, carriage returns and line feeds as
337
+ `\\`, `\t`, `\r` and `\n`. The slug comes from the current directory's git remote; `--slug` overrides it.
338
+
339
+ | command | runs |
340
+ | --- | --- |
341
+ | `setup [--vault <path>] [--model <name>] [--force]` | the mechanical steps of `/memory:install`; idempotent, one line per step. Writes config after setup succeeds. An existing key is kept unless `--force` |
342
+ | `prune [--slug <key>] [--dry-run]` | archive logs older than 90 days, refresh the index, print candidate duplicates as `dupe\|cross-dupe<TAB>score<TAB>layer<TAB>note<TAB>layer<TAB>note`. Dry run previews log moves and scans an existing index read-only. Merge and mark decisions stay in `/memory:prune` |
343
+ | `search <query...>` | hybrid search (`memory-semantic.mjs --query`) |
344
+ | `index [dir] [--rebuild]` | build or refresh this project's index |
345
+ | `semantic <flags>` | `memory-semantic.mjs` as is: `--coverage`, `--dupes`, `--clusters`, … |
346
+ | `doctor` | Run the same checks as `/memory:doctor` against the CLI install. `--hooks` reads shared plugin logs. |
347
+ | `eval`, `mark`, `merge`, `adopt`, `audit` | the scripts behind the matching `/memory:` commands |
348
+ | `mcp` | the stdio MCP server above |
349
+
350
+ **Any agent without MCP** (OMP, a cron job, a shell script, another user's harness) needs one line
351
+ in its instructions: *"To recall project knowledge, run `claude-memory search "<terms>"` and read
352
+ the files in the third column."* Write the query in the words the answer would use; the keyword
353
+ arm does not know synonyms.
354
+
355
+ The package's `postinstall` prunes unused binaries from its global install. If npm enforces an
356
+ install-script allowlist, use the package names listed in its diagnostic to allow the scripts.
357
+
358
+ Measured on a real 3,400-chunk vault with `bge-m3`, against author-written paraphrases that share
359
+ no distinctive term with the target note:
360
+
361
+ | case set | n | recall@1 | @5 | @10 | MRR |
362
+ | --- | --- | --- | --- | --- | --- |
363
+ | English paraphrases | 28 | 0.393 | **0.821** | 0.893 | 0.546 |
364
+ | Dutch paraphrases | 15 | 0.467 | **0.867** | 0.933 | 0.628 |
365
+ | same English set, keyword-only | 28 | 0.071 | 0.250 | 0.464 | 0.158 |
366
+
367
+ Those case sets contain vault content, so they are machine-local and not in this repo. To
368
+ reproduce the numbers on your own machine, or to check a change did not regress retrieval, generate
369
+ a deterministic synthetic vault:
370
+
371
+ ```bash
372
+ node scripts/memory-synth-vault.mjs --out /tmp/bench --notes 300 --seed 7
373
+ node scripts/memory-semantic.mjs --vault /tmp/bench --slug bench --index --rebuild
374
+ node scripts/memory-eval.mjs --vault /tmp/bench --slug bench --run --cases /tmp/bench/cases-paraphrase.jsonl
375
+ ```
376
+
377
+ **Any recall figure quoted anywhere must name the case set it came from.** Questions rewritten per
378
+ run measure the questions, not the retrieval.
379
+
380
+ ## Development
381
+
382
+ ```bash
383
+ node --test # every *.test.mjs beside the module it tests
384
+ node --test hooks/lib/paths.test.mjs # one file
385
+ scripts/doctor.sh
386
+ ```
387
+
388
+ **Node only — Bun does not work here.** Bun has no `node:sqlite`, which the search engine and the
389
+ recall hook are built on; the native deps load fine. Full evaluation with numbers:
390
+ [docs/decisions/2026-08-17-bun.md](docs/decisions/2026-08-17-bun.md).
391
+
392
+ Nothing resolves an absolute install path: bash uses `BASH_SOURCE` and node uses
393
+ `import.meta.url`. So a dev checkout, a symlink, and the version-pinned plugin cache all work
394
+ the same way. `${CLAUDE_PLUGIN_ROOT}` is guaranteed only in `hooks/hooks.json`. Command bodies
395
+ trust it only when it holds `scripts/memory-semantic.mjs` — inside `ctx_execute` it is
396
+ context-mode's root — and otherwise read the `$CLAUDE_MEMORY_HOME/plugin-root` breadcrumb the
397
+ SessionStart hook writes.
398
+
399
+ ### Contributing
400
+
401
+ `main` is protected — branch, push, open a PR. CI runs the self-tests on Node 22 and 24 against a
402
+ generated synthetic vault (never a real one) and must be green to merge. Put a note under
403
+ `## [Unreleased]` in [`CHANGELOG.md`](CHANGELOG.md) in the same PR; that section becomes the
404
+ release notes verbatim.
405
+
406
+ Branch protection, the two review workflows, why a PR that edits a workflow file never gets
407
+ reviewed, and the release process: **[docs/ci-and-releases.md](docs/ci-and-releases.md)**.
408
+
409
+ Design notes and decision records live in **[docs/](docs/)**.
410
+
411
+ ## License
412
+
413
+ MIT
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env node
2
+ // SessionEnd + Stop entry. Two modes, one file:
3
+ //
4
+ // no argv -> GATE. Reads the hook payload on stdin, decides, and detaches the worker below.
5
+ // argv -> WORKER. Distils one transcript into Obsidian Insight notes.
6
+ //
7
+ // The gate re-invokes this same path, so the argv form is a contract — keep it.
8
+ import { readStdin, payload, hookCwd, logHook } from './lib/hook-io.mjs';
9
+ import { distill, gate, gateOutcome, reconcileFields } from './lib/distill-session.mjs';
10
+
11
+ const argv = process.argv.slice(2);
12
+
13
+ if (argv.length >= 2) {
14
+ // WORKER. It logs its own line rather than being wrapped by a supervisor process: the gate's
15
+ // duration is a decision and this one is the distillation, and `process.on('exit')` catches every
16
+ // way this process can end short of a signal — including a throw, which exits non-zero.
17
+ /** @type {import('./lib/hook-io.mjs').HookOutcome} */
18
+ let outcome = 'error';
19
+ /** @type {string | undefined} */
20
+ let reason;
21
+ /** @type {Awaited<ReturnType<typeof distill>> | undefined} */
22
+ let r;
23
+ process.on('exit', () =>
24
+ logHook({
25
+ hook: 'distill-session',
26
+ event: 'worker',
27
+ cwd: argv[1],
28
+ session: process.env.MEMORY_HOOK_SESSION,
29
+ outcome,
30
+ reason,
31
+ // appendJsonl() would re-derive the slug from argv[1], which may be gone (#138).
32
+ extra: { ...(argv[2] ? { slug: argv[2] } : {}), ...(r ? reconcileFields(r) : {}) },
33
+ }),
34
+ );
35
+ try {
36
+ r = await distill(argv[0], argv[1], argv[2]);
37
+ } catch (e) {
38
+ // Caught only to RECORD it, then rethrown: the exit code and the stack in distill.log are
39
+ // unchanged. Without this an `error` row printed no reason at all, in the same report round
40
+ // that added the reason column so an error row could be read.
41
+ reason = String(/** @type {Error} */ (e)?.message ?? e);
42
+ throw e;
43
+ }
44
+ outcome = 'ran';
45
+ reason = r
46
+ ? `wrote ${r.written}, merged ${r.merged}` + (r.declined ? `, declined ${r.declined}` : '')
47
+ : 'nothing to distil';
48
+ if (r)
49
+ console.log(
50
+ `distill: wrote ${r.written} note(s), merged ${r.merged} into existing` +
51
+ // Omitted when zero, like every other optional field in this log: a mark that never fires
52
+ // should not add a column, but a mark that fires must never be invisible.
53
+ (r.declined ? `, declined ${r.declined} (reconcile: manual)` : '') +
54
+ `, for ${r.slug}`,
55
+ );
56
+ } else if (argv.length === 1) {
57
+ console.error(
58
+ 'usage: distill-session.mjs <transcript> <cwd> [project-key] (or no args to gate on stdin)',
59
+ );
60
+ process.exit(1);
61
+ } else {
62
+ // GATE only. The worker half above writes the second line itself — same session id, carried in
63
+ // MEMORY_HOOK_SESSION, and a duration that is the distillation rather than this decision.
64
+ const p = payload(readStdin());
65
+ const plan = gate(p);
66
+ logHook({
67
+ hook: 'distill-session',
68
+ event: String(p.hook_event_name ?? ''),
69
+ cwd: hookCwd(p),
70
+ session: /** @type {string|undefined} */ (p.session_id),
71
+ outcome: gateOutcome(plan),
72
+ reason: plan.run ? `${plan.lines} lines` : plan.reason,
73
+ });
74
+ }
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+ // SessionStart entry: nudge or regenerate a stale codebase graph report.
3
+ //
4
+ // Thin on purpose: stdin in, at most one JSON line out. Logic and tests live in
5
+ // lib/graph-staleness-check.mjs.
6
+ import { readStdin, payload, hookCwd, logHook } from './lib/hook-io.mjs';
7
+ import { check } from './lib/graph-staleness-check.mjs';
8
+
9
+ const p = payload(readStdin());
10
+ const cwd = hookCwd(p);
11
+ const session = /** @type {string|undefined} */ (p.session_id);
12
+
13
+ // A GATE, and the one detached hook with no worker line: the pid in graphgen.lock has to be the
14
+ // `claude` process itself, or a dead supervisor would free the lock while the work ran on. See
15
+ // lib/graph-staleness-check.mjs's check().
16
+ const r = check(cwd);
17
+ if (r.line) console.log(r.line);
18
+ logHook({
19
+ hook: 'graph-staleness-check',
20
+ event: String(p.hook_event_name ?? ''),
21
+ cwd,
22
+ session,
23
+ outcome: r.outcome,
24
+ reason: r.reason,
25
+ });
@@ -0,0 +1,94 @@
1
+ {
2
+ "hooks": {
3
+ "SessionStart": [
4
+ {
5
+ "hooks": [
6
+ {
7
+ "type": "command",
8
+ "command": "p=$(cat); printf '%s' \"$p\" | \"${CLAUDE_PLUGIN_ROOT}/hooks/vault-memory-sync.sh\" | { command -v node >/dev/null 2>&1 && node \"${CLAUDE_PLUGIN_ROOT}/hooks/session-context.mjs\" \"$p\" || cat; }",
9
+ "timeout": 15,
10
+ "statusMessage": "Syncing memory to Obsidian vault"
11
+ },
12
+ {
13
+ "type": "command",
14
+ "command": "command -v node >/dev/null 2>&1 && node \"${CLAUDE_PLUGIN_ROOT}/hooks/insights-surface.mjs\" || exit 0",
15
+ "timeout": 10,
16
+ "statusMessage": "Surfacing past mistakes"
17
+ },
18
+ {
19
+ "type": "command",
20
+ "command": "command -v node >/dev/null 2>&1 && node \"${CLAUDE_PLUGIN_ROOT}/hooks/memory-link-lint.mjs\" || exit 0",
21
+ "timeout": 10,
22
+ "statusMessage": "Linting memory note graph"
23
+ },
24
+ {
25
+ "type": "command",
26
+ "command": "command -v node >/dev/null 2>&1 && node \"${CLAUDE_PLUGIN_ROOT}/hooks/semantic-index-refresh.mjs\" || exit 0",
27
+ "timeout": 10
28
+ },
29
+ {
30
+ "type": "command",
31
+ "command": "command -v node >/dev/null 2>&1 && node \"${CLAUDE_PLUGIN_ROOT}/hooks/graph-staleness-check.mjs\" || exit 0",
32
+ "timeout": 10
33
+ }
34
+ ]
35
+ }
36
+ ],
37
+ "UserPromptSubmit": [
38
+ {
39
+ "hooks": [
40
+ {
41
+ "type": "command",
42
+ "command": "command -v node >/dev/null 2>&1 && node \"${CLAUDE_PLUGIN_ROOT}/hooks/memory-recall.mjs\" || exit 0",
43
+ "timeout": 10
44
+ }
45
+ ]
46
+ }
47
+ ],
48
+ "userPromptTransformed": [
49
+ {
50
+ "hooks": [
51
+ {
52
+ "type": "command",
53
+ "command": "command -v node >/dev/null 2>&1 && node \"${CLAUDE_PLUGIN_ROOT}/hooks/memory-recall.mjs\" || exit 0",
54
+ "timeout": 10
55
+ }
56
+ ]
57
+ }
58
+ ],
59
+ "PostToolUse": [
60
+ {
61
+ "matcher": "Write|Edit|MultiEdit",
62
+ "hooks": [
63
+ {
64
+ "type": "command",
65
+ "command": "command -v node >/dev/null 2>&1 && node \"${CLAUDE_PLUGIN_ROOT}/hooks/validate-note.mjs\" || exit 0",
66
+ "timeout": 10
67
+ }
68
+ ]
69
+ }
70
+ ],
71
+ "SessionEnd": [
72
+ {
73
+ "hooks": [
74
+ {
75
+ "type": "command",
76
+ "command": "command -v node >/dev/null 2>&1 && node \"${CLAUDE_PLUGIN_ROOT}/hooks/distill-session.mjs\" || exit 0",
77
+ "timeout": 15
78
+ }
79
+ ]
80
+ }
81
+ ],
82
+ "Stop": [
83
+ {
84
+ "hooks": [
85
+ {
86
+ "type": "command",
87
+ "command": "command -v node >/dev/null 2>&1 && node \"${CLAUDE_PLUGIN_ROOT}/hooks/distill-session.mjs\" || exit 0",
88
+ "timeout": 15
89
+ }
90
+ ]
91
+ }
92
+ ]
93
+ }
94
+ }