@nogataka/claw-memory 0.1.0 → 0.1.1

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.
@@ -3,14 +3,14 @@
3
3
  "owner": { "name": "nogataka" },
4
4
  "metadata": {
5
5
  "description": "claw-memory: local semantic memory + raw-log search for Claude Code",
6
- "version": "0.1.0"
6
+ "version": "0.1.1"
7
7
  },
8
8
  "plugins": [
9
9
  {
10
10
  "name": "claw-memory",
11
11
  "source": "./",
12
12
  "description": "Local semantic memory: auto-distill, recall injection, and raw Claude Code + Codex transcript search.",
13
- "version": "0.1.0"
13
+ "version": "0.1.1"
14
14
  }
15
15
  ]
16
16
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claw-memory",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Local semantic memory for Claude Code: auto-distills sessions, injects relevant past context, and searches raw Claude Code + Codex transcripts. sqlite-vec + local embeddings, no daemon, no Python.",
5
5
  "author": { "name": "nogataka" },
6
6
  "repository": "https://github.com/nogataka/claw-memory",
package/README.ja.md ADDED
@@ -0,0 +1,291 @@
1
+ # claw-memory
2
+
3
+ [English](README.md) | **日本語**
4
+
5
+ **AI コーディングエージェント(Claude Code / Codex)のためのローカル完結型・長期記憶。**
6
+ エージェントが過去のセッション・あなたの好み・以前の決定事項を記憶し、記録済みの全
7
+ トランスクリプトを横断検索できます。デーモン不要、Python 不要、外部ベクトル DB 不要。
8
+ データは一切マシン外に出ません(セッションを要約する LLM 呼び出しのみ外部で、これも
9
+ あなたが選択・制御します)。
10
+
11
+ ```bash
12
+ npm install -g @nogataka/claw-memory
13
+ ```
14
+
15
+ - **ストレージ**: `better-sqlite3` + `sqlite-vec` — ベクトルを 1 つの SQLite ファイル内に格納
16
+ - **埋め込み**: ローカルの `Xenova/multilingual-e5-small`(384次元・多言語・オフライン)
17
+ - **2 つの記憶ソース**: 蒸留済みのセマンティック DB と、Claude Code / Codex の生ログ全文検索
18
+ - **自動取り込み**: フックで終了済みセッションを蒸留し、新しいセッションへ関連記憶を注入
19
+ - **差し替え可能な LLM**: Claude / Codex のサブスクリプション(API キー不要)、または任意の
20
+ Anthropic / OpenAI 互換エンドポイントで蒸留
21
+
22
+ ---
23
+
24
+ ## 目次
25
+
26
+ - [機能](#機能)
27
+ - [インストールガイド](#インストールガイド)
28
+ - [MCP ツール](#mcp-ツール)
29
+ - [設定(環境変数)](#設定環境変数)
30
+ - [CLI リファレンス](#cli-リファレンス)
31
+ - [仕組み](#仕組み)
32
+ - [メモリビューア](#メモリビューア)
33
+ - [アンインストール](#アンインストール)
34
+ - [補足](#補足)
35
+
36
+ ---
37
+
38
+ ## 機能
39
+
40
+ ### 1. 2 つの独立した記憶ソース
41
+
42
+ | ソース | 内容 | ツール |
43
+ |--------|------|--------|
44
+ | **蒸留 DB** | LLM がセッションを要約 → 要約・好み・構造化メタデータ付きの埋め込みチャンク。セマンティック検索可能。 | `memory_recall`, `memory_search`, `memory_get` |
45
+ | **生ログ検索** | 実際の Claude Code(`~/.claude/projects`)/ Codex(`~/.codex/sessions`)ログを全文検索。蒸留していないセッションも対象。 | `memory_search_logs` |
46
+
47
+ 蒸留 DB は整理済みで高速に想起でき、生ログ検索は claw-memory 導入前を含め「いつか話した
48
+ こと」を必ず見つけられるセーフティネットです。
49
+
50
+ ### 2. 自動取り込み(distill)
51
+
52
+ セッション終了時、トランスクリプトを次の形に蒸留します。
53
+
54
+ - **構造化要約**(`### 依頼 / 調査・判明 / 完了 / 次の一手`)
55
+ - **ユーザーの好み**(言語・回答スタイル・フレームワーク・口調 など)を常時適用コンテキストとして保存
56
+ - **会話チャンク**をセマンティック検索用に埋め込み。各チャンクには
57
+ **observation type**(`discovery` / `bugfix` / `feature` / `decision` / `change`)、
58
+ **concepts**、**読んだ/編集したファイル** を付与
59
+
60
+ 蒸留は **増分的**(watermark で新規内容のないセッションをスキップ)かつ **冪等**
61
+ (再蒸留は置換であり重複しない)。クロスセッションの重複チャンクも排除します。
62
+
63
+ ### 3. 自動 recall 注入
64
+
65
+ セッション開始時(および各プロンプト時)に記憶ブロックを注入します。
66
+
67
+ - **好み** は `instruction="always-apply"` — エージェントが必ず従います。
68
+ - **直近の要約 + 類似する過去会話** は `instruction="reference-only"` — 背景として扱い、
69
+ 不必要に蒸し返しません。
70
+
71
+ これにより、文脈を再説明しなくても続きから作業できます。
72
+
73
+ ### 4. 構造化されたフィルタ検索
74
+
75
+ `memory_search` はトークン軽量なインデックス(id + タイトル + 日付 + type)を返します。
76
+ `type` / `concept` / `file` / 日付範囲で絞り込み、必要なものだけ `memory_get` で本文取得 —
77
+ コンテキスト消費を最小化します。
78
+
79
+ ### 5. プライバシーと安全性(設計段階から)
80
+
81
+ - **完全ローカル**: ストレージと埋め込みはマシン外に出ません。`distill` のみ LLM を呼び、
82
+ どの LLM を使うかはあなたが選択します。
83
+ - **`<private>…</private>`** で囲んだ区間は、保存・LLM 送信の前に除去されます。
84
+ - **`CLAW_MEMORY_EXCLUDED_PROJECTS`**: 指定パスは記録も想起もしません。
85
+ - **`memory_forget`**: チャンクをソフト削除。検索・recall・ビューアから消えます。
86
+
87
+ ### 6. 差し替え可能な LLM バックエンド(distill のみ)
88
+
89
+ サブスクリプションログイン(API キー不要)や任意の HTTP エンドポイントを利用できます
90
+ ([設定](#設定環境変数)参照)。tier ルーティングで、高頻度な distill を安価なモデルに
91
+ 振り分けられます。
92
+
93
+ ### 7. オンデマンドな Web ビューア
94
+
95
+ ビルド不要・読み取り専用のビューア(`claw-memory ui`)。プロジェクト・要約・チャンク
96
+ (メタデータ付き)・好みを閲覧でき、生ログ検索も実行できます。SSE で開いている間は自動
97
+ 更新。起動した時だけ動きます。
98
+
99
+ ---
100
+
101
+ ## インストールガイド
102
+
103
+ ### 前提条件
104
+
105
+ - **Node.js 20 以上**
106
+ - サブスクリプション LLM バックエンドを使う場合: **Claude Code CLI**(ログイン済み)/ **Codex CLI**(ログイン済み)
107
+ - 初回 `distill` 時に埋め込みモデル(約 100 MB、`~/.cache` にキャッシュ)をダウンロード
108
+
109
+ ### 手順 1 — パッケージをグローバルインストール
110
+
111
+ ```bash
112
+ npm install -g @nogataka/claw-memory
113
+ ```
114
+
115
+ グローバル導入によりフックと MCP サーバーが即座に起動します(未導入時はプラグインが
116
+ `npx -y @nogataka/claw-memory@latest` にフォールバックし、初回が遅くなります)。
117
+
118
+ ### 手順 2a — Claude Code(プラグイン、推奨)
119
+
120
+ ```text
121
+ /plugin marketplace add nogataka/claw-memory
122
+ /plugin install claw-memory
123
+ ```
124
+
125
+ Claude Code を再起動してください。次が自動登録されます。
126
+
127
+ - **MCP サーバー**(8 つの記憶ツール)
128
+ - **フック**: `SessionStart` / `UserPromptSubmit` → recall 注入、`Stop` → 自動 distill
129
+
130
+ 手動設定は不要です。確認は `/mcp` で `claw-memory` が見えるかどうかで行えます。
131
+
132
+ > **プラグインを使わない場合**: `claw-memory install --claude-code` で MCP サーバーと
133
+ > フックを `~/.claude/settings.json` にマージできます(冪等・バックアップ付き)。
134
+
135
+ ### 手順 2b — Codex(インストーラ)
136
+
137
+ Codex には第三者プラグインのマーケットプレイスが無いため、インストーラで登録します。
138
+
139
+ ```bash
140
+ claw-memory install --codex
141
+ ```
142
+
143
+ これは冪等に次を行います。
144
+
145
+ - `~/.codex/config.toml` に `[mcp_servers.claw-memory]` を追記(`config.toml.bak` にバックアップ)
146
+ - `memory-recall` skill を配置
147
+ - `AGENTS.md` に「セッション冒頭で `memory_recall` を呼ぶ」指示を追記
148
+
149
+ Codex を再起動してください。**Codex 側の自動 distill は手動のみ**(Stop フック相当が無い
150
+ ため)。定期的に自分で実行します。
151
+
152
+ ```bash
153
+ claw-memory distill-codex --recent # 最近の Codex セッションを蒸留(watermark で重複回避)
154
+ claw-memory distill-codex --all # 全件バックフィル
155
+ ```
156
+
157
+ ### 手順 2c — ソースから(開発)
158
+
159
+ ```bash
160
+ git clone https://github.com/nogataka/claw-memory
161
+ cd claw-memory
162
+ npm install # ネイティブの better-sqlite3 / sqlite-vec をビルド
163
+ npm run build # tsc -> dist/
164
+ npm link # 任意: `claw-memory` バイナリを公開
165
+ ```
166
+
167
+ ---
168
+
169
+ ## MCP ツール
170
+
171
+ | ツール | 用途 |
172
+ |--------|------|
173
+ | `memory_recall(query, cwd?, topK?)` | すぐ読めるコンテキストブロック: 好み + 直近要約 + 類似する過去会話。タスク開始時に呼ぶ。 |
174
+ | `memory_search(query, cwd?, limit?, type?, concept?, file?, dateFrom?, dateTo?)` | トークン軽量なヒットインデックス(id + タイトル + 日付 + type)。メタデータで絞り込み。 |
175
+ | `memory_get(ids)` | 指定 id の本文 + メタデータを取得。 |
176
+ | `memory_remember(text, cwd?, sessionId?)` | フリーテキストのメモを永続保存。 |
177
+ | `memory_distill(cwd, sessionId? \| transcriptPath?)` | セッションを要約して記憶化(LLM バックエンドが必要)。 |
178
+ | `memory_get_preferences(cwd?)` | プロジェクトの保存済み好みを一覧。 |
179
+ | `memory_search_logs(query, sources?, projectPath?, startDate?, endDate?, limit?, offset?)` | Claude Code + Codex の生ログを全文検索。 |
180
+ | `memory_forget(ids)` | チャンクをソフト削除(検索 / recall / ビューアから除外)。 |
181
+
182
+ `memory_distill`(LLM)と `memory_search_logs`(`~/.claude/projects`・`~/.codex/sessions`
183
+ を直接読む)以外は完全ローカルで動作します。
184
+
185
+ ---
186
+
187
+ ## 設定(環境変数)
188
+
189
+ | 変数 | 既定値 | 用途 |
190
+ |------|--------|------|
191
+ | `CLAW_MEMORY_DIR` | `~/.claw-memory` | データディレクトリ(`memory.db` と `logs/`)。 |
192
+ | `CLAW_MEMORY_LLM_BACKEND` | `agent-sdk` | `agent-sdk` \| `codex-sdk` \| `anthropic` \| `openai-compatible`。 |
193
+ | `CLAW_MEMORY_MODEL` / `AGENT_SDK_MODEL` | `claude-sonnet-4-5` | 既定の distill モデル(agent-sdk / anthropic)。 |
194
+ | `CLAW_MEMORY_TIER_SMART` / `_SUMMARY` / `_SIMPLE` | — | tier 別モデル上書き(安価モデルを単純作業へ)。 |
195
+ | `CLAW_MEMORY_CODEX_MODEL` | Codex 既定 | `codex-sdk` バックエンドのモデル。 |
196
+ | `CLAW_MEMORY_CODEX_API_KEY` | — | 任意。未設定なら Codex CLI のログインを使用。 |
197
+ | `ANTHROPIC_API_KEY` / `ANTHROPIC_BASE_URL` | — | `anthropic` バックエンド用。 |
198
+ | `CLAW_MEMORY_OPENAI_API_KEY` / `CLAW_MEMORY_OPENAI_BASE_URL` | — | `openai-compatible` 用(Gemini / OpenRouter / LM Studio)。 |
199
+ | `CLAW_MEMORY_EXCLUDED_PROJECTS` | — | 記録・想起しないパス部分文字列(カンマ/コロン区切り)。 |
200
+ | `MEMORY_SIMILARITY_MAX_DISTANCE` | `0.6` | セマンティックヒットの最大コサイン距離(小さいほど厳格)。 |
201
+ | `CLAW_MEMORY_UI_PORT` | `4319` | ビューアのポート。 |
202
+
203
+ ### LLM バックエンド
204
+
205
+ | バックエンド | 認証 | 備考 |
206
+ |--------------|------|------|
207
+ | `agent-sdk`(既定) | Claude CLI ログイン(Pro/Max/Team/Enterprise) | ゼロ設定・API キー不要 |
208
+ | `codex-sdk` | Codex CLI ログイン(ChatGPT/Codex プラン) | `@openai/codex-sdk`。read-only・ツール無効で実行 |
209
+ | `anthropic` | `ANTHROPIC_API_KEY` | fetch ベースの Messages API |
210
+ | `openai-compatible` | `CLAW_MEMORY_OPENAI_API_KEY` + ベース URL + `CLAW_MEMORY_MODEL` | Gemini / OpenRouter / LM Studio |
211
+
212
+ ```bash
213
+ export CLAW_MEMORY_LLM_BACKEND=codex-sdk # Codex サブスクリプションで distill
214
+ ```
215
+
216
+ ---
217
+
218
+ ## CLI リファレンス
219
+
220
+ ```bash
221
+ claw-memory mcp # stdio MCP サーバー(エージェントが起動するもの)
222
+ claw-memory ui [--port N] [--open] # 読み取り専用 Web ビューア
223
+ claw-memory distill --cwd P --session ID [--path FILE] [--if-stale]
224
+ claw-memory distill-codex [--recent] [--limit N] [--all]
225
+ claw-memory remember --cwd P "メモ"
226
+ claw-memory search-logs "クエリ" [--source claude-code,codex] [--project P]
227
+ [--start ISO] [--end ISO] [--limit N] [--offset N]
228
+ claw-memory hook <recall|distill> # ライフサイクルフック(JSON を stdin で受領)
229
+ claw-memory install [--codex | --claude-code] # MCP + フックを登録(既定: codex)
230
+ claw-memory uninstall [--codex | --claude-code]
231
+ ```
232
+
233
+ ---
234
+
235
+ ## 仕組み
236
+
237
+ ```
238
+ [書き込み側] [読み出し側]
239
+ セッション終了 (Stop フック / distill-codex) セッション開始 (SessionStart フック / memory_recall)
240
+ └ distill └ buildMemoryBlock
241
+ ├ 要約 ───────────────► session_summaries ──► <previous-session-summaries>
242
+ ├ 好み ───────────────► user_preferences ───► <user-preferences>(always-apply)
243
+ └ チャンク(埋込+メタ) ─► vec_chunks + ────────► <relevant-past-conversations>
244
+ conversation_chunks (コサイン KNN・プロジェクト/メタ絞り込み)
245
+
246
+ [別ソース] 生ログ (~/.claude/projects, ~/.codex/sessions) ──► memory_search_logs
247
+ ```
248
+
249
+ - **単一の SQLite ファイル** `~/.claw-memory/memory.db`。`sqlite-vec` が 384 次元ベクトルを
250
+ 内包し、メタデータは並列テーブル、FTS5 がキーワード fallback を提供。
251
+ - **埋め込み** はローカルの `Xenova/multilingual-e5-small`(多言語・オフライン・e5 の
252
+ `query:`/`passage:` プレフィックス遵守)。モデルは MCP プロセスごとに 1 回ロード。
253
+ - **検索** はハイブリッド: コサイン KNN(プロジェクト + メタデータで絞り込み)を FTS5 の
254
+ キーワードヒットで補強し、重複排除して距離順にソート。
255
+ - 構造化された日次ログを `~/.claw-memory/logs/` に出力。
256
+
257
+ ---
258
+
259
+ ## メモリビューア
260
+
261
+ ```bash
262
+ claw-memory ui --open # http://localhost:4319
263
+ ```
264
+
265
+ 読み取り専用。プロジェクト・要約・会話チャンク(type / concepts / files 付き)・好みを
266
+ 閲覧でき、**🔎 ログ検索** で Claude Code + Codex の生ログを全文検索できます。開いている間
267
+ は SSE で自動更新。それ以外はバックグラウンドで何も動きません — 確認したい時だけ起動して
268
+ ください。
269
+
270
+ ---
271
+
272
+ ## アンインストール
273
+
274
+ ```bash
275
+ claw-memory uninstall --codex # config.toml ブロック + skill + AGENTS 記述を除去
276
+ claw-memory uninstall --claude-code # settings.json から mcp + フックを除去
277
+ # Claude Code プラグイン: /plugin uninstall claw-memory
278
+ npm uninstall -g @nogataka/claw-memory
279
+ ```
280
+
281
+ メモリ DB は残ります。完全に消す場合は `~/.claw-memory` を削除してください。
282
+
283
+ ---
284
+
285
+ ## 補足
286
+
287
+ - `better-sqlite3` / `sqlite-vec` はネイティブモジュールです。Node の ABI 変更後は `npm rebuild` を実行してください。
288
+ - MCP サーバーはエージェントセッションごとに常駐するため、埋め込みモデルは 1 回だけロードされます。
289
+ - ビューアと MCP は同時実行できます(SQLite WAL が並行読み書きを処理)。
290
+ - インストール時、依存は `legacy-peer-deps=true` で解決されます(同梱 SDK 間の zod の
291
+ peer 範囲の重なりによるもの)。`.npmrc` に設定済みで無害です。
package/README.md CHANGED
@@ -1,168 +1,296 @@
1
1
  # claw-memory
2
2
 
3
- Independent, **in-process** semantic memory for any MCP-capable agent (Claude Code, Codex, …).
4
- No daemon, no Python, no external vector DB.
3
+ **English** | [日本語](README.ja.md)
5
4
 
6
- - **Storage**: `better-sqlite3` + `sqlite-vec` (vectors live *inside* the SQLite file)
5
+ **Local, in-process long-term memory for AI coding agents (Claude Code & Codex).**
6
+ Your agent remembers past sessions, your preferences, and prior decisions — and can
7
+ search every raw transcript you've ever recorded. No daemon, no Python, no external
8
+ vector database, no data leaving your machine (except the LLM call that summarizes a
9
+ session, which you control).
10
+
11
+ ```bash
12
+ npm install -g @nogataka/claw-memory
13
+ ```
14
+
15
+ - **Storage**: `better-sqlite3` + `sqlite-vec` — vectors live *inside* one SQLite file
7
16
  - **Embeddings**: local `Xenova/multilingual-e5-small` (384-dim, multilingual, offline)
8
- - **Search**: semantic (cosine KNN, per-project metadata filter) + FTS5 keyword fallback
9
- - **Write**: LLM distillation of session transcripts → summary + preferences + chunks
10
- - **Viewer**: optional, on-demand lightweight web UI (no framework, no build)
17
+ - **Two memory sources**: a distilled semantic DB **and** full-text search over raw
18
+ Claude Code + Codex transcripts
19
+ - **Auto-capture**: lifecycle hooks distill finished sessions and inject relevant memory
20
+ back into new ones
21
+ - **Pluggable LLM**: distill via your Claude or Codex subscription (no API key), or any
22
+ Anthropic / OpenAI-compatible endpoint
23
+
24
+ ---
25
+
26
+ ## Table of contents
27
+
28
+ - [Features](#features)
29
+ - [Installation guide](#installation-guide)
30
+ - [MCP tools](#mcp-tools)
31
+ - [Configuration](#configuration-environment-variables)
32
+ - [CLI reference](#cli-reference)
33
+ - [How it works](#how-it-works)
34
+ - [Memory viewer](#memory-viewer)
35
+ - [Uninstall](#uninstall)
36
+ - [Notes](#notes)
37
+
38
+ ---
39
+
40
+ ## Features
41
+
42
+ ### 1. Two independent memory sources
43
+
44
+ | Source | What it is | Tooling |
45
+ |--------|-----------|---------|
46
+ | **Distilled DB** | LLM-summarized sessions → summaries, preferences, and embedded conversation chunks with structured metadata. Semantically searchable. | `memory_recall`, `memory_search`, `memory_get` |
47
+ | **Raw transcript search** | Full-text grep over your *actual* Claude Code (`~/.claude/projects`) and Codex (`~/.codex/sessions`) logs — including sessions that were never distilled. | `memory_search_logs` |
48
+
49
+ The distilled DB is curated and fast to recall; raw search is a safety net that finds
50
+ anything you ever discussed, even before claw-memory was installed.
51
+
52
+ ### 2. Automatic capture (distill)
53
+
54
+ When a session ends, claw-memory distills the transcript into:
55
+
56
+ - a **structured summary** (`### 依頼 / 調査・判明 / 完了 / 次の一手`),
57
+ - **user preferences** (language, response style, frameworks, tone, …) applied as
58
+ always-on context,
59
+ - **conversation chunks** embedded for semantic search, each tagged with an
60
+ **observation type** (`discovery` / `bugfix` / `feature` / `decision` / `change`),
61
+ **concepts**, and **files read / modified**.
62
+
63
+ Distillation is **incremental** (a watermark skips sessions with no new content) and
64
+ **idempotent** (re-distilling a session replaces, never duplicates). Cross-session
65
+ duplicate chunks are dropped.
66
+
67
+ ### 3. Automatic recall injection
68
+
69
+ At the start of a session (and on each prompt), claw-memory injects a memory block:
70
+
71
+ - **Preferences** as `instruction="always-apply"` — the agent follows them.
72
+ - **Recent summaries + semantically similar past conversations** as
73
+ `instruction="reference-only"` — used as background, not parroted back.
74
+
75
+ This means the agent picks up where you left off without you re-explaining context.
76
+
77
+ ### 4. Structured, filterable search
78
+
79
+ `memory_search` returns a token-light index (id + title + date + type). Filter by
80
+ `type`, `concept`, `file`, or date range, then pull full bodies with `memory_get` only
81
+ for what you need — keeping context usage minimal.
82
+
83
+ ### 5. Privacy & safety, by design
84
+
85
+ - **Fully local**: storage and embeddings never leave your machine. Only `distill`
86
+ calls an LLM, and you choose which one.
87
+ - **`<private>…</private>`** spans are stripped before anything is persisted or sent
88
+ to the LLM.
89
+ - **`CLAW_MEMORY_EXCLUDED_PROJECTS`**: never record or recall listed paths.
90
+ - **`memory_forget`**: soft-delete chunks; they vanish from search, recall, and the viewer.
91
+
92
+ ### 6. Pluggable LLM backend (distill only)
11
93
 
12
- Data lives at `~/.claw-memory/memory.db` (override with `CLAW_MEMORY_DIR`). Completely
13
- separate from any other app.
94
+ Use a subscription login (no API key) or any HTTP endpoint — see
95
+ [Configuration](#configuration-environment-variables). Tier routing lets cheap models
96
+ handle the high-frequency distill work.
14
97
 
15
- ## Install
98
+ ### 7. On-demand web viewer
16
99
 
17
- Published as `@nogataka/claw-memory`. Install once globally so hooks/MCP resolve fast
18
- (otherwise they fall back to `npx`):
100
+ A zero-build, read-only viewer (`claw-memory ui`) to browse projects, summaries,
101
+ chunks (with their metadata), preferences, and to run raw-log search — with live
102
+ updates via SSE. It runs only when you start it.
103
+
104
+ ---
105
+
106
+ ## Installation guide
107
+
108
+ ### Prerequisites
109
+
110
+ - **Node.js ≥ 20**
111
+ - For the subscription LLM backends: **Claude Code CLI** (logged in) and/or **Codex CLI** (logged in)
112
+ - First `distill` downloads the embedding model (~100 MB, cached under `~/.cache`)
113
+
114
+ ### Step 1 — install the package globally
19
115
 
20
116
  ```bash
21
117
  npm install -g @nogataka/claw-memory
22
118
  ```
23
119
 
24
- First run downloads the e5 model (~100 MB, cached in `~/.cache`).
120
+ Installing globally makes hooks and the MCP server start instantly. (Without it, the
121
+ plugin falls back to `npx -y @nogataka/claw-memory@latest`, which is slower on first run.)
25
122
 
26
- ### Claude Code (plugin)
123
+ ### Step 2a — Claude Code (plugin, recommended)
27
124
 
28
- ```
125
+ ```text
29
126
  /plugin marketplace add nogataka/claw-memory
30
127
  /plugin install claw-memory
31
128
  ```
32
129
 
33
- Restart Claude Code. This auto-registers the MCP server and the hooks
34
- (SessionStart/UserPromptSubmit → recall injection, Stop → auto-distill).
35
- No manual setup. (Not using the plugin? Run `claw-memory install --claude-code`
36
- to merge the MCP server + hooks into `~/.claude/settings.json`.)
130
+ Restart Claude Code. This auto-registers:
131
+
132
+ - the **MCP server** (8 memory tools), and
133
+ - the **hooks**: `SessionStart` / `UserPromptSubmit` recall injection, `Stop` → auto-distill.
37
134
 
38
- ### Codex (installer)
135
+ No manual config. To verify, run `/mcp` and look for `claw-memory`.
136
+
137
+ > **Not using the plugin?** Run `claw-memory install --claude-code` to merge the MCP
138
+ > server and hooks into `~/.claude/settings.json` (idempotent, backs up the file).
139
+
140
+ ### Step 2b — Codex (installer)
39
141
 
40
142
  Codex has no third-party plugin marketplace, so register via the installer:
41
143
 
42
144
  ```bash
43
- claw-memory install --codex # adds [mcp_servers.claw-memory] to ~/.codex/config.toml
44
- # + memory-recall skill + AGENTS.md recall instruction
145
+ claw-memory install --codex
45
146
  ```
46
147
 
47
- Restart Codex. Recall is available via the `memory_recall` MCP tool (the AGENTS.md
48
- note tells the agent to call it at session start). **Auto-distill is manual on Codex**
49
- (no notify hook); run periodically:
148
+ This idempotently:
149
+
150
+ - adds `[mcp_servers.claw-memory]` to `~/.codex/config.toml` (backed up to `config.toml.bak`),
151
+ - installs the `memory-recall` skill, and
152
+ - appends an `AGENTS.md` instruction telling the agent to call `memory_recall` at session start.
153
+
154
+ Restart Codex. **Auto-distill is manual on Codex** (no equivalent of the Stop hook) — run
155
+ it yourself periodically:
50
156
 
51
157
  ```bash
52
158
  claw-memory distill-codex --recent # distill recent Codex sessions (watermark-deduped)
53
159
  claw-memory distill-codex --all # backfill everything
54
160
  ```
55
161
 
56
- Remove with `claw-memory uninstall --codex` (or `--claude-code`).
57
-
58
- ### From source
162
+ ### Step 2c from source (development)
59
163
 
60
164
  ```bash
165
+ git clone https://github.com/nogataka/claw-memory
61
166
  cd claw-memory
62
- npm install # builds native better-sqlite3 / sqlite-vec
63
- npm run build # tsc -> dist/
167
+ npm install # builds native better-sqlite3 / sqlite-vec
168
+ npm run build # tsc -> dist/
169
+ npm link # optional: expose the `claw-memory` binary
64
170
  ```
65
171
 
172
+ ---
173
+
66
174
  ## MCP tools
67
175
 
68
176
  | Tool | Purpose |
69
177
  |------|---------|
70
- | `memory_recall(query, cwd?, topK?)` | Ready-to-read context block: preferences + summaries + similar past conversations |
71
- | `memory_search(query, cwd?, limit?)` | Token-efficient hit index (id + title + date) |
72
- | `memory_get(ids)` | Full text for given chunk ids |
73
- | `memory_remember(text, cwd?, sessionId?)` | Store a free-text note |
74
- | `memory_distill(cwd, sessionId? \| transcriptPath?)` | Summarize a session into memory (needs LLM creds) |
75
- | `memory_get_preferences(cwd?)` | List stored preferences |
76
- | `memory_search_logs(query, sources?, projectPath?, startDate?, endDate?, limit?, offset?)` | Full-text search over RAW Claude Code + Codex transcripts (second memory source; finds undistilled history) |
77
- | `memory_forget(ids)` | Soft-delete chunks (hidden from search/recall/viewer) |
78
-
79
- `memory_distill` uses an LLM (see *LLM backend* below). `memory_search_logs` reads
80
- `~/.claude/projects` and `~/.codex/sessions` directly. All other tools are fully local.
81
-
82
- ## LLM backend (distill only)
83
-
84
- distill needs a single tool-less completion, selectable via `CLAW_MEMORY_LLM_BACKEND`:
178
+ | `memory_recall(query, cwd?, topK?)` | Ready-to-read context block: preferences + recent summaries + similar past conversations. Call at the start of a task. |
179
+ | `memory_search(query, cwd?, limit?, type?, concept?, file?, dateFrom?, dateTo?)` | Token-light hit index (id + title + date + type), with metadata filters. |
180
+ | `memory_get(ids)` | Full text + metadata for given chunk ids. |
181
+ | `memory_remember(text, cwd?, sessionId?)` | Store a durable free-text note. |
182
+ | `memory_distill(cwd, sessionId? \| transcriptPath?)` | Summarize a session into memory (needs an LLM backend). |
183
+ | `memory_get_preferences(cwd?)` | List stored preferences for the project. |
184
+ | `memory_search_logs(query, sources?, projectPath?, startDate?, endDate?, limit?, offset?)` | Full-text search over RAW Claude Code + Codex transcripts. |
185
+ | `memory_forget(ids)` | Soft-delete chunks (hidden from search / recall / viewer). |
186
+
187
+ All tools are fully local except `memory_distill` (LLM) and `memory_search_logs`
188
+ (reads `~/.claude/projects` and `~/.codex/sessions` directly).
189
+
190
+ ---
191
+
192
+ ## Configuration (environment variables)
193
+
194
+ | Variable | Default | Purpose |
195
+ |----------|---------|---------|
196
+ | `CLAW_MEMORY_DIR` | `~/.claw-memory` | Data directory (holds `memory.db` and `logs/`). |
197
+ | `CLAW_MEMORY_LLM_BACKEND` | `agent-sdk` | `agent-sdk` \| `codex-sdk` \| `anthropic` \| `openai-compatible`. |
198
+ | `CLAW_MEMORY_MODEL` / `AGENT_SDK_MODEL` | `claude-sonnet-4-5` | Default distill model (agent-sdk / anthropic). |
199
+ | `CLAW_MEMORY_TIER_SMART` / `_SUMMARY` / `_SIMPLE` | — | Per-tier model override (route cheap models to simple work). |
200
+ | `CLAW_MEMORY_CODEX_MODEL` | Codex default | Model for the `codex-sdk` backend. |
201
+ | `CLAW_MEMORY_CODEX_API_KEY` | — | Optional; otherwise the Codex CLI login is used. |
202
+ | `ANTHROPIC_API_KEY` / `ANTHROPIC_BASE_URL` | — | For the `anthropic` backend. |
203
+ | `CLAW_MEMORY_OPENAI_API_KEY` / `CLAW_MEMORY_OPENAI_BASE_URL` | — | For the `openai-compatible` backend (Gemini / OpenRouter / LM Studio). |
204
+ | `CLAW_MEMORY_EXCLUDED_PROJECTS` | — | Comma/colon-separated path substrings to never record or recall. |
205
+ | `MEMORY_SIMILARITY_MAX_DISTANCE` | `0.6` | Max cosine distance for a semantic hit (lower = stricter). |
206
+ | `CLAW_MEMORY_UI_PORT` | `4319` | Viewer port. |
207
+
208
+ ### LLM backends
85
209
 
86
210
  | Backend | Auth | Notes |
87
211
  |---------|------|-------|
88
- | `agent-sdk` (default) | Claude Code CLI login (Claude Pro/Max/Team/Enterprise) | zero-config, no API key |
89
- | `codex-sdk` | Codex CLI login (ChatGPT/Codex plan) | `@openai/codex-sdk`, no API key; requires Codex CLI. Model via `CLAW_MEMORY_CODEX_MODEL` |
90
- | `anthropic` | `ANTHROPIC_API_KEY` (`ANTHROPIC_BASE_URL` optional) | plain Messages API |
91
- | `openai-compatible` | `CLAW_MEMORY_OPENAI_API_KEY` + `CLAW_MEMORY_OPENAI_BASE_URL` | Gemini / OpenRouter / LM Studio (set `CLAW_MEMORY_MODEL`) |
212
+ | `agent-sdk` (default) | Claude CLI login (Pro/Max/Team/Enterprise) | zero-config, no API key |
213
+ | `codex-sdk` | Codex CLI login (ChatGPT/Codex plan) | `@openai/codex-sdk`; runs read-only, no tools |
214
+ | `anthropic` | `ANTHROPIC_API_KEY` | plain Messages API over fetch |
215
+ | `openai-compatible` | `CLAW_MEMORY_OPENAI_API_KEY` + base URL + `CLAW_MEMORY_MODEL` | Gemini / OpenRouter / LM Studio |
92
216
 
93
217
  ```bash
94
- export CLAW_MEMORY_LLM_BACKEND=codex-sdk # use the Codex subscription for distill
218
+ export CLAW_MEMORY_LLM_BACKEND=codex-sdk # distill using the Codex subscription
95
219
  ```
96
220
 
97
- Both SDK backends reuse a subscription login (no API key). Tier routing (cheap models for
98
- simple work): `CLAW_MEMORY_TIER_SMART` / `_SUMMARY` / `_SIMPLE`, else `AGENT_SDK_MODEL` /
99
- `CLAW_MEMORY_MODEL` (agent-sdk/anthropic default `claude-sonnet-4-5`; codex-sdk uses the Codex default).
221
+ ---
100
222
 
101
- ## Automatic capture & recall (Claude Code hooks)
223
+ ## CLI reference
102
224
 
103
- No daemon — hooks spawn the CLI per event. Register in `~/.claude/settings.json`:
104
-
105
- ```json
106
- {
107
- "hooks": {
108
- "SessionStart": [{ "hooks": [{ "type": "command", "command": "/Volumes/Data/dev/claw-memory/hooks/claw-hook.sh recall" }] }],
109
- "UserPromptSubmit": [{ "hooks": [{ "type": "command", "command": "/Volumes/Data/dev/claw-memory/hooks/claw-hook.sh recall" }] }],
110
- "Stop": [{ "hooks": [{ "type": "command", "command": "/Volumes/Data/dev/claw-memory/hooks/claw-hook.sh distill" }] }]
111
- }
112
- }
225
+ ```bash
226
+ claw-memory mcp # stdio MCP server (what agents spawn)
227
+ claw-memory ui [--port N] [--open] # read-only web viewer
228
+ claw-memory distill --cwd P --session ID [--path FILE] [--if-stale]
229
+ claw-memory distill-codex [--recent] [--limit N] [--all]
230
+ claw-memory remember --cwd P "a note"
231
+ claw-memory search-logs "query" [--source claude-code,codex] [--project P]
232
+ [--start ISO] [--end ISO] [--limit N] [--offset N]
233
+ claw-memory hook <recall|distill> # lifecycle hook (reads JSON on stdin)
234
+ claw-memory install [--codex | --claude-code] # register MCP + hooks (default: codex)
235
+ claw-memory uninstall [--codex | --claude-code]
113
236
  ```
114
237
 
115
- - **recall** (SessionStart / UserPromptSubmit): prints the memory block to stdout → injected into context. Preferences + recent summaries, plus semantically similar past conversations when the prompt is present.
116
- - **distill** (Stop): detached, fire-and-forget. Incremental via a watermark (skips sessions with no new content). Honors `CLAW_MEMORY_EXCLUDED_PROJECTS` and `<private>…</private>`.
117
-
118
- ## Register with an agent
238
+ ---
119
239
 
120
- ### Claude Code — `.mcp.json` (project root) or `~/.claude.json`
240
+ ## How it works
121
241
 
122
- ```json
123
- {
124
- "mcpServers": {
125
- "memory": {
126
- "command": "node",
127
- "args": ["/Volumes/Data/dev/claw-memory/dist/cli.js", "mcp"]
128
- }
129
- }
130
- }
131
242
  ```
132
-
133
- ### Codex `~/.codex/config.toml`
134
-
135
- ```toml
136
- [mcp_servers.memory]
137
- command = "node"
138
- args = ["/Volumes/Data/dev/claw-memory/dist/cli.js", "mcp"]
243
+ [write path] [read path]
244
+ session ends (Stop hook / distill-codex) session starts (SessionStart hook / memory_recall)
245
+ └ distill └ buildMemoryBlock
246
+ ├ summary ───────────► session_summaries ──► <previous-session-summaries>
247
+ ├ preferences ────────► user_preferences ───► <user-preferences> (always-apply)
248
+ chunks (embed+meta) ─► vec_chunks + ────────► <relevant-past-conversations>
249
+ conversation_chunks (cosine KNN, per-project, filtered)
250
+
251
+ [separate source] raw logs (~/.claude/projects, ~/.codex/sessions) ──► memory_search_logs
139
252
  ```
140
253
 
141
- Then add to your `CLAUDE.md` / `AGENTS.md`:
142
- > 会話の冒頭で `memory_recall` を呼び、過去の文脈と好みを取得すること。
254
+ - **One SQLite file** at `~/.claw-memory/memory.db`. `sqlite-vec` stores 384-dim vectors
255
+ inside it; metadata lives in a parallel table; FTS5 provides a keyword fallback.
256
+ - **Embeddings** run locally via `Xenova/multilingual-e5-small` (multilingual, offline,
257
+ e5 `query:`/`passage:` prefixing). The model loads once per MCP process.
258
+ - **Search** is hybrid: cosine KNN (filtered by project + metadata) augmented with FTS5
259
+ keyword hits, de-duplicated and distance-sorted.
260
+ - Daily structured logs are written to `~/.claw-memory/logs/`.
261
+
262
+ ---
143
263
 
144
264
  ## Memory viewer
145
265
 
146
266
  ```bash
147
- npm run ui # http://localhost:4319 , opens browser
148
- # or
149
- node dist/cli.js ui --port 4319 --open
267
+ claw-memory ui --open # http://localhost:4319
150
268
  ```
151
269
 
152
- Read-only. Browse projects, session summaries, conversation chunks and preferences.
153
- Start it only when you want to inspect; nothing runs in the background otherwise.
270
+ Read-only. Browse projects, session summaries, conversation chunks (with type /
271
+ concepts / files), and preferences; toggle **🔎 ログ検索** to full-text search raw
272
+ Claude Code + Codex transcripts. Live-updates via SSE while open. Nothing runs in the
273
+ background otherwise — start it only when you want to inspect.
154
274
 
155
- ## CLI
275
+ ---
276
+
277
+ ## Uninstall
156
278
 
157
279
  ```bash
158
- node dist/cli.js mcp # stdio MCP server
159
- node dist/cli.js ui [--port N] [--open] # viewer
160
- node dist/cli.js distill --cwd <dir> --session <id> # distill a CC session
161
- node dist/cli.js remember --cwd <dir> "a note" # store a note
280
+ claw-memory uninstall --codex # remove config.toml block + skill + AGENTS note
281
+ claw-memory uninstall --claude-code # remove mcp + hooks from settings.json
282
+ # Claude Code plugin: /plugin uninstall claw-memory
283
+ npm uninstall -g @nogataka/claw-memory
162
284
  ```
163
285
 
286
+ Your memory database is left untouched; delete `~/.claw-memory` to wipe it.
287
+
288
+ ---
289
+
164
290
  ## Notes
165
291
 
166
- - `better-sqlite3` / `sqlite-vec` are native; rebuild on Node ABI changes (`npm rebuild`).
292
+ - `better-sqlite3` / `sqlite-vec` are native modules; run `npm rebuild` after a Node ABI change.
167
293
  - The MCP server is long-lived per agent session, so the embedding model loads once.
168
- - Viewer + MCP can run simultaneously (SQLite WAL handles concurrent read/write).
294
+ - Viewer + MCP can run simultaneously SQLite WAL handles concurrent read/write.
295
+ - On install, dependencies resolve with `legacy-peer-deps=true` (a zod peer-range overlap
296
+ between bundled SDKs); this is configured in `.npmrc` and is harmless.
package/hooks/hooks.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "hooks": [
6
6
  {
7
7
  "type": "command",
8
- "command": "'${CLAUDE_PLUGIN_ROOT}/hooks/run-hook.cmd' claw-hook.sh hook recall",
8
+ "command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/run-hook.cmd\" claw-hook.sh hook recall",
9
9
  "async": false
10
10
  }
11
11
  ]
@@ -16,7 +16,7 @@
16
16
  "hooks": [
17
17
  {
18
18
  "type": "command",
19
- "command": "'${CLAUDE_PLUGIN_ROOT}/hooks/run-hook.cmd' claw-hook.sh hook recall",
19
+ "command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/run-hook.cmd\" claw-hook.sh hook recall",
20
20
  "async": false
21
21
  }
22
22
  ]
@@ -27,7 +27,7 @@
27
27
  "hooks": [
28
28
  {
29
29
  "type": "command",
30
- "command": "'${CLAUDE_PLUGIN_ROOT}/hooks/run-hook.cmd' claw-hook.sh hook distill",
30
+ "command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/run-hook.cmd\" claw-hook.sh hook distill",
31
31
  "async": true
32
32
  }
33
33
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nogataka/claw-memory",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "description": "Independent, in-process semantic memory MCP server (sqlite-vec + local Xenova e5) with a lightweight web viewer. No daemon, no Python. Installable as a Claude Code plugin and a Codex MCP server.",
6
6
  "license": "MIT",
@@ -27,7 +27,8 @@
27
27
  "skills",
28
28
  ".claude-plugin",
29
29
  ".mcp.json",
30
- "README.md"
30
+ "README.md",
31
+ "README.ja.md"
31
32
  ],
32
33
  "engines": {
33
34
  "node": ">=20.0.0"