Back to Mem0

@mem0/opencode-plugin

mem0-plugin/.opencode-plugin/README.md

2.0.53.2 KB
Original Source

@mem0/opencode-plugin

Persistent memory for OpenCode. Your agent remembers decisions, preferences, and learnings across sessions automatically.

Install

bash
bunx @mem0/opencode-plugin@latest install

Or using OpenCode's built-in CLI:

bash
opencode plugin @mem0/opencode-plugin

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. No manual config needed.

Get your API key (free): app.mem0.ai/dashboard/api-keys

bash
echo 'export MEM0_API_KEY="m0-your-key"' >> ~/.zshrc && source ~/.zshrc

Restart OpenCode.

What's included

ComponentDescription
MCP Server9 memory tools — add, search, get, update, delete memories
Lifecycle HooksAuto-search on session start and every prompt, metadata enforcement, error memory lookup, compaction context
16 Slash Commands/mem0:remember, /mem0:tour, /mem0:stats, /mem0:health, /mem0:dream, and more

Hooks

Pure TypeScript — no Python, no shell scripts. Uses the mem0ai SDK directly.

HookEventWhat it does
Chat messagechat.messageLoads prior memories on session start, searches relevant memories before each prompt, auto-captures learnings periodically
Pre-tooltool.execute.beforeBlocks MEMORY.md writes, enforces user_id/app_id on mem0 tools
Post-tooltool.execute.afterTracks stats, scans bash errors for related memories
System transformexperimental.chat.system.transformInjects memory context (session memories, search results, error lookups) into system prompt
Compactionexperimental.session.compactingStores 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 shell

MCP Tools

ToolDescription
add_memorySave text or conversation history
search_memoriesSemantic search across memories
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 an entity and its memories
list_entitiesList users/agents/apps stored in Mem0

Verify

Start OpenCode and ask: "Search my memories for recent decisions"

If the mem0 tools respond, you're all set.

Troubleshooting

ProblemFix
No tools appearingRestart OpenCode after installing
401 Unauthorizedecho $MEM0_API_KEY must print your m0- key
Plugin not loadingRun opencode plugin @mem0/opencode-plugin again

License

Apache-2.0