Prerequisites
Before setting up Mem0 with Claude Code, ensure you have:-
A Mem0 Platform account and API key:
- Sign up at app.mem0.ai
- Get your API key (starts with
m0-)
- Claude Code CLI or Claude Cowork desktop app installed
- Your API key added to your shell profile (persists across sessions):
Installation
Option A — Plugin Marketplace (Recommended)
Install the full plugin including MCP server, lifecycle hooks, and SDK skill.-
Add the Mem0 marketplace:
-
Install the plugin:
Option B — MCP Only
Add the Mem0 MCP server directly with a single command:Option C — Manual MCP Configuration
Add to your Claude Code MCP config (.mcp.json):
Start a new session and ask: “List my mem0 entities” or “Search my memories for hello”. If the
mem0 tools appear and respond, you’re all set.Post-Installation: Run /mem0:onboard
After installing the plugin, start a new Claude Code session and run:
- Verifies your API key and MCP connection
- Detects and imports project files (
CLAUDE.md,AGENTS.md,.cursorrules) - Installs coding-optimized memory categories
- Shows your identity (user ID, project scope, branch)
What’s Included
| Component | Plugin Install | MCP Only |
|---|---|---|
| MCP Server (9 memory tools) | Yes | Yes |
| Lifecycle Hooks | Yes | No |
| Mem0 SDK Skill | Yes | No |
Available MCP Tools
Once installed, the following tools are available in every Claude Code session:| 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
When installed via the plugin marketplace, Mem0 hooks into Claude Code’s lifecycle to automatically manage memory:| Hook | Event | What it does |
|---|---|---|
| Session start | SessionStart | Loads prior memories and displays status banner |
| User prompt | UserPromptSubmit | Searches relevant memories before each message; skips short prompts |
| Pre-tool | PreToolUse | Blocks MEMORY.md writes, enforces user_id/app_id on mem0 tool calls |
| Post-tool | PostToolUse | Tracks stats, scans bash errors for related memories |
| Pre-compact | PreCompact | Stores a session summary before context compaction |
Example Workflow
Troubleshooting
- “Connection failed” — Verify
MEM0_API_KEYis set in your shell:echo $MEM0_API_KEY. If empty, add it to your shell profile (see Prerequisites) - No tools appearing — Restart your Claude Code session after installation
- Memories not being captured — Ensure you installed via the plugin marketplace (Option A) for lifecycle hooks. MCP-only installs require manual memory operations
- “Mem0 Inactive” banner every session — Your API key isn’t persisting. Add
export MEM0_API_KEY="m0-..."to your~/.zshrc(or~/.bashrc) and runsource ~/.zshrc
Mem0 MCP Setup
Detailed MCP configuration for all clients
Codex Integration
Add Mem0 memory to OpenAI Codex workflows