Skip to main content
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, automatically capturing learnings at key lifecycle points, and retrieving relevant context before every response.

Prerequisites

Before setting up Mem0 with Codex, ensure you have:
  1. A Mem0 Platform account and API key:
  2. OpenAI Codex access
  3. Your API key added to your shell profile (persists across sessions):
echo 'export MEM0_API_KEY="m0-your-api-key"' >> ~/.zshrc
source ~/.zshrc
echo 'export MEM0_API_KEY="m0-your-api-key"' >> ~/.bashrc
source ~/.bashrc

Installation

Install the full plugin including MCP server, lifecycle hooks, and SDK skill.
  1. Add the Mem0 marketplace:
    codex plugin marketplace add mem0ai/mem0
    
  2. Install the plugin:
    codex plugin add mem0@mem0-plugins
    
    Or, in the app: restart Codex, open the Plugin Directory, browse the Mem0 Plugins marketplace, and install Mem0.
Step 1 is required for the app UI. Mem0 isn’t in OpenAI’s curated directory yet, so without codex plugin marketplace add, Mem0 won’t appear in the Codex app’s Plugin Directory: searching for it returns nothing. Adding the marketplace surfaces it (under Created by you) and makes it installable.
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 needs no plugin or marketplace. Add the MCP server with a single command:
codex mcp add mem0 --url https://mcp.mem0.ai/mcp/ --bearer-token-env-var MEM0_API_KEY
Or add it manually to ~/.codex/config.toml:
[mcp_servers.mem0]
url = "https://mcp.mem0.ai/mcp/"
bearer_token_env_var = "MEM0_API_KEY"
Make sure MEM0_API_KEY is exported in the shell you launch Codex from, then restart Codex. This gives you the MCP tools but not the lifecycle hooks or SDK skill.

Managing the Plugin

codex plugin marketplace upgrade               # pull latest plugin versions
codex plugin remove mem0@mem0-plugins          # uninstall the plugin (keeps the marketplace)
codex plugin marketplace remove mem0-plugins   # unregister the marketplace entirely
To update, run 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

ComponentPlugin InstallMCP Only
MCP Server (9 memory tools)YesYes
Lifecycle HooksYesNo
Mem0 SDK SkillYesNo

Available MCP Tools

Once installed, the following tools are available in every Codex session:
ToolDescription
add_memorySave text or conversation history for a user/agent
search_memoriesSemantic search across memories with filters
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 a user/agent/app/run entity and its memories
list_entitiesList 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:
HookEventWhat it does
Session startSessionStartLoads prior memories and displays status banner
User promptUserPromptSubmitSearches relevant memories before each message
Pre-tool (3 handlers)PreToolUseBlocks MEMORY.md writes; enforces user_id/app_id on mem0 tool calls; scans files being read for relevant memory context
Post-toolPostToolUseTracks stats, scans bash errors for related memories
StopStopStores a session summary when the session ends
Pre-compactPreCompactStores a summary before the context is compacted

Example Workflow

# Task 1: Setting up a new service
You: Create a REST API for the notifications service using Express and TypeScript.

# Codex searches memories, finds user preferences from prior tasks.
# After completing the task, Mem0 stores:
#   - Decision: "Notifications service uses Express + TypeScript + Zod validation"
#   - Convention: "All API routes follow /api/v1/{resource} pattern"
#   - Preference: "User prefers explicit error types over generic catch-all"

# Task 2 (days later): Extending the service
You: Add WebSocket support for real-time notification delivery.

# Codex searches memories, retrieves the architecture decisions and conventions.
# Follows the same patterns established in the first task.

Troubleshooting

  • “Connection failed”: Verify MEM0_API_KEY is set: echo $MEM0_API_KEY
  • No tools appearing: Restart your Codex session after installation
  • Duplicate mem0 MCP / “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
https://mintcdn.com/mem0/QK-8_hblyHgAr7vt/images/provider-icons/anthropic.svg?fit=max&auto=format&n=QK-8_hblyHgAr7vt&q=85&s=d2a2af9f60f53e9f21d741fe237af0f5

Claude Code Integration

Add Mem0 memory to Claude Code workflows
Using Mem0? Star us on GitHub to help more developers discover memory for AI apps.