VOOZH about

URL: https://dev.to/gecojs/give-your-ai-persistent-memory-opencode-mempalace-in-10-minute-dl7

⇱ Give Your AI Persistent Memory: OpenCode + MemPalace in 10 Minute - DEV Community


The Problem

Every OpenCode session starts from scratch. Your AI doesn't remember past conversations, decisions, or solved problems. You repeat context over and over.

The Solution

opencode-mempalace-persistence is a pure TypeScript plugin that auto-saves every conversation to MemPalace — a local vector database with 96.6% recall on LongMemEval. No cron, no cloud, no API keys.

Architecture

The plugin uses two OpenCode hooks:

  1. chat.message — when you send a new question, the previous turn (question + answer) is saved
  2. session.idle — catches the last turn before you close OpenCode

Each turn is categorized by wing type (developer, creative, emotions, family, consciousness) and fed to MemPalace's vector store. Knowledge Graph facts (decisions, milestones, problems, preferences) are extracted automatically.

The mining runs asynchronously — state is saved immediately, and MemPalace indexing happens in the background. The UI is never blocked.

Setup

Step 1: Install MemPalace

pip install mempalace

Or with uv:

uv tool install mempalace

Step 2: Configure OpenCode

Edit ~/.config/opencode/opencode.json:

{"plugin":["opencode-mempalace-persistence"],"mcp":{"mempalace":{"type":"local","command":["mempalace-mcp"],"enabled":true}},"instructions":["AGENTS.md","~/.mempalace/identity.txt"]}

Step 3: Create AGENTS.md

Create ~/.config/opencode/AGENTS.md:

# Memory & Knowledge Instructions

Before answering, search MemPalace using MCP tools.

1. Call `mempalace_search` with the user's question as query.
2. Call `mempalace_kg_query` for entity "user" and filter by keywords.
3. Use relevant context in your response.

Step 4: Add your identity

Create ~/.mempalace/identity.txt:

I am [name], a [role]. I work with [technologies].

Step 5: Restart OpenCode

That's it. Every conversation is now automatically saved to MemPalace.

What Gets Saved

Every turn produces:

  • A drawer in MemPalace's vector database with the full conversation text
  • A wing assignment based on content analysis
  • Knowledge Graph facts: decisions, milestones, problems, preferences

Why Not Cron?

Before building this plugin, I was running a cron job to sync conversations. It was fragile, slow, and produced duplicates. The plugin approach is:

  • Real-time: sync happens immediately after each response
  • Delta-only: only new messages are processed
  • Async: the UI is never blocked
  • Graceful shutdown: session.idle catches the last turn

Links


Built with TypeScript, OpenCode Plugin SDK, and MemPalace. Published under MIT license.