docs/public/openclaw-integration.mdx
The OpenClaw plugin gives claude-mem persistent memory to agents running on the OpenClaw gateway. It handles three things:
before_prompt_build hook, keeping MEMORY.md free for agent-curated memoryOpenClaw Gateway
│
├── before_agent_start ───→ Init session
├── before_prompt_build ──→ Inject context into system prompt
├── tool_result_persist ──→ Record observation
├── agent_end ────────────→ Summarize + Complete session
└── gateway_start ────────→ Reset session tracking + context cache
│
▼
Claude-Mem Worker (localhost:37777)
├── POST /api/sessions/init
├── POST /api/sessions/observations
├── POST /api/sessions/summarize
├── POST /api/sessions/complete
├── GET /api/context/inject ──→ System prompt context
└── GET /stream ─────────────→ SSE → Messaging channels
The context is cached for 60 seconds to avoid re-fetching on every LLM turn within a session.
Tools prefixed with `memory_` are skipped to avoid recursive recording.
The plugin injects cross-session observation context into each agent's system prompt via OpenClaw's before_prompt_build hook. The content comes from the worker's GET /api/context/inject?projects=<project> endpoint, which generates a formatted markdown timeline from the SQLite database.
This approach keeps MEMORY.md under the agent's control for curated long-term memory (decisions, preferences, durable facts), while the observation timeline is delivered through the system prompt where it belongs.
The plugin runs a background service that connects to the worker's SSE stream (GET /stream) and forwards new_observation events to a configured messaging channel. This lets you monitor what your agents are learning in real-time from Telegram, Discord, Slack, or any supported OpenClaw channel.
The SSE connection uses exponential backoff (1s → 30s) for automatic reconnection.
The observation feed sends a formatted message to your OpenClaw channel every time claude-mem creates a new observation. Each message includes the observation title and subtitle so you can follow along as your agents work.
Messages look like this in your channel:
🧠 Claude-Mem Observation
**Implemented retry logic for API client**
Added exponential backoff with configurable max retries to handle transient failures
The observation feed works with any channel that your OpenClaw gateway has configured. You need two pieces of information:
telegram, discord, slack, signal, whatsapp, line)**Target ID:** Your Telegram chat ID (numeric). To find it:
1. Message [@userinfobot](https://t.me/userinfobot) on Telegram
2. It will reply with your chat ID (e.g., `123456789`)
3. For group chats, the ID is negative (e.g., `-1001234567890`)
```json
"observationFeed": {
"enabled": true,
"channel": "telegram",
"to": "123456789"
}
```
**Target ID:** The Discord channel ID. To find it:
1. Enable Developer Mode in Discord (Settings → Advanced → Developer Mode)
2. Right-click the channel → Copy Channel ID
```json
"observationFeed": {
"enabled": true,
"channel": "discord",
"to": "1234567890123456789"
}
```
**Target ID:** The Slack channel ID (not the channel name). To find it:
1. Open the channel in Slack
2. Click the channel name at the top
3. Scroll to the bottom of the channel details — the ID looks like `C01ABC2DEFG`
```json
"observationFeed": {
"enabled": true,
"channel": "slack",
"to": "C01ABC2DEFG"
}
```
**Target ID:** The Signal phone number or group ID configured in your OpenClaw gateway.
```json
"observationFeed": {
"enabled": true,
"channel": "signal",
"to": "+1234567890"
}
```
**Target ID:** The WhatsApp phone number or group JID configured in your OpenClaw gateway.
```json
"observationFeed": {
"enabled": true,
"channel": "whatsapp",
"to": "+1234567890"
}
```
**Target ID:** The LINE user ID or group ID from the LINE Developer Console.
```json
"observationFeed": {
"enabled": true,
"channel": "line",
"to": "U1234567890abcdef"
}
```
Add the observationFeed block to your claude-mem plugin config in your OpenClaw gateway configuration:
{
"plugins": {
"claude-mem": {
"enabled": true,
"config": {
"project": "my-project",
"observationFeed": {
"enabled": true,
"channel": "telegram",
"to": "123456789"
}
}
}
}
}
After starting the gateway, check that the feed is connected:
Check the logs — You should see:
[claude-mem] Observation feed starting — channel: telegram, target: 123456789
[claude-mem] Connecting to SSE stream at http://localhost:37777/stream
[claude-mem] Connected to SSE stream
Use the status command — Run /claude_mem_feed in any OpenClaw chat to see:
Claude-Mem Observation Feed
Enabled: yes
Channel: telegram
Target: 123456789
Connection: connected
Trigger a test — Have an agent do some work. When the worker processes the tool usage into an observation, you'll receive a message in your configured channel.
| Symptom | Cause | Fix |
|---|---|---|
Connection: disconnected | Worker not running or wrong port | Check workerPort config, run npm run worker:status |
Connection: reconnecting | Worker was running but connection dropped | The plugin auto-reconnects with backoff — wait up to 30s |
Unknown channel type in logs | Channel plugin not loaded on gateway | Verify your OpenClaw gateway has the channel plugin configured |
| No messages appearing | Feed connected but no observations being created | Check that agents are running and the worker is processing observations |
Observation feed disabled in logs | enabled is false or missing | Set observationFeed.enabled to true |
Observation feed misconfigured in logs | Missing channel or to | Both channel and to are required |
Run this one-liner to install everything automatically:
curl -fsSL https://install.cmem.ai/openclaw.sh | bash
The installer handles dependency checks (Bun, uv), plugin installation, memory slot configuration, AI provider setup, worker startup, and optional observation feed configuration.
You can also pre-select options:
# With a specific AI provider
curl -fsSL https://install.cmem.ai/openclaw.sh | bash -s -- --provider=gemini --api-key=YOUR_KEY
# Fully unattended (defaults to Claude Max Plan)
curl -fsSL https://install.cmem.ai/openclaw.sh | bash -s -- --non-interactive
# Upgrade existing installation
curl -fsSL https://install.cmem.ai/openclaw.sh | bash -s -- --upgrade
Add claude-mem to your OpenClaw gateway's plugin configuration:
{
"plugins": {
"claude-mem": {
"enabled": true,
"config": {
"project": "my-project",
"syncMemoryFile": true,
"workerPort": 37777,
"observationFeed": {
"enabled": true,
"channel": "telegram",
"to": "your-chat-id"
}
}
}
}
}
Show or toggle the observation feed status.
/claude_mem_feed # Show current status
/claude_mem_feed on # Request enable
/claude_mem_feed off # Request disable
Check worker health and session status.
/claude_mem_status
Returns worker status, port, active session count, and observation feed connection state.
The plugin uses HTTP calls to the already-running claude-mem worker service rather than spawning subprocesses. This means:
bun dependency required on the gatewayEach OpenClaw agent session gets a unique contentSessionId (format: openclaw-<sessionKey>-<timestamp>) that maps to a claude-mem session in the worker. The plugin tracks:
sessionIds — Maps OpenClaw session keys to content session IDscontextCache — TTL cache (60s) for context injection responses, keyed by projectBoth are cleared on gateway_start.
localhost:37777 (or configured port)