claude-mem 10.6.2 → 10.7.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.
@@ -0,0 +1,462 @@
1
+ # Claude-Mem OpenClaw Plugin — Setup Guide
2
+
3
+ This guide walks through setting up the claude-mem plugin on an OpenClaw gateway. By the end, your agents will have persistent memory across sessions via system prompt context injection, and optionally a real-time observation feed streaming to a messaging channel.
4
+
5
+ ## Quick Install (Recommended)
6
+
7
+ Run this one-liner to install everything automatically:
8
+
9
+ ```bash
10
+ curl -fsSL https://install.cmem.ai/openclaw.sh | bash
11
+ ```
12
+
13
+ The installer handles dependency checks (Bun, uv), plugin installation, memory slot configuration, AI provider setup, worker startup, and optional observation feed configuration — all interactively.
14
+
15
+ ### Install with options
16
+
17
+ Pre-select your AI provider and API key to skip interactive prompts:
18
+
19
+ ```bash
20
+ curl -fsSL https://install.cmem.ai/openclaw.sh | bash -s -- --provider=gemini --api-key=YOUR_KEY
21
+ ```
22
+
23
+ For fully unattended installation (defaults to Claude Max Plan, skips observation feed):
24
+
25
+ ```bash
26
+ curl -fsSL https://install.cmem.ai/openclaw.sh | bash -s -- --non-interactive
27
+ ```
28
+
29
+ To upgrade an existing installation (preserves settings, updates plugin):
30
+
31
+ ```bash
32
+ curl -fsSL https://install.cmem.ai/openclaw.sh | bash -s -- --upgrade
33
+ ```
34
+
35
+ After installation, skip to [Step 4: Restart the Gateway and Verify](#step-4-restart-the-gateway-and-verify) to confirm everything is working.
36
+
37
+ ---
38
+
39
+ ## Manual Setup
40
+
41
+ The steps below are for manual installation if you prefer not to use the automated installer, or need to troubleshoot individual steps.
42
+
43
+ ### Step 1: Clone the Claude-Mem Repo
44
+
45
+ First, clone the claude-mem repository to a location accessible by your OpenClaw gateway. This gives you the worker service source and the plugin code.
46
+
47
+ ```bash
48
+ cd /opt # or wherever you want to keep it
49
+ git clone https://github.com/thedotmack/claude-mem.git
50
+ cd claude-mem
51
+ npm install
52
+ npm run build
53
+ ```
54
+
55
+ You'll need **bun** installed for the worker service. If you don't have it:
56
+
57
+ ```bash
58
+ curl -fsSL https://bun.sh/install | bash
59
+ ```
60
+
61
+ ### Step 2: Get the Worker Running
62
+
63
+ The claude-mem worker is an HTTP service on port 37777. It stores observations, generates summaries, and serves the context timeline. The plugin talks to it over HTTP — it doesn't matter where the worker is running, just that it's reachable on localhost:37777.
64
+
65
+ #### Check if it's already running
66
+
67
+ If this machine also runs Claude Code with claude-mem installed, the worker may already be running:
68
+
69
+ ```bash
70
+ curl http://localhost:37777/api/health
71
+ ```
72
+
73
+ **Got `{"status":"ok"}`?** The worker is already running. Skip to Step 3.
74
+
75
+ **Got connection refused or no response?** The worker isn't running. Continue below.
76
+
77
+ #### If Claude Code has claude-mem installed
78
+
79
+ If claude-mem is installed as a Claude Code plugin (at `~/.claude/plugins/marketplaces/thedotmack/`), start the worker from that installation:
80
+
81
+ ```bash
82
+ cd ~/.claude/plugins/marketplaces/thedotmack
83
+ npm run worker:restart
84
+ ```
85
+
86
+ Verify:
87
+ ```bash
88
+ curl http://localhost:37777/api/health
89
+ ```
90
+
91
+ **Got `{"status":"ok"}`?** You're set. Skip to Step 3.
92
+
93
+ **Still not working?** Check `npm run worker:status` for error details, or check that bun is installed and on your PATH.
94
+
95
+ #### If there's no Claude Code installation
96
+
97
+ Run the worker from the cloned repo:
98
+
99
+ ```bash
100
+ cd /opt/claude-mem # wherever you cloned it
101
+ npm run worker:start
102
+ ```
103
+
104
+ Verify:
105
+ ```bash
106
+ curl http://localhost:37777/api/health
107
+ ```
108
+
109
+ **Got `{"status":"ok"}`?** You're set. Move to Step 3.
110
+
111
+ **Still not working?** Debug steps:
112
+ - Check that bun is installed: `bun --version`
113
+ - Check the worker status: `npm run worker:status`
114
+ - Check if something else is using port 37777: `lsof -i :37777`
115
+ - Check logs: `npm run worker:logs` (if available)
116
+ - Try running it directly to see errors: `bun plugin/scripts/worker-service.cjs start`
117
+
118
+ ### Step 3: Add the Plugin to Your Gateway
119
+
120
+ Add the `claude-mem` plugin to your OpenClaw gateway configuration:
121
+
122
+ ```json
123
+ {
124
+ "plugins": {
125
+ "claude-mem": {
126
+ "enabled": true,
127
+ "config": {
128
+ "project": "my-project",
129
+ "syncMemoryFile": true,
130
+ "workerPort": 37777
131
+ }
132
+ }
133
+ }
134
+ }
135
+ ```
136
+
137
+ #### Config fields explained
138
+
139
+ - **`project`** (string, default: `"openclaw"`) — The project name that scopes all observations in the memory database. Use a unique name per gateway/use-case so observations don't mix. For example, if this gateway runs a coding bot, use `"coding-bot"`.
140
+
141
+ - **`syncMemoryFile`** (boolean, default: `true`) — When enabled, the plugin injects the observation timeline into each agent's system prompt via the `before_prompt_build` hook. This gives agents cross-session context without writing to MEMORY.md. Set to `false` to disable context injection entirely (observations are still recorded).
142
+
143
+ - **`syncMemoryFileExclude`** (string[], default: `[]`) — Agent IDs excluded from automatic context injection. Useful for agents that curate their own memory. Observations are still recorded for excluded agents.
144
+
145
+ - **`workerPort`** (number, default: `37777`) — The port where the claude-mem worker service is listening. Only change this if you configured the worker to use a different port.
146
+
147
+ ---
148
+
149
+ ## Step 4: Restart the Gateway and Verify
150
+
151
+ Restart your OpenClaw gateway so it picks up the new plugin configuration. After restart, check the gateway logs for:
152
+
153
+ ```
154
+ [claude-mem] OpenClaw plugin loaded — v1.0.0 (worker: 127.0.0.1:37777)
155
+ ```
156
+
157
+ If you see this, the plugin is loaded. You can also verify by running `/claude_mem_status` in any OpenClaw chat:
158
+
159
+ ```
160
+ Claude-Mem Worker Status
161
+ Status: ok
162
+ Port: 37777
163
+ Active sessions: 0
164
+ Observation feed: disconnected
165
+ ```
166
+
167
+ The observation feed shows `disconnected` because we haven't configured it yet. That's next.
168
+
169
+ ## Step 5: Verify Observations Are Being Recorded
170
+
171
+ Have an agent do some work. The plugin automatically records observations through these OpenClaw events:
172
+
173
+ 1. **`before_agent_start`** — Initializes a claude-mem session when the agent starts
174
+ 2. **`before_prompt_build`** — Injects the observation timeline into the agent's system prompt (cached for 60s)
175
+ 3. **`tool_result_persist`** — Records each tool use (Read, Write, Bash, etc.) as an observation
176
+ 4. **`agent_end`** — Summarizes the session and marks it complete
177
+
178
+ All of this happens automatically. No additional configuration needed.
179
+
180
+ To verify it's working, check the worker's viewer UI at http://localhost:37777 to see observations appearing after the agent runs.
181
+
182
+ You can also check the worker's viewer UI at http://localhost:37777 to see observations appearing in real time.
183
+
184
+ ## Step 6: Set Up the Observation Feed (Streaming to a Channel)
185
+
186
+ The observation feed connects to the claude-mem worker's SSE (Server-Sent Events) stream and forwards every new observation to a messaging channel in real time. Your agents learn things, and you see them learning in your Telegram/Discord/Slack/etc.
187
+
188
+ ### What you'll see
189
+
190
+ Every time claude-mem creates a new observation from your agent's tool usage, a message like this appears in your channel:
191
+
192
+ ```
193
+ 🧠 Claude-Mem Observation
194
+ **Implemented retry logic for API client**
195
+ Added exponential backoff with configurable max retries to handle transient failures
196
+ ```
197
+
198
+ ### Pick your channel
199
+
200
+ You need two things:
201
+ - **Channel type** — Must match a channel plugin already running on your OpenClaw gateway
202
+ - **Target ID** — The chat/channel/user ID where messages go
203
+
204
+ #### Telegram
205
+
206
+ Channel type: `telegram`
207
+
208
+ To find your chat ID:
209
+ 1. Message @userinfobot on Telegram — https://t.me/userinfobot
210
+ 2. It replies with your numeric chat ID (e.g., `123456789`)
211
+ 3. For group chats, the ID is negative (e.g., `-1001234567890`)
212
+
213
+ ```json
214
+ "observationFeed": {
215
+ "enabled": true,
216
+ "channel": "telegram",
217
+ "to": "123456789"
218
+ }
219
+ ```
220
+
221
+ #### Discord
222
+
223
+ Channel type: `discord`
224
+
225
+ To find your channel ID:
226
+ 1. Enable Developer Mode in Discord: Settings → Advanced → Developer Mode
227
+ 2. Right-click the target channel → Copy Channel ID
228
+
229
+ ```json
230
+ "observationFeed": {
231
+ "enabled": true,
232
+ "channel": "discord",
233
+ "to": "1234567890123456789"
234
+ }
235
+ ```
236
+
237
+ #### Slack
238
+
239
+ Channel type: `slack`
240
+
241
+ To find your channel ID (not the channel name):
242
+ 1. Open the channel in Slack
243
+ 2. Click the channel name at the top
244
+ 3. Scroll to the bottom of the channel details — the ID looks like `C01ABC2DEFG`
245
+
246
+ ```json
247
+ "observationFeed": {
248
+ "enabled": true,
249
+ "channel": "slack",
250
+ "to": "C01ABC2DEFG"
251
+ }
252
+ ```
253
+
254
+ #### Signal
255
+
256
+ Channel type: `signal`
257
+
258
+ Use the phone number or group ID configured in your OpenClaw gateway's Signal plugin.
259
+
260
+ ```json
261
+ "observationFeed": {
262
+ "enabled": true,
263
+ "channel": "signal",
264
+ "to": "+1234567890"
265
+ }
266
+ ```
267
+
268
+ #### WhatsApp
269
+
270
+ Channel type: `whatsapp`
271
+
272
+ Use the phone number or group JID configured in your OpenClaw gateway's WhatsApp plugin.
273
+
274
+ ```json
275
+ "observationFeed": {
276
+ "enabled": true,
277
+ "channel": "whatsapp",
278
+ "to": "+1234567890"
279
+ }
280
+ ```
281
+
282
+ #### LINE
283
+
284
+ Channel type: `line`
285
+
286
+ Use the user ID or group ID from the LINE Developer Console.
287
+
288
+ ```json
289
+ "observationFeed": {
290
+ "enabled": true,
291
+ "channel": "line",
292
+ "to": "U1234567890abcdef"
293
+ }
294
+ ```
295
+
296
+ ### Add it to your config
297
+
298
+ Your complete plugin config should now look like this (using Telegram as an example):
299
+
300
+ ```json
301
+ {
302
+ "plugins": {
303
+ "claude-mem": {
304
+ "enabled": true,
305
+ "config": {
306
+ "project": "my-project",
307
+ "syncMemoryFile": true,
308
+ "workerPort": 37777,
309
+ "observationFeed": {
310
+ "enabled": true,
311
+ "channel": "telegram",
312
+ "to": "123456789"
313
+ }
314
+ }
315
+ }
316
+ }
317
+ }
318
+ ```
319
+
320
+ ### Restart and verify
321
+
322
+ Restart the gateway. Check the logs for these three lines in order:
323
+
324
+ ```
325
+ [claude-mem] Observation feed starting — channel: telegram, target: 123456789
326
+ [claude-mem] Connecting to SSE stream at http://localhost:37777/stream
327
+ [claude-mem] Connected to SSE stream
328
+ ```
329
+
330
+ Then run `/claude_mem_feed` in any OpenClaw chat:
331
+
332
+ ```
333
+ Claude-Mem Observation Feed
334
+ Enabled: yes
335
+ Channel: telegram
336
+ Target: 123456789
337
+ Connection: connected
338
+ ```
339
+
340
+ If `Connection` shows `connected`, you're done. Have an agent do some work and watch observations stream to your channel.
341
+
342
+ ## Commands Reference
343
+
344
+ The plugin registers two commands:
345
+
346
+ ### /claude_mem_status
347
+
348
+ Reports worker health and current session state.
349
+
350
+ ```
351
+ /claude_mem_status
352
+ ```
353
+
354
+ Output:
355
+ ```
356
+ Claude-Mem Worker Status
357
+ Status: ok
358
+ Port: 37777
359
+ Active sessions: 2
360
+ Observation feed: connected
361
+ ```
362
+
363
+ ### /claude_mem_feed
364
+
365
+ Shows observation feed status. Accepts optional `on`/`off` argument.
366
+
367
+ ```
368
+ /claude_mem_feed — show status
369
+ /claude_mem_feed on — request enable (update config to persist)
370
+ /claude_mem_feed off — request disable (update config to persist)
371
+ ```
372
+
373
+ ## How It All Works
374
+
375
+ ```
376
+ OpenClaw Gateway
377
+
378
+ ├── before_agent_start ───→ Init session
379
+ ├── before_prompt_build ──→ Inject context into system prompt
380
+ ├── tool_result_persist ──→ Record observation
381
+ ├── agent_end ────────────→ Summarize + Complete session
382
+ └── gateway_start ────────→ Reset session tracking + context cache
383
+
384
+
385
+ Claude-Mem Worker (localhost:37777)
386
+ ├── POST /api/sessions/init
387
+ ├── POST /api/sessions/observations
388
+ ├── POST /api/sessions/summarize
389
+ ├── POST /api/sessions/complete
390
+ ├── GET /api/context/inject ──→ System prompt context
391
+ └── GET /stream ─────────────→ SSE → Messaging channels
392
+ ```
393
+
394
+ ### System prompt context injection
395
+
396
+ The plugin injects the observation timeline into each agent's system prompt via the `before_prompt_build` hook. The content comes from the worker's `GET /api/context/inject` endpoint. Context is cached for 60 seconds per project to avoid re-fetching on every LLM turn. The cache is cleared on gateway restart.
397
+
398
+ This keeps MEMORY.md under the agent's control for curated long-term memory, while the observation timeline is delivered through the system prompt.
399
+
400
+ ### Observation recording
401
+
402
+ Every tool use (Read, Write, Bash, etc.) is sent to the claude-mem worker as an observation. The worker's AI agent processes it into a structured observation with title, subtitle, facts, concepts, and narrative. Tools prefixed with `memory_` are skipped to avoid recursive recording.
403
+
404
+ ### Session lifecycle
405
+
406
+ - **`before_agent_start`** — Creates a session in the worker.
407
+ - **`before_prompt_build`** — Fetches the observation timeline and returns it as `appendSystemContext`. Cached for 60s.
408
+ - **`tool_result_persist`** — Records observation (fire-and-forget). Tool responses are truncated to 1000 characters.
409
+ - **`agent_end`** — Sends the last assistant message for summarization, then completes the session. Both fire-and-forget.
410
+ - **`gateway_start`** — Clears all session tracking (session IDs, context cache) so agents start fresh.
411
+
412
+ ### Observation feed
413
+
414
+ A background service connects to the worker's SSE stream and forwards `new_observation` events to a configured messaging channel. The connection auto-reconnects with exponential backoff (1s → 30s max).
415
+
416
+ ## Troubleshooting
417
+
418
+ | Problem | What to check |
419
+ |---------|---------------|
420
+ | Worker health check fails | Is bun installed? (`bun --version`). Is something else on port 37777? (`lsof -i :37777`). Try running directly: `bun plugin/scripts/worker-service.cjs start` |
421
+ | Worker started from Claude Code install but not responding | Check `cd ~/.claude/plugins/marketplaces/thedotmack && npm run worker:status`. May need `npm run worker:restart`. |
422
+ | Worker started from cloned repo but not responding | Check `cd /path/to/claude-mem && npm run worker:status`. Make sure you ran `npm install && npm run build` first. |
423
+ | No context in agent system prompt | Check that `syncMemoryFile` is not set to `false`. Check that the agent's ID is not in `syncMemoryFileExclude`. Verify the worker is running and has observations. |
424
+ | Observations not being recorded | Check gateway logs for `[claude-mem]` messages. The worker must be running and reachable on localhost:37777. |
425
+ | Feed shows `disconnected` | Worker's `/stream` endpoint not reachable. Check `workerPort` matches the actual worker port. |
426
+ | Feed shows `reconnecting` | Connection dropped. The plugin auto-reconnects — wait up to 30 seconds. |
427
+ | `Unknown channel type` in logs | The channel plugin (e.g., telegram) isn't loaded on your gateway. Make sure the channel is configured and running. |
428
+ | `Observation feed disabled` in logs | Set `observationFeed.enabled` to `true` in your config. |
429
+ | `Observation feed misconfigured` in logs | Both `observationFeed.channel` and `observationFeed.to` are required. |
430
+ | No messages in channel despite `connected` | The feed only sends processed observations, not raw tool usage. There's a 1-2 second delay. Make sure the worker is actually processing observations (check http://localhost:37777). |
431
+
432
+ ## Full Config Reference
433
+
434
+ ```json
435
+ {
436
+ "plugins": {
437
+ "claude-mem": {
438
+ "enabled": true,
439
+ "config": {
440
+ "project": "openclaw",
441
+ "syncMemoryFile": true,
442
+ "workerPort": 37777,
443
+ "observationFeed": {
444
+ "enabled": false,
445
+ "channel": "telegram",
446
+ "to": "123456789"
447
+ }
448
+ }
449
+ }
450
+ }
451
+ }
452
+ ```
453
+
454
+ | Field | Type | Default | Description |
455
+ |-------|------|---------|-------------|
456
+ | `project` | string | `"openclaw"` | Project name scoping observations in the database |
457
+ | `syncMemoryFile` | boolean | `true` | Inject observation context into agent system prompt |
458
+ | `syncMemoryFileExclude` | string[] | `[]` | Agent IDs excluded from context injection |
459
+ | `workerPort` | number | `37777` | Claude-mem worker service port |
460
+ | `observationFeed.enabled` | boolean | `false` | Stream observations to a messaging channel |
461
+ | `observationFeed.channel` | string | — | Channel type: `telegram`, `discord`, `slack`, `signal`, `whatsapp`, `line` |
462
+ | `observationFeed.to` | string | — | Target chat/channel/user ID |