OpenAI Codex CLI Memory Options Comparison
| Feature / Aspect | Native Codex CLI | Codex CLI + Memoreal MCP | Operational Benefit |
|---|---|---|---|
| Configuration Location | ~/.codex/config.toml | ~/.codex/config.toml [mcp_servers.memoreal] | Native TOML configuration file integration |
| Authentication Method | API Keys or ChatGPT OAuth | RFC 8628 Device Flow or MEMOREAL_API_KEY | Secure browser pairing on remote SSH and containers |
| Session Memory | Ephemeral subagent context | Persistent 4-tier cognitive memory | Subagents retain decisions across multiple CLI turns |
| Code Intelligence | Greps and filesystem reads | AST search_code, impact, and call_tree | Reduces multi-file token consumption by up to 70% |
How OpenAI Codex CLI Interacts with Model Context Protocol Servers
OpenAI Codex CLI provides a powerful terminal interface for autonomous software engineering, allowing developers to spawn background subagents, execute unit tests, and refactor complex multi-module systems.
By default, Codex subagents operate with an ephemeral memory buffer that resets when a task concludes. By wiring Codex to an external MCP server, subagents can record their findings, review historical bug causes, and pass structured handoff payloads to subsequent worker processes.
- Codex CLI parses MCP server definitions from the ~/.codex/config.toml configuration file.
- Subagents can autonomously invoke MCP tools to query past architectural precedents before writing code.
- Persistent memory reduces repetitive prompt explanations across independent CLI executions.
Configuring ~/.codex/config.toml with Memoreal Persistent Memory
To enable Memoreal in Codex CLI, open or create ~/.codex/config.toml in your home directory. Add a dedicated [mcp_servers.memoreal] block specifying the executable command and arguments.
The standard configuration uses npx to run @kolivri/memoreal-mcp on demand. You can pass your MEMOREAL_API_KEY inside the [mcp_servers.memoreal.env] table, or omit it if you prefer authenticating interactively via browser OAuth on your workstation.
- Ensure TOML table headers correctly match [mcp_servers.<name>] syntax.
- Environment variables defined in the configuration are automatically passed to the spawned process.
- You can run codex mcp test memoreal to verify process spawning and tool discovery.
RFC 8628 Headless Terminal Authentication and Pairing
When running Codex CLI in headless cloud environments, Docker containers, or remote SSH sessions, manually copying and pasting long secret API keys can be insecure and awkward.
Memoreal supports RFC 8628 (OAuth 2.1 Device Authorization Grant). When you initiate pairing, the CLI displays a short, human-friendly 8-character verification code and a pairing URL. Visiting the URL in any authenticated browser approves the CLI session instantly, establishing an encrypted token pair without leaking secrets to terminal scrollback.
- RFC 8628 eliminates the need to expose long-lived production secrets in plaintext config files.
- Pairing works seamlessly through jump hosts, cloud devboxes, and remote devcontainers.
- Tokens can be revoked immediately from the Memoreal cloud management dashboard if a laptop is lost.
Configuring Memoreal MCP in ~/.codex/config.toml
toml# ~/.codex/config.toml
# Register Memoreal persistent memory and code intelligence server
[mcp_servers.memoreal]
command = "npx"
args = ["-y", "@kolivri/memoreal-mcp@latest"]
[mcp_servers.memoreal.env]
MEMOREAL_API_KEY = "mem_live_YOUR_API_KEY"
Frequently Asked Questions
Does Codex CLI support hot-reloading MCP configuration changes in config.toml?
Codex CLI reads config.toml at startup. If you edit the configuration file while a session is running, you must exit and restart the CLI to establish new MCP connections.
Can Codex CLI subagents share memory with Cursor Composer or Claude Code?
Yes, because Memoreal indexes memories in a unified cloud or team workspace namespace, memories recorded by Codex CLI in your terminal are immediately accessible in Cursor and Claude Code.
What is the advantage of using blast-radius tools like impact in Codex CLI?
Instead of scanning dozens of files using grep or reading entire directories into context, the impact tool uses AST call graphs to return exact upstream callers in under 15ms, saving thousands of tokens.
Install Persistent Memory for Your Coding Agent
Sub-15ms deterministic recall, AST symbol navigation, and 70%+ token savings across Claude Code, Cursor, Codex CLI, and Windsurf.
npx -y @kolivri/memoreal-mcp setup