How to give OpenAI Codex persistent memory with MCP

Last updated

Codex starts each session with only its instructions, such as your AGENTS.md files, and no memory of earlier sessions. To give it a memory it can search and add to, run codex mcp add memlo --url https://memlo.ai/mcp, sign in to Memlo in the browser page that opens, and start a new Codex session. Codex can then save and find memories, and so can Claude Code and your other MCP apps, from the same account.

What Codex keeps between sessions

Codex reads instructions from AGENTS.md files: one in your Codex home folder (~/.codex by default) and others from the root of your Git repository down to the folder you are working in. By default it stops adding files once their combined size reaches 32 KiB (the project_doc_max_bytes setting).

AGENTS.md is good for rules that rarely change: build commands, coding style, where things live. It is not a place to collect every decision a team makes. A memory server holds those instead, and Codex searches it when it needs something.

Set up Memlo in Codex

You need a Memlo account. Accounts are by invitation for now; you can join the waitlist on the home page.

Step 1: Add the server

codex mcp add memlo --url https://memlo.ai/mcp

This writes the server into ~/.codex/config.toml:

[mcp_servers.memlo]
url = "https://memlo.ai/mcp"

Step 2: Sign in

Codex opens a browser page at auth.memlo.ai. Sign in to Memlo and choose Continue on the page that asks to allow Codex to use Memlo. Codex registers itself, so you don't need a client ID or secret.

If the sign-in did not finish, or later expires, sign in again with:

codex mcp login memlo

On a computer without a browser, codex mcp login memlo --no-browser prints the sign-in address instead.

Step 3: Check the connection

codex mcp list

The memlo row should show OAuth under Auth.

Step 4: Start a new session

Start a new Codex session so it loads the server, then ask it to call the whoami tool. It answers with your Memlo account.

Load your memory at the start of every session

Ask Codex to call get_prime_directive first in every session. That tool returns how to use Memlo and your space's prime_memory: what the space is for and its key memories. Codex reads ~/.codex/AGENTS.md in every session, so one line there does it:

At the start of every session, call the memlo MCP tool get_prime_directive and follow what it returns.

Use it

A memory saved from Codex is in the same account as one saved from Claude Code. The guide How to share one memory between AI agents covers working across several agents.

Frequently asked questions

Does Codex have memory between sessions?

Codex reads your AGENTS.md files at the start of every session, up to 32 KiB by default. It does not keep the conversation itself. A memory server adds notes that Codex can search, save and change from any session.

Do I need an API key or a client ID?

No. codex mcp add with the URL is enough. Codex registers itself with Memlo's sign-in and you sign in with your own account.

How do I remove Memlo from Codex?

Run codex mcp logout memlo to remove the saved sign-in, then codex mcp remove memlo to remove the server. To cut off access from the Memlo side, open Account settings in the Memlo app and choose Disconnect next to the app under Connected apps.

Can Codex and Claude Code use the same memories?

Yes. Both connect to the same server and you sign in to the same account, so a memory saved from one is found from the other.

Try Memlo

Memlo is invitation only for now. Join the waitlist and we'll email you when your invitation is ready.

Join the waitlist