Integrates Mem0 universal memory layer with OpenCode for intelligent long-term memory capabilities.
Traditional AI assistants have no memory - they forget everything after each conversation. Mem0 changes this by providing:
- Multi-Level Memory: Adaptive personalization across users, sessions, and agents
- Semantic Search: Retrieve relevant memories using natural language queries
- Cost Efficient: Reduces token usage by 90% compared to full context
- Developer-Friendly: Intuitive API, cross-platform SDKs, and fully managed service option
- Continuous Learning: Remembers user preferences and adapts to individual needs over time
- Add Memory: Store user preferences, facts, and information
- Semantic Search: Retrieve relevant memories using natural language
- Get All Memories: Retrieve all memories for a user, agent, or session
- Delete Memory: Delete specific memories or all matching memories
- Memory History: Get all versions and changes of memories
- Session Compaction: Auto-inject memory context during session compaction
# Clone the repository
git clone https://github.com/allbugterminator/opencode-mem0-plugin.git
# Copy to global plugin directory
mkdir -p ~/.config/opencode/plugins/
cp -r opencode-mem0-plugin ~/.config/opencode/plugins/mem0
# Or place in project-level
mkdir -p .opencode/plugins/
cp -r opencode-mem0-plugin .opencode/plugins/mem0Sign up at Mem0 Platform to get your API key.
Create mem0-config.json in the plugin directory:
{
"apiKey": "your-mem0-api-key"
}Or via environment variables:
export MEM0_API_KEY=your-api-keycd ~/.config/opencode/plugins/mem0
bun install
# or use: npm installThe plugin will load automatically on next startup.
| Option | Type | Default | Description |
|---|---|---|---|
apiKey |
string | - | Mem0 Cloud API key (required) |
orgId |
string | - | Mem0 Organization ID (optional, for multi-tenant) |
projectId |
string | - | Mem0 Project ID (optional, for project isolation) |
host |
string | https://api.mem0.ai |
Self-hosted Mem0 server URL |
Store information in Mem0 memory. Use to remember facts, preferences, skills, and important context.
mem0_add memory="User prefers using VS Code for development" userId="user123"
mem0_add memory="User prefers dark theme" userId="user123" metadata={"category": "preference"}
Retrieve relevant memories using natural language query. Fast embedding-based retrieval.
mem0_search query="What development tools does user prefer" userId="user123" limit=5
mem0_search query="User's work preferences" agentId="assistant" sessionId="session1"
Get all memories for a user, agent, or session. Complete listing of stored memories.
mem0_get_all userId="user123" limit=10
mem0_get_all sessionId="session1"
Delete a specific single memory.
mem0_delete memoryId="mem_xxx"
Delete all memories matching criteria. Must specify at least one filter.
mem0_delete_all userId="user123"
mem0_delete_all sessionId="session1"
Get history of a memory - all changes and versions.
mem0_get_history memoryId="mem_xxx"
User: I prefer receiving project progress summaries in the afternoon.
Agent: I'll remember that you prefer afternoon summaries. Let me store this preference.
Call mem0_add to store this preference for future reference.
When user asks "What did I work on last time?", the Agent:
- Calls
mem0_searchto query relevant memories - Gets memories about past projects
- Provides personalized, context-aware response
During session compaction, the Mem0 plugin automatically retrieves relevant memories and injects them into context, ensuring:
- New agents can resume from where they left off
- Important context is not lost
- Conversation continuity is maintained
┌─────────────────┐ ┌─────────────────┐
│ OpenCode │ │ Mem0 │
│ Agent │────►│ Memory │
│ │ │ Service │
└─────────────────┘ └─────────────────┘
│ │
│ Tools: │ Storage:
│ - mem0_add │ - Vector Store
│ - mem0_search │ (Qdrant, Chroma, etc.)
│ - mem0_get_all │
│ - mem0_delete │ LLM Providers:
│ │ - OpenAI
│ - Anthropic
│ - Custom
To use self-hosted Mem0 service:
{
"apiKey": "your-api-key",
"host": "http://localhost:8000"
}See Mem0 docs for detailed self-hosted guide.
- Bun (to run OpenCode)
- Mem0 npm package:
mem0ai - Mem0 API Key (for cloud) or self-hosted Mem0 server
Check if plugin directory exists:
ls ~/.config/opencode/plugins/Ensure mem0-config.json is correct, or set environment variables:
echo $MEM0_API_KEYManually install dependencies:
cd ~/.config/opencode/plugins/mem0
bun add mem0ai- Verify
userId,agentId,sessionIdparameters are correct - Check if Mem0 Cloud account has sufficient quota
- Mem0 - Universal memory layer for AI Agents
- OpenCode Plugins Docs - OpenCode plugin development guide
- mem0ai npm - Mem0 JavaScript SDK
Apache License 2.0 - See LICENSE for details.
If you find this plugin useful, please star the Mem0 repository!