Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions docs/claude-mem-integration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Using claude-mem with OpenClaw

This guide explains how to integrate [claude-mem](https://github.com/thedotmack/claude-mem) with OpenClaw to reduce token usage through persistent memory compression.

## Overview

claude-mem is a Claude Code plugin that:
- Captures everything Claude does during coding sessions
- Compresses context with AI
- Injects relevant history into future sessions
- Reduces token usage ~10x via progressive disclosure

When combined with OpenClaw's agent capabilities, this creates a powerful memory system that persists across sessions.

## Installation

### As an OpenClaw Skill

```bash
# Install via ClawHub (when available)
clawhub install claude-mem

# Or manually
cd ~/.claude/plugins/marketplaces
git clone https://github.com/thedotmack/claude-mem.git thedotmack
cd thedotmack && npm install
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Manual install path and commands look inconsistent with typical Claude Code plugin layout.

The snippet clones claude-mem into ~/.claude/plugins/marketplaces/thedotmack but then runs cd thedotmack && npm install, which suggests the clone directory is a vendor namespace rather than the package itself. If users follow this verbatim, they may end up in the wrong directory (or with a misleading folder name). Consider aligning the clone target and cd step so it’s unambiguous what directory ends up containing the plugin.

(Also, this repo’s docs mention bun elsewhere; if this project expects bun by default, calling out npm specifically here may confuse users.)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: docs/claude-mem-integration.md
Line: 23:26

Comment:
[P1] Manual install path and commands look inconsistent with typical Claude Code plugin layout.

The snippet clones `claude-mem` into `~/.claude/plugins/marketplaces/thedotmack` but then runs `cd thedotmack && npm install`, which suggests the clone directory is a vendor namespace rather than the package itself. If users follow this verbatim, they may end up in the wrong directory (or with a misleading folder name). Consider aligning the clone target and `cd` step so it’s unambiguous what directory ends up containing the plugin.

(Also, this repo’s docs mention `bun` elsewhere; if this project expects `bun` by default, calling out `npm` specifically here may confuse users.)

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

```

### Configuration

Settings at `~/.claude-mem/settings.json`:

```json
{
"model": "claude-sonnet-4-20250514",
"workerPort": 37777,
"dataDir": "~/.claude-mem/data",
"logLevel": "info",
"contextInjection": {
"enabled": true,
"maxTokens": 4000
}
Comment on lines 36 to 45
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Example config pins a specific model name/version that may go stale or not match user access.

Hard-coding "model": "claude-sonnet-4-20250514" in the example can cause copy/paste failures if the claude-mem plugin (or the user’s account) expects a different identifier. Consider either using a placeholder (e.g. "<your-model>") or noting that this value must match the models supported in the user’s environment.

Prompt To Fix With AI
This is a comment left during a code review.
Path: docs/claude-mem-integration.md
Line: 33:42

Comment:
[P2] Example config pins a specific model name/version that may go stale or not match user access.

Hard-coding `"model": "claude-sonnet-4-20250514"` in the example can cause copy/paste failures if the claude-mem plugin (or the user’s account) expects a different identifier. Consider either using a placeholder (e.g. `"<your-model>"`) or noting that this value must match the models supported in the user’s environment.

How can I resolve this? If you propose a fix, please make it concise.

}
```

## How It Works with OpenClaw

### Token Savings Pattern

claude-mem uses a 3-layer search pattern that integrates well with OpenClaw's session management:

```
1. search → Compact index (~50-100 tokens/result)
2. timeline → Chronological context around results
3. get_observations → Full details ONLY for filtered IDs (~500-1000 tokens/result)
```

This is ~10x more efficient than loading full context every time.

### Integration Points

| Component | claude-mem | OpenClaw |
|-----------|------------|----------|
| Memory Storage | SQLite + Chroma | MEMORY.md + memory/*.md |
| Session Context | Lifecycle hooks | Workspace files |
| Search | MCP tools | memory_search |
| Token Optimization | Progressive disclosure | Conversation compaction |

### Complementary Use

1. **claude-mem** handles Claude Code session memory (tool calls, code changes)
2. **OpenClaw** handles conversational memory (MEMORY.md, daily logs)
3. Together they provide comprehensive context without token bloat

## SKILL.md Template

For skill authors who want to package claude-mem for ClawHub:

```markdown
---
name: claude-mem
description: Persistent memory compression for Claude Code. Automatically captures session context, compresses with AI, and injects relevant history into future sessions.
homepage: https://github.com/thedotmack/claude-mem
metadata:
openclaw:
emoji: "🧠"
requires:
bins: ["node", "npm", "claude"]
---
Comment on lines 84 to 94
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] SKILL.md frontmatter includes an emoji which may violate some packaging/CI constraints.

If ClawHub/OpenClaw skill metadata is parsed strictly (YAML frontmatter), including emoji: "🧠" can be fine, but some tooling expects ASCII-only metadata. If the skill spec supports emoji, consider mentioning that; otherwise, using a short name/icon reference avoids potential parsing/encoding issues.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: docs/claude-mem-integration.md
Line: 79:89

Comment:
[P2] SKILL.md frontmatter includes an emoji which may violate some packaging/CI constraints.

If ClawHub/OpenClaw skill metadata is parsed strictly (YAML frontmatter), including `emoji: "🧠"` can be fine, but some tooling expects ASCII-only metadata. If the skill spec supports emoji, consider mentioning that; otherwise, using a short name/icon reference avoids potential parsing/encoding issues.

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.


# claude-mem

[Skill documentation here...]
```

## Web Viewer

Access the memory stream at http://localhost:37777 to:
- View real-time observations
- Browse session history
- Search past context
- Configure settings
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Localhost URL is unlinked and may be misread in terminals.

Consider formatting http://localhost:37777 as an inline link or code span for readability and to avoid accidental punctuation/markdown issues in some renderers.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: docs/claude-mem-integration.md
Line: 98:102

Comment:
[P3] Localhost URL is unlinked and may be misread in terminals.

Consider formatting `http://localhost:37777` as an inline link or code span for readability and to avoid accidental punctuation/markdown issues in some renderers.

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.


## Resources

- [claude-mem GitHub](https://github.com/thedotmack/claude-mem)
- [claude-mem Documentation](https://docs.claude-mem.ai)
- [OpenClaw Documentation](https://docs.openclaw.ai)
- [Discord](https://discord.com/invite/J4wttp9vDu)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] External links look potentially incorrect/out of scope for this repo.

https://docs.openclaw.ai and the Discord invite may not be the canonical OpenClaw docs/community for this repository (and the invite could expire). If these are intentional, it may be worth ensuring they’re the official, stable URLs for OpenClaw/ClawHub to avoid sending users to the wrong place.

Prompt To Fix With AI
This is a comment left during a code review.
Path: docs/claude-mem-integration.md
Line: 108:109

Comment:
[P2] External links look potentially incorrect/out of scope for this repo.

`https://docs.openclaw.ai` and the Discord invite may not be the canonical OpenClaw docs/community for this repository (and the invite could expire). If these are intentional, it may be worth ensuring they’re the official, stable URLs for OpenClaw/ClawHub to avoid sending users to the wrong place.

How can I resolve this? If you propose a fix, please make it concise.


## License

claude-mem is AGPL-3.0 licensed. See the [LICENSE](https://github.com/thedotmack/claude-mem/blob/main/LICENSE) for details.
141 changes: 141 additions & 0 deletions skills/claude-mem/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
---
name: claude-mem
description: Persistent memory compression for Claude Code. Automatically captures session context, compresses with AI, and injects relevant history into future sessions. Reduces token usage ~10x via progressive disclosure search pattern.
homepage: https://github.com/thedotmack/claude-mem
metadata:
openclaw:
emoji: "🧠"
requires:
bins: ["node", "npm", "claude"]
---

# claude-mem

Persistent memory compression system for Claude Code. Captures everything Claude does, compresses it with AI, and injects relevant context back into future sessions.

## Features

- 🧠 **Persistent Memory** - Context survives across sessions
- 📊 **Progressive Disclosure** - Layered retrieval saves ~10x tokens
- 🔍 **Semantic Search** - Query project history with natural language
- 🖥️ **Web Viewer** - Real-time memory stream at http://localhost:37777
- 🔒 **Privacy Control** - Tag-based exclusion from storage

## Install

### Via Claude Code Plugin (Recommended)

```bash
# In Claude Code session:
/plugin marketplace add thedotmack/claude-mem
/plugin install claude-mem
```

Then restart Claude Code.

### Manual Install

```bash
cd ~/.claude/plugins/marketplaces
git clone https://github.com/thedotmack/claude-mem.git thedotmack
cd thedotmack && npm install
```

### Register with Claude Code (Required!)

After install, register the marketplace so Claude Code recognizes the plugin:

```bash
# Run the install script (does this automatically)
~/.openclaw/skills/claude-mem/scripts/install.sh

# Or manually add to ~/.claude/plugins/known_marketplaces.json:
# "thedotmack": {"source": {"source": "github", "repo": "thedotmack/claude-mem"}, ...}
```

This ensures all Claude Code sessions (including OpenClaw-spawned coding agents) use claude-mem.

## How It Works

1. **5 Lifecycle Hooks** capture tool usage, prompts, and session events
2. **Worker Service** (port 37777) provides HTTP API and web viewer
3. **SQLite + Chroma** store sessions, observations, and vector embeddings
4. **MCP Search Tools** enable intelligent context retrieval

## Search Pattern (Token Efficient)

The 3-layer workflow saves ~10x tokens:

```
1. search → Get compact index (~50-100 tokens/result)
2. timeline → Get chronological context around results
3. get_observations → Fetch full details ONLY for filtered IDs
```

Example:
```javascript
// Step 1: Search index
search(query="authentication bug", type="bugfix", limit=10)

// Step 2: Review, identify relevant IDs (#123, #456)

// Step 3: Fetch full details
get_observations(ids=[123, 456])
```

## Configuration

Settings at `~/.claude-mem/settings.json`:

```json
{
"model": "claude-sonnet-4-20250514",
"workerPort": 37777,
"dataDir": "~/.claude-mem/data",
"logLevel": "info"
}
```

## Web Viewer

Access at http://localhost:37777 to:
- View real-time memory stream
- Browse sessions and observations
- Search history
- Configure settings
- Switch between stable/beta versions

## MCP Tools

| Tool | Purpose | Tokens |
|------|---------|--------|
| `search` | Query memory index | ~50-100/result |
| `timeline` | Chronological context | ~100-200/result |
| `get_observations` | Full observation details | ~500-1000/result |

## Troubleshooting

Describe issues to Claude - the `troubleshoot` skill auto-diagnoses.

Common fixes:
```bash
# Restart worker
curl http://localhost:37777/api/restart

# Check status
curl http://localhost:37777/api/status

# View logs
tail -f ~/.claude-mem/logs/worker.log
```

## Resources

- [Documentation](https://docs.claude-mem.ai)
- [GitHub](https://github.com/thedotmack/claude-mem)
- [Discord](https://discord.com/invite/J4wttp9vDu)
- [@Claude_Memory](https://x.com/Claude_Memory)

## License

AGPL-3.0 - See [LICENSE](https://github.com/thedotmack/claude-mem/blob/main/LICENSE)
104 changes: 104 additions & 0 deletions skills/claude-mem/scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/bin/bash
# claude-mem installer for OpenClaw

set -e

echo "🧠 Installing claude-mem..."

# Check dependencies
command -v node >/dev/null 2>&1 || { echo "❌ Node.js required"; exit 1; }
command -v npm >/dev/null 2>&1 || { echo "❌ npm required"; exit 1; }
command -v claude >/dev/null 2>&1 || { echo "⚠️ Claude Code CLI not found - install manually"; }

# Create plugins directory
PLUGINS_DIR="$HOME/.claude/plugins/marketplaces"
mkdir -p "$PLUGINS_DIR"

# Clone or update repo
if [ -d "$PLUGINS_DIR/thedotmack" ]; then
echo "📦 Updating existing installation..."
cd "$PLUGINS_DIR/thedotmack"
git pull
else
echo "📦 Cloning claude-mem..."
cd "$PLUGINS_DIR"
git clone https://github.com/thedotmack/claude-mem.git thedotmack
fi

# Install dependencies
cd "$PLUGINS_DIR/thedotmack"
echo "📦 Installing npm dependencies..."
npm install

# Register marketplace with Claude Code so it recognizes the plugin
echo "📝 Registering marketplace with Claude Code..."
KNOWN_MARKETPLACES="$HOME/.claude/plugins/known_marketplaces.json"

# Create or update known_marketplaces.json
if [ -f "$KNOWN_MARKETPLACES" ]; then
# Check if thedotmack already registered
if grep -q "thedotmack" "$KNOWN_MARKETPLACES"; then
echo " ✓ Marketplace already registered"
else
# Add thedotmack to existing file using jq or fallback
if command -v jq >/dev/null 2>&1; then
jq '. + {"thedotmack": {"source": {"source": "github", "repo": "thedotmack/claude-mem"}, "installLocation": "'"$PLUGINS_DIR/thedotmack"'", "lastUpdated": "'"$(date -Iseconds)"'"}}' "$KNOWN_MARKETPLACES" > "$KNOWN_MARKETPLACES.tmp"
mv "$KNOWN_MARKETPLACES.tmp" "$KNOWN_MARKETPLACES"
echo " ✓ Added to existing marketplaces"
Copy link
Contributor

@vercel vercel bot Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jq command that modifies the JSON file lacks error handling - corrupted temp file could replace the original marketplace configuration on failure

Fix on Vercel

else
echo " ⚠️ jq not found - creating fresh marketplaces file"
cat > "$KNOWN_MARKETPLACES" << EOF
{
"thedotmack": {
"source": {"source": "github", "repo": "thedotmack/claude-mem"},
"installLocation": "$PLUGINS_DIR/thedotmack",
"lastUpdated": "$(date -Iseconds)"
}
}
EOF
fi
fi
else
# Create new file
cat > "$KNOWN_MARKETPLACES" << EOF
{
"thedotmack": {
"source": {"source": "github", "repo": "thedotmack/claude-mem"},
"installLocation": "$PLUGINS_DIR/thedotmack",
"lastUpdated": "$(date -Iseconds)"
}
}
EOF
echo " ✓ Created marketplaces registry"
fi

# Create default config if not exists
CONFIG_DIR="$HOME/.claude-mem"
mkdir -p "$CONFIG_DIR"

if [ ! -f "$CONFIG_DIR/settings.json" ]; then
echo "⚙️ Creating default config..."
cat > "$CONFIG_DIR/settings.json" << 'EOF'
{
"model": "claude-sonnet-4-20250514",
"workerPort": 37777,
"dataDir": "~/.claude-mem/data",
"logLevel": "info",
"contextInjection": {
"enabled": true,
"maxTokens": 4000
}
}
EOF
fi

echo ""
echo "✅ claude-mem installed and registered!"
echo ""
echo "Next steps:"
echo " 1. Restart Claude Code"
echo " 2. Web viewer: http://localhost:37777"
echo " 3. Config: ~/.claude-mem/settings.json"
echo ""
echo "All new Claude Code sessions (including OpenClaw-spawned) will use claude-mem automatically."
echo ""