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 and using a skill-based memory protocol to automatically retrieve context and store learnings.

Overview

  1. MCP Server — Connect to Mem0’s remote MCP server for memory tools (add, search, update, delete)
  2. Memory Protocol Skill — Instructs the agent to retrieve memories at task start, store learnings on completion, and capture session state before context loss
  3. Plugin Marketplace — Install via Codex’s repo-level or personal plugin marketplace
  4. Zero local dependencies — Cloud-hosted MCP server, no local setup required

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 exported in your shell:
export MEM0_API_KEY="m0-your-api-key"

Installation

Add a .agents/plugins/marketplace.json to your repository root:
{
  "name": "mem0-plugins",
  "interface": {
    "displayName": "Mem0 Plugins"
  },
  "plugins": [
    {
      "name": "mem0",
      "source": {
        "source": "local",
        "path": "./plugins/mem0"
      },
      "policy": {
        "installation": "AVAILABLE",
        "authentication": "ON_INSTALL"
      },
      "category": "Productivity"
    }
  ]
}
Then in Codex, browse the repo’s plugin directory and install Mem0.

Option B — Personal Marketplace

Add to ~/.agents/plugins/marketplace.json:
{
  "name": "mem0-plugins",
  "interface": {
    "displayName": "Mem0 Plugins"
  },
  "plugins": [
    {
      "name": "mem0",
      "source": {
        "source": "local",
        "path": "/path/to/mem0-plugin"
      },
      "policy": {
        "installation": "AVAILABLE",
        "authentication": "ON_INSTALL"
      },
      "category": "Productivity"
    }
  ]
}

Option C — Manual MCP Configuration

Add to your Codex MCP config:
{
  "mcpServers": {
    "mem0": {
      "type": "http",
      "url": "https://mcp.mem0.ai/mcp/",
      "headers": {
        "Authorization": "Token ${MEM0_API_KEY}"
      }
    }
  }
}
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
Memory Protocol SkillYesNo
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

Memory Protocol Skill

Codex uses a skill-based approach instead of lifecycle hooks. When installed via the plugin marketplace, the memory protocol skill instructs the agent to:

On Every New Task

  1. Call search_memories with a query related to the current task to load relevant context
  2. Review returned memories to understand what was learned in prior sessions
  3. Optionally call get_memories to browse all stored memories

After Completing Significant Work

Store key learnings using add_memory with structured metadata:
What to storeMetadata 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:
{
  "name": "mem0",
  "version": "0.1.0",
  "description": "Mem0 memory layer for AI applications.",
  "skills": "./skills/",
  "mcpServers": "./.codex-mcp.json",
  "interface": {
    "displayName": "Mem0",
    "shortDescription": "Persistent memory layer for AI coding workflows",
    "category": "Productivity",
    "capabilities": ["Read", "Write"]
  }
}

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 in your shell: echo $MEM0_API_KEY
  • No tools appearing — Restart your Codex session after plugin installation
  • Plugin not found — Ensure .agents/plugins/marketplace.json is at the repository root and source.path points to the correct plugin directory
  • Skills not loading — Verify the skills field in plugin.json points to a valid directory containing SKILL.md files

Mem0 MCP Setup

Detailed MCP configuration for all clients

Claude Code Integration

Add Mem0 memory to Claude Code workflows