AI News Hub Logo

AI News Hub

Give Your AI Persistent Memory: OpenCode + MemPalace in 10 Minute

DEV Community
geco

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. 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. The plugin uses two OpenCode hooks: chat.message — when you send a new question, the previous turn (question + answer) is saved 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. pip install mempalace Or with uv: uv tool install mempalace Edit ~/.config/opencode/opencode.json: { "plugin": ["opencode-mempalace-persistence"], "mcp": { "mempalace": { "type": "local", "command": ["mempalace-mcp"], "enabled": true } }, "instructions": ["AGENTS.md", "~/.mempalace/identity.txt"] } 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. Create ~/.mempalace/identity.txt: I am [name], a [role]. I work with [technologies]. That's it. Every conversation is now automatically saved to MemPalace. 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 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 GitHub: https://github.com/geco/opencode-mempalace-persistence npm: opencode-mempalace-persistence MemPalace: https://github.com/MemPalace/mempalace awesome-opencode: https://github.com/awesome-opencode/awesome-opencode/pull/357 Built with TypeScript, OpenCode Plugin SDK, and MemPalace. Published under MIT license.