Add persistent memory to OpenAI Codex with the Mem0 plugin. Codex forgets everything between tasks — this plugin fixes that by connecting to Mem0’s cloud memory layer via MCP and using a skill-based memory protocol to automatically retrieve context and store learnings.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.
Overview
- MCP Server — Connect to Mem0’s remote MCP server for memory tools (add, search, update, delete)
- Memory Protocol Skill — Instructs the agent to retrieve memories at task start, store learnings on completion, and capture session state before context loss
- Plugin Marketplace — Install via Codex’s repo-level or personal plugin marketplace
- Zero local dependencies — Cloud-hosted MCP server, no local setup required
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 exported in your shell:
Installation
Option A — Direct MCP (Recommended)
The fastest way to connect Codex to Mem0 — no downloads, no marketplace. Codex reads MCP servers from~/.codex/config.toml as TOML. Add:
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).Option B — Sideload the Plugin (Advanced)
For the full plugin experience — MCP server plus the Mem0 SDK skill, memory protocol skill, and opt-in lifecycle hooks — sideload the plugin from a local clone. The Mem0 repo already ships a marketplace manifest at.agents/plugins/marketplace.json, so there’s no JSON to author by hand. This follows the Codex build-plugins local-testing workflow.
Don’t combine Option B with Option A. The plugin manifest declares its MCP server via
.codex-mcp.json, so Codex auto-registers the mem0 MCP server when the plugin loads. Adding the same [mcp_servers.mem0] block to ~/.codex/config.toml will create a duplicate registration..agents/plugins/marketplace.json. The bundled file uses path: "./mem0-plugin", which Codex resolves relative to the clone root.
Why we recommend this over hand-authoring
~/.agents/plugins/marketplace.json: Codex requires source.path in any marketplace manifest to be relative (starting with ./) and inside the marketplace root. The repo’s bundled manifest already satisfies this — the marketplace root is the clone directory, and mem0-plugin/ lives inside it. With a personal ~/.agents/plugins/marketplace.json, the root is ~/ and the clone has to live under ~/ too. The CLI form sidesteps that constraint./plugins, browse the Mem0 Plugins marketplace, and install Mem0.
Step 4 (optional) — enable lifecycle hooks. Codex doesn’t auto-wire hooks from plugin manifests; it only reads them from ~/.codex/hooks.json (or <repo>/.codex/hooks.json). Run the bundled installer once to merge the Mem0 entries into your global hooks file:
~/.codex/config.toml:
| Event | Behavior |
|---|---|
SessionStart | Loads prior memories as bootstrap context |
UserPromptSubmit | Injects relevant memories before each prompt |
Stop | Reminds the agent to persist learnings at turn end |
python3 ~/codex-plugins/mem0-source/mem0-plugin/scripts/install_codex_hooks.py --uninstall.
Managing the Plugin
Codex provides CLI commands for managing marketplaces after install:git pull inside your clone (~/codex-plugins/mem0-source) and then run codex plugin marketplace upgrade to refresh Codex’s plugin cache. Plugins are cached at ~/.codex/plugins/cache/<marketplace>/<plugin>/<version>/.
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 | Sideloaded Plugin | Direct MCP |
|---|---|---|
| MCP Server (9 memory tools) | Yes | Yes |
| Memory Protocol Skill | Yes | No |
| Mem0 SDK Skill | Yes | No |
| Lifecycle Hooks (opt-in) | 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 |
Memory Protocol Skill
When the plugin is sideloaded, the memory protocol skill instructs the agent to:On Every New Task
- Call
search_memorieswith a query related to the current task to load relevant context - Review returned memories to understand what was learned in prior sessions
- Optionally call
get_memoriesto browse all stored memories
After Completing Significant Work
Store key learnings usingadd_memory with structured metadata:
| What to store | Metadata type |
|---|---|
| Architectural decisions | {"type": "decision"} |
| Strategies that worked | {"type": "task_learning"} |
| Failed approaches | {"type": "anti_pattern"} |
| User preferences observed | {"type": "user_preference"} |
| Environment discoveries | {"type": "environmental"} |
| Conventions established | {"type": "convention"} |
Before Losing Context
Store a comprehensive session summary including goals, accomplishments, decisions, files modified, and current state with metadata{"type": "session_state"}.
Plugin Manifest
The Codex plugin manifest (.codex-plugin/plugin.json) follows the Codex plugin specification:
Example Workflow
Troubleshooting
- “Connection failed” — Verify
MEM0_API_KEYis set in your shell:echo $MEM0_API_KEY - No tools appearing — Restart your Codex session after plugin installation
- Duplicate
mem0MCP server / “tool collision” errors — You combined Option A (Direct MCP) with Option B (sideload). The sideloaded plugin auto-registersmem0from.codex-mcp.json, so remove the[mcp_servers.mem0]block from~/.codex/config.toml. plugin/read failed in TUI— Codex can’t find the plugin directory the marketplace points at. If you usedcodex plugin marketplace add <path>, confirm the path is your clone root and that<clone>/.agents/plugins/marketplace.jsonexists. If you hand-authored~/.agents/plugins/marketplace.json,source.pathmust be relative (start with./), inside the marketplace root (~/for personal installs), and end inmem0-plugin— e.g."./codex-plugins/mem0-source/mem0-plugin".- Plugin not found in
/plugins— Runcodex plugin marketplace add ~/path/to/cloneagain, or confirm the marketplace was registered withcodex plugin marketplace remove mem0-pluginsthen re-add. - Skills not loading — Verify the
skillsfield inplugin.jsonpoints to a valid directory containingSKILL.mdfiles. - Hooks not firing — Confirm
codex_hooks = trueis in~/.codex/config.tomlunder[features], and that~/.codex/hooks.jsoncontains the Mem0 entries (re-run the installer if not). Restart Codex after enabling the flag. - Hooks broke after moving the clone — The installer bakes absolute paths into
~/.codex/hooks.jsonpointing at scripts inside your clone. If you moved or renamed the clone directory, runpython3 <new-clone>/mem0-plugin/scripts/install_codex_hooks.pyfrom the new location — the installer is idempotent and replaces the old entries.
Mem0 MCP Setup
Detailed MCP configuration for all clients
Claude Code Integration
Add Mem0 memory to Claude Code workflows