Skip to main content

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.

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.

Prerequisites

  1. A Mem0 API key (starts with m0-):
  2. Add it to your shell profile so it persists across sessions:
echo 'export MEM0_API_KEY="m0-your-api-key"' >> ~/.zshrc && source ~/.zshrc

Installation

opencode plugin @mem0/opencode-plugin
Or using this command which does the same thing:
bunx @mem0/opencode-plugin@latest install
Or let your agent do it — paste this into OpenCode:
Install @mem0/opencode-plugin by following https://raw.githubusercontent.com/mem0ai/mem0/main/mem0-plugin/.opencode-plugin/README.md
All commands auto-add the plugin and MCP server to your ~/.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 your opencode.json (project-level or global at ~/.config/opencode/opencode.json):
{
  "mcp": {
    "mem0": {
      "type": "remote",
      "url": "https://mcp.mem0.ai/mcp/",
      "headers": {
        "Authorization": "Token {env:MEM0_API_KEY}"
      },
      "oauth": false
    }
  }
}
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

ComponentPlugin (A)MCP Only (B)
MCP Server (9 memory tools)YesYes
Lifecycle HooksYesNo
16 Slash CommandsYesNo

Available MCP Tools

ToolDescription
add_memorySave text or conversation history for a user/agent
search_memoriesSemantic search across memories with filters
get_memoriesList memories with filters and pagination
get_memoryRetrieve a specific memory by ID
update_memoryOverwrite a memory’s text by ID
delete_memoryDelete a single memory by ID
delete_all_memoriesBulk delete all memories in scope
delete_entitiesDelete a user/agent/app/run entity and its memories
list_entitiesList 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 EventHookWhat happens
chat.messageChat messageSearches prior memories on session start, searches relevant memories before each prompt, auto-captures learnings periodically
tool.execute.beforePre-toolBlocks MEMORY.md writes, injects user_id/app_id on mem0 tool calls
tool.execute.afterPost-toolTracks stats, scans Bash errors and pre-fetches related error memories
experimental.chat.system.transformSystem transformInjects memory context (session memories, search results, error lookups) into the system prompt
experimental.session.compactingCompactionStores session state memory, then injects prior memories into compaction context so nothing is lost
shell.envShell envExports 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-plugin again, 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