Claude-Mem:持久化 AI 智能体记忆 - Openclaw Skills

作者:互联网

2026-04-13

AI教程

什么是 Claude-Mem for OpenClaw?

Claude-Mem 插件是一个复杂的记忆层,旨在为自主智能体提供连续的上下文历史。通过直接集成到智能体生命周期中,它确保记录、总结每一次工具交互和决策,并供未来会话使用。这种架构将无状态智能体转变为具有上下文感知能力的助手,使其能够在 Openclaw Skills 生态系统中基于之前的工作进行构建。

该插件的核心利用了一个专门的工作服务,将原始工具输出处理为结构化的观察结果。随后,这些数据会同步回智能体工作区中实时更新的 Markdown 文件,允许大语言模型(LLM)在无需手动注入上下文的情况下“记住”其进度和发现。这对于构建复杂、多阶段工作流的开发者来说是一次重大升级。

下载入口:https://github.com/openclaw/skills/tree/main/skills/thedotmack/claude-mem

安装与下载

1. ClawHub CLI

从源直接安装技能的最快方式。

npx clawhub@latest install claude-mem

2. 手动安装

将技能文件夹复制到以下位置之一

全局模式 ~/.openclaw/skills/ 工作区 /skills/

优先级:工作区 > 本地 > 内置

3. 提示词安装

将此提示词复制到 OpenClaw 即可自动安装。

请帮我使用 Clawhub 安装 claude-mem。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。

Claude-Mem for OpenClaw 应用场景

  • 在多次智能体重启或不同的聊天会话中保持特定项目的上下文。
  • 通过 T@elegrimm 或 Discord 等外部消息应用实时坚控智能体工具使用情况和“思考过程”。
  • 通过自动更新的 MEMORY.md 文件自动生成项目日志和文档。
  • 在智能体需要回顾之前架构决策的长期编码任务中,防止上下文丢失。
Claude-Mem for OpenClaw 工作原理
  1. 插件在智能体启动事件期间触发会话初始化,将历史上下文同步到工作区。
  2. 每次工具执行(如 bash 命令或文件读取)都会被捕获为原始观察结果。
  3. 这些观察结果被发送到本地工作服务,该服务将数据结构化为事实、概念和叙述。
  4. 智能体目录中维护一个实时更新的 MEMORY.md 文件,以提供即时的基于文件的上下文。
  5. 完成后,会话将被总结并存储在持久化数据库中,供未来的 Openclaw Skills 实例检索。

Claude-Mem for OpenClaw 配置指南

最快的安装方式是使用自动化脚本:

curl -fsSL https://install.cmem.ai/openclaw.sh | bash

如需手动安装,请克隆仓库并准备工作服务:

cd /opt/claude-mem
npm install
npm run build
bun plugin/scripts/worker-service.cjs start

当工作服务在 37777 端口运行后,将插件添加到您的网关配置文件中并重启服务以启用记忆功能。

Claude-Mem for OpenClaw 数据架构与分类体系

该插件将数据组织成结构化层次结构,以确保人类和 AI 智能体都能清晰理解。主要界面是 MEMORY.md 文件,其结构如下:

组件 描述
项目范围 用于分割观察结果的唯一标识符(例如 'coding-bot')。
观察结果 包含标题、副标题、事实和叙述摘要的结构化日志。
工作区映射 将特定目录路径映射到持久化会话 ID。
时间线 工作期间生成的工具结果和智能体见解的按时间顺序排列的列表。

Claude-Mem OpenClaw Plugin — Setup Guide

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, a live-updating MEMORY.md in their workspace, and optionally a real-time observation feed streaming to a messaging channel.

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 — all interactively.

Install with options

Pre-select your AI provider and API key to skip interactive prompts:

curl -fsSL https://install.cmem.ai/openclaw.sh | bash -s -- --provider=gemini --api-key=YOUR_KEY

For fully unattended installation (defaults to Claude Max Plan, skips observation feed):

curl -fsSL https://install.cmem.ai/openclaw.sh | bash -s -- --non-interactive

To upgrade an existing installation (preserves settings, updates plugin):

curl -fsSL https://install.cmem.ai/openclaw.sh | bash -s -- --upgrade

After installation, skip to Step 4: Restart the Gateway and Verify to confirm everything is working.


Manual Setup

The steps below are for manual installation if you prefer not to use the automated installer, or need to troubleshoot individual steps.

Step 1: Clone the Claude-Mem Repo

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.

cd /opt  # or wherever you want to keep it
git clone https://github.com/thedotmack/claude-mem.git
cd claude-mem
npm install
npm run build

You'll need bun installed for the worker service. If you don't have it:

curl -fsSL https://bun.sh/install | bash

Step 2: Get the Worker Running

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.

Check if it's already running

If this machine also runs Claude Code with claude-mem installed, the worker may already be running:

curl http://localhost:37777/api/health

Got {"status":"ok"}? The worker is already running. Skip to Step 3.

Got connection refused or no response? The worker isn't running. Continue below.

If Claude Code has claude-mem installed

If claude-mem is installed as a Claude Code plugin (at ~/.claude/plugins/marketplaces/thedotmack/), start the worker from that installation:

cd ~/.claude/plugins/marketplaces/thedotmack
npm run worker:restart

Verify:

curl http://localhost:37777/api/health

Got {"status":"ok"}? You're set. Skip to Step 3.

Still not working? Check npm run worker:status for error details, or check that bun is installed and on your PATH.

If there's no Claude Code installation

Run the worker from the cloned repo:

cd /opt/claude-mem  # wherever you cloned it
npm run worker:start

Verify:

curl http://localhost:37777/api/health

Got {"status":"ok"}? You're set. Move to Step 3.

Still not working? Debug steps:

  • Check that bun is installed: bun --version
  • Check the worker status: npm run worker:status
  • Check if something else is using port 37777: lsof -i :37777
  • Check logs: npm run worker:logs (if available)
  • Try running it directly to see errors: bun plugin/scripts/worker-service.cjs start

Step 3: Add the Plugin to Your Gateway

Add the claude-mem plugin to your OpenClaw gateway configuration:

{
  "plugins": {
    "claude-mem": {
      "enabled": true,
      "config": {
        "project": "my-project",
        "syncMemoryFile": true,
        "workerPort": 37777
      }
    }
  }
}

Config fields explained

  • 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".

  • syncMemoryFile (boolean, default: true) — When enabled, the plugin writes a MEMORY.md file to each agent's workspace directory. This file contains the full timeline of observations and summaries from previous sessions, and it updates on every tool use so agents always have fresh context. Set to false only if you don't want the plugin writing files to agent workspaces.

  • 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.


Step 4: Restart the Gateway and Verify

Restart your OpenClaw gateway so it picks up the new plugin configuration. After restart, check the gateway logs for:

[claude-mem] OpenClaw plugin loaded — v1.0.0 (worker: 127.0.0.1:37777)

If you see this, the plugin is loaded. You can also verify by running /claude_mem_status in any OpenClaw ch@t:

Claude-Mem Worker Status
Status: ok
Port: 37777
Active sessions: 0
Observation feed: disconnected

The observation feed shows disconnected because we haven't configured it yet. That's next.

Step 5: Verify Observations Are Being Recorded

Have an agent do some work. The plugin automatically records observations through these OpenClaw events:

  1. before_agent_start — Initializes a claude-mem session when the agent starts, syncs MEMORY.md to the workspace
  2. tool_result_persist — Records each tool use (Read, Write, Bash, etc.) as an observation, re-syncs MEMORY.md
  3. agent_end — Summarizes the session and marks it complete

All of this happens automatically. No additional configuration needed.

To verify it's working, check the agent's workspace directory for a MEMORY.md file after the agent runs. It should contain a formatted timeline of observations.

You can also check the worker's viewer UI at http://localhost:37777 to see observations appearing in real time.

Step 6: Set Up the Observation Feed (Streaming to a Channel)

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 T@elegrimm/Discord/Slack/etc.

What you'll see

Every time claude-mem creates a new observation from your agent's tool usage, a message like this appears in your channel:

?? Claude-Mem Observation
**Implemented retry logic for API client**
Added exponential backoff with configurable max retries to handle transient failures

Pick your channel

You need two things:

  • Channel type — Must match a channel plugin already running on your OpenClaw gateway
  • Target ID — The ch@t/channel/user ID where messages go

T@elegrimm

Channel type: telegram

To find your ch@t ID:

  1. Message @userinfobot on T@elegrimm — https://t.me/userinfobot
  2. It replies with your numeric ch@t ID (e.g., 123456789)
  3. For group ch@ts, the ID is negative (e.g., -1001234567890)
"observationFeed": {
  "enabled": true,
  "channel": "telegram",
  "to": "123456789"
}

Discord

Channel type: discord

To find your channel ID:

  1. Enable Developer Mode in Discord: Settings → Advanced → Developer Mode
  2. Right-click the target channel → Copy Channel ID
"observationFeed": {
  "enabled": true,
  "channel": "discord",
  "to": "1234567890123456789"
}

Slack

Channel type: slack

To find your channel ID (not the channel name):

  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
"observationFeed": {
  "enabled": true,
  "channel": "slack",
  "to": "C01ABC2DEFG"
}

Signal

Channel type: signal

Use the phone number or group ID configured in your OpenClaw gateway's Signal plugin.

"observationFeed": {
  "enabled": true,
  "channel": "signal",
  "to": "+1234567890"
}

WhatsApp

Channel type: whatsapp

Use the phone number or group JID configured in your OpenClaw gateway's WhatsApp plugin.

"observationFeed": {
  "enabled": true,
  "channel": "whatsapp",
  "to": "+1234567890"
}

LINE

Channel type: line

Use the user ID or group ID from the LINE Developer Console.

"observationFeed": {
  "enabled": true,
  "channel": "line",
  "to": "U1234567890abcdef"
}

Add it to your config

Your complete plugin config should now look like this (using T@elegrimm as an example):

{
  "plugins": {
    "claude-mem": {
      "enabled": true,
      "config": {
        "project": "my-project",
        "syncMemoryFile": true,
        "workerPort": 37777,
        "observationFeed": {
          "enabled": true,
          "channel": "telegram",
          "to": "123456789"
        }
      }
    }
  }
}

Restart and verify

Restart the gateway. Check the logs for these three lines in order:

[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

Then run /claude_mem_feed in any OpenClaw ch@t:

Claude-Mem Observation Feed
Enabled: yes
Channel: telegram
Target: 123456789
Connection: connected

If Connection shows connected, you're done. Have an agent do some work and watch observations stream to your channel.

Commands Reference

The plugin registers two commands:

/claude_mem_status

Reports worker health and current session state.

/claude_mem_status

Output:

Claude-Mem Worker Status
Status: ok
Port: 37777
Active sessions: 2
Observation feed: connected

/claude_mem_feed

Shows observation feed status. Accepts optional on/off argument.

/claude_mem_feed          — show status
/claude_mem_feed on       — request enable (update config to persist)
/claude_mem_feed off      — request disable (update config to persist)

How It All Works

OpenClaw Gateway
  │
  ├── before_agent_start ──→ Sync MEMORY.md + Init session
  ├── tool_result_persist ──→ Record observation + Re-sync MEMORY.md
  ├── agent_end ────────────→ Summarize + Complete session
  └── gateway_start ────────→ Reset session tracking
                    │
                    ▼
         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 ──→ MEMORY.md content
           └── GET  /stream ─────────────→ SSE → Messaging channels

MEMORY.md live sync

The plugin writes MEMORY.md to each agent's workspace with the full observation timeline. It updates:

  • On every before_agent_start — agent gets fresh context before starting
  • On every tool_result_persist — context stays current as the agent works

Updates are fire-and-forget (non-blocking). The agent is never held up waiting for MEMORY.md to write.

Observation recording

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.

Session lifecycle

  • before_agent_start — Creates a session in the worker, syncs MEMORY.md. Short prompts (under 10 chars) skip session init but still sync.
  • tool_result_persist — Records observation (fire-and-forget), re-syncs MEMORY.md (fire-and-forget). Tool responses are truncated to 1000 characters.
  • agent_end — Sends the last assistant message for summarization, then completes the session. Both fire-and-forget.
  • gateway_start — Clears all session tracking (session IDs, workspace mappings) so agents start fresh.

Observation feed

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).

Troubleshooting

Problem What to check
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
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.
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.
No MEMORY.md appearing Check that syncMemoryFile is not set to false. Verify the agent's event context includes workspaceDir.
Observations not being recorded Check gateway logs for [claude-mem] messages. The worker must be running and reachable on localhost:37777.
Feed shows disconnected Worker's /stream endpoint not reachable. Check workerPort matches the actual worker port.
Feed shows reconnecting Connection dropped. The plugin auto-reconnects — wait up to 30 seconds.
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.
Observation feed disabled in logs Set observationFeed.enabled to true in your config.
Observation feed misconfigured in logs Both observationFeed.channel and observationFeed.to are required.
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).

Full Config Reference

{
  "plugins": {
    "claude-mem": {
      "enabled": true,
      "config": {
        "project": "openclaw",
        "syncMemoryFile": true,
        "workerPort": 37777,
        "observationFeed": {
          "enabled": false,
          "channel": "telegram",
          "to": "123456789"
        }
      }
    }
  }
}
Field Type Default Description
project string "openclaw" Project name scoping observations in the database
syncMemoryFile boolean true Write MEMORY.md to agent workspaces
workerPort number 37777 Claude-mem worker service port
observationFeed.enabled boolean false Stream observations to a messaging channel
observationFeed.channel string Channel type: telegram, discord, slack, signal, whatsapp, line
observationFeed.to string Target ch@t/channel/user ID