Prerequisites
Before setting up Mem0 with Codex, ensure you have:-
A Mem0 Platform account and API key:
- Sign up at app.mem0.ai
- Get your API key (starts with
m0-)
- OpenAI Codex access
- 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:
- Restart Codex, open the Plugin Directory, browse the Mem0 Plugins marketplace, and install Mem0.
Do not combine with Option B. The plugin manifest auto-registers the
mem0 MCP server, so adding both will create a duplicate registration.Option B — Direct MCP
The fastest way to connect Codex to Mem0 — no plugin, no marketplace. Add to~/.codex/config.toml:
MEM0_API_KEY is exported in the shell you launch Codex from, then restart Codex.
Codex’s
codex mcp add CLI only supports stdio MCP servers. Because Mem0’s MCP is HTTP/streamable, you configure it by editing config.toml directly (or via the Plugins → Connect to a custom MCP → Streamable HTTP UI in the Codex app).Managing the Plugin
codex plugin marketplace upgrade to pull the latest from the Mem0 repo.
After either option, start a new Codex task and ask: “List my mem0 entities” or “Search my memories for hello”. If the
mem0 tools appear and respond, you’re all set.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 Codex 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 Codex’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 |
| 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:echo $MEM0_API_KEY - No tools appearing — Restart your Codex session after installation
- Duplicate
mem0MCP / “tool collision” errors — You combined Option A with Option B. Remove the[mcp_servers.mem0]block from~/.codex/config.toml; the plugin registers it automatically - Hooks not firing — Ensure the plugin is installed via the marketplace (Option A). MCP-only installs do not include hooks
Mem0 MCP Setup
Detailed MCP configuration for all clients
Claude Code Integration
Add Mem0 memory to Claude Code workflows