Add persistent memory to OpenCode with the Mem0 plugin. Your agent forgets everything between sessions — Mem0 fixes that by storing decisions, preferences, and learnings so they carry over automatically.Documentation Index
Fetch the complete documentation index at: https://docs.mem0.ai/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
-
A Mem0 API key (starts with
m0-):- Get your API key (free sign-up at app.mem0.ai)
- Add it to your shell profile so it persists across sessions:
Installation
Option A — Plugin Install (Recommended)
~/.config/opencode/opencode.json. Restart OpenCode — you get the MCP server, lifecycle hooks, and all /mem0: slash commands.
Option B — MCP Only
If you only need the memory tools without hooks or skills, add this to youropencode.json (project-level or global at ~/.config/opencode/opencode.json):
Start a new OpenCode session and ask: “Search my memories for hello”. If the
mem0 tools appear and respond, you’re all set.What’s Included
| Component | Plugin (A) | MCP Only (B) |
|---|---|---|
| MCP Server (9 memory tools) | Yes | Yes |
| Lifecycle Hooks | Yes | No |
| 16 Slash Commands | Yes | No |
Available MCP Tools
| Tool | Description |
|---|---|
add_memory | Save text or conversation history for a user/agent |
search_memories | Semantic search across memories with filters |
get_memories | List memories with filters and pagination |
get_memory | Retrieve a specific memory by ID |
update_memory | Overwrite a memory’s text by ID |
delete_memory | Delete a single memory by ID |
delete_all_memories | Bulk delete all memories in scope |
delete_entities | Delete a user/agent/app/run entity and its memories |
list_entities | List users/agents/apps/runs stored in Mem0 |
Lifecycle Hooks
The plugin uses the mem0ai TypeScript SDK directly — pure TypeScript, no Python, no shell scripts.| OpenCode Event | Hook | What happens |
|---|---|---|
chat.message | Chat message | Searches prior memories on session start, searches relevant memories before each prompt, auto-captures learnings periodically |
tool.execute.before | Pre-tool | Blocks MEMORY.md writes, injects user_id/app_id on mem0 tool calls |
tool.execute.after | Post-tool | Tracks stats, scans Bash errors and pre-fetches related error memories |
experimental.chat.system.transform | System transform | Injects memory context (session memories, search results, error lookups) into the system prompt |
experimental.session.compacting | Compaction | Stores session state memory, then injects prior memories into compaction context so nothing is lost |
shell.env | Shell env | Exports MEM0_USER_ID, MEM0_APP_ID, MEM0_SESSION_ID, and MEM0_BRANCH to all shell executions |
Troubleshooting
- No tools appearing — Restart OpenCode after installing
- “Connection failed” — Verify your key is set:
echo $MEM0_API_KEY - Plugin not loading — Run
opencode plugin @mem0/opencode-pluginagain, then restart - Hooks not firing — Hooks require the plugin install (Option A). MCP-only installs don’t include hooks.
Mem0 MCP Setup
Detailed MCP configuration for all clients
Antigravity Integration
Add Mem0 memory to Google Antigravity