Skip to content

synapz-org/opencode-claude-mem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenCode + Claude-Mem Integration

Unified memory across OpenCode and Claude Code using claude-mem.

What This Does

  • Real-time sync: Automatically captures OpenCode conversations and syncs them to claude-mem
  • Memory search: Query your claude-mem memories from within OpenCode via MCP
  • Cross-platform context: Memories from Claude Code sessions are searchable in OpenCode and vice versa

Prerequisites

  • OpenCode installed
  • claude-mem v7.0+ installed (as a Claude Code plugin or standalone)
  • Node.js 18+

Quick Install

# Clone the repo
git clone https://github.com/yourusername/opencode-claude-mem.git
cd opencode-claude-mem

# Run the installer
./install.sh

Manual Installation

1. Configure MCP Server (Memory Search)

Add claude-mem's MCP server to your OpenCode config. Create or edit ~/.config/opencode/.opencode.json:

{
  "mcpServers": {
    "claude-mem": {
      "type": "stdio",
      "command": "node",
      "args": ["~/.claude/plugins/cache/thedotmack/claude-mem/VERSION/scripts/mcp-server.cjs"]
    }
  }
}

Replace VERSION with your installed claude-mem version (e.g., 8.2.0).

2. Install Sync Scripts

# Create scripts directory
mkdir -p ~/.opencode/scripts

# Copy sync scripts
cp scripts/mem-sync.js ~/.opencode/scripts/
cp scripts/mem-sync-daemon.js ~/.opencode/scripts/

# Make executable
chmod +x ~/.opencode/scripts/mem-sync.js
chmod +x ~/.opencode/scripts/mem-sync-daemon.js

3. Install OpenCode Commands

# Create commands directory
mkdir -p ~/.opencode/command

# Copy commands
cp commands/mem-sync.md ~/.opencode/command/
cp commands/mem-daemon.md ~/.opencode/command/

4. Start the Sync Daemon

# Start manually
node ~/.opencode/scripts/mem-sync-daemon.js start

# Check status
node ~/.opencode/scripts/mem-sync-daemon.js status

5. (Optional) Auto-Start on Login (macOS)

# Copy and customize the launchd plist
cp launchd/com.opencode.mem-sync.plist ~/Library/LaunchAgents/

# Edit the plist to match your node path
# Find your node path with: which node

# Load the service
launchctl load ~/Library/LaunchAgents/com.opencode.mem-sync.plist

Usage

OpenCode Commands

Command Description
/mem-sync Manually sync recent sessions to claude-mem
/mem-sync --all Sync all OpenCode sessions
/mem-sync --since 48 Sync sessions from last 48 hours
/mem-daemon Show daemon control commands

Daemon Control

# Check if daemon is running
node ~/.opencode/scripts/mem-sync-daemon.js status

# Start daemon
node ~/.opencode/scripts/mem-sync-daemon.js start

# Stop daemon
node ~/.opencode/scripts/mem-sync-daemon.js stop

Memory Search

Once configured, OpenCode can use claude-mem's MCP tools to search memories:

  • search - Semantic search across all memories
  • timeline - View memories chronologically
  • get_recent_context - Get context from recent sessions

How It Works

┌─────────────┐     ┌──────────────────┐     ┌─────────────┐
│  OpenCode   │────▶│  Sync Daemon     │────▶│ Claude-Mem  │
│  Sessions   │     │  (file watcher)  │     │   Worker    │
└─────────────┘     └──────────────────┘     └─────────────┘
                                                    │
                                                    ▼
                                            ┌─────────────┐
                                            │   SQLite    │
                                            │  Database   │
                                            └─────────────┘
                                                    │
                    ┌───────────────────────────────┼───────────────────────────────┐
                    ▼                               ▼                               ▼
            ┌─────────────┐                 ┌─────────────┐                 ┌─────────────┐
            │  OpenCode   │                 │ Claude Code │                 │   Viewer    │
            │ (MCP search)│                 │   (hooks)   │                 │  (web UI)   │
            └─────────────┘                 └─────────────┘                 └─────────────┘
  1. File Watcher: Monitors ~/.local/share/opencode/storage/ for new messages
  2. Debouncing: Waits 3 seconds after last activity before syncing (batches rapid messages)
  3. Worker API: Submits conversations to claude-mem's worker for observation extraction
  4. MCP Server: Exposes search tools that OpenCode can query

Configuration

Environment Variables

Variable Default Description
CLAUDE_MEM_WORKER_PORT 37777 Claude-mem worker port
CLAUDE_MEM_WORKER_HOST 127.0.0.1 Claude-mem worker host

Sync Settings

Edit the constants at the top of mem-sync-daemon.js:

const DEBOUNCE_MS = 3000;        // Wait time after last activity
const SESSION_TIMEOUT_MS = 60000; // Consider session "done" after inactivity

Troubleshooting

Daemon won't start

  1. Check if claude-mem worker is running:

    curl http://127.0.0.1:37777/health
  2. Check daemon logs:

    cat ~/.opencode/mem-sync-daemon.log

Memories not appearing

  1. Verify the daemon is running:

    node ~/.opencode/scripts/mem-sync-daemon.js status
  2. Check if sessions are being detected:

    node ~/.opencode/scripts/mem-sync.js --dry-run
  3. View the claude-mem UI to see if observations are being created:

    http://127.0.0.1:37777/
    

MCP tools not available in OpenCode

  1. Verify your .opencode.json config is valid JSON
  2. Check the claude-mem MCP server path exists
  3. Restart OpenCode after config changes

License

MIT

Credits

About

Unified memory across OpenCode and Claude Code using claude-mem

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published