# Codex Memory: How to Add Persistent Memory to Codex CLI

*Give Codex Long-Term Memory in 2 Minutes*

Published: 2026-11-04 · Updated: 2026-11-17 · Author: Membase Team  
Source: https://membase.com/blog/codex-memory

> *Disclosure: Membase is our product. Codex’s built-in memory works well for many solo projects, and we say where. Codex features were checked against OpenAI’s Codex documentation in November 2026.*

## Quick answer

Codex has two kinds of built-in memory:

- **AGENTS.md:** instructions you write. Codex loads them at the start of every session.
- **Memories:** notes Codex generates from your past chats, stored locally under ~/.codex (memories_v2/ in a fresh setup, memories/ if you already had one). They are off by default.

Codex still forgets in four places: on your other machines, for your teammates, in your other AI tools, and once your AGENTS.md files pass the 32 KiB limit. To fix that, add a memory layer that lives outside one machine. With Membase it takes one command:

```bash
npx add-mcp 'https://api.app.membase.com/mcp-http'
```

**In this guide:** [Does Codex remember past conversations?](https://membase.com/blog/codex-memory#does-codex-remember-past-conversations) · [AGENTS.md](https://membase.com/blog/codex-memory#agentsmd-memory-you-write) · [Codex Memories](https://membase.com/blog/codex-memory#codex-memories-memory-codex-writes) · [Why Codex forgets](https://membase.com/blog/codex-memory#why-codex-forgets) · [What forgetting looks like](https://membase.com/blog/codex-memory#what-forgetting-looks-like) · [Your options](https://membase.com/blog/codex-memory#your-options-for-longer-lasting-codex-memory) · [Add persistent memory with Membase](https://membase.com/blog/codex-memory#add-persistent-memory-with-membase) · [FAQ](https://membase.com/blog/codex-memory#faq)

## Does Codex remember past conversations?

Not by default.

Inside one session, Codex remembers everything in its context window. You can reopen an earlier session with codex resume, but a new session doesn’t see it. With Memories off, a new session starts from AGENTS.md, your repo and your prompt.

So memory in Codex means files: the ones you write (AGENTS.md) and, if you turn them on, the ones Codex writes (Memories).

## AGENTS.md: memory you write

AGENTS.md is a Markdown file of instructions. Codex reads it before it starts work.

It can live at several levels:

| Level | Location | Use it for |
| --- | --- | --- |
| Global | ~/.codex/AGENTS.md | Your personal defaults in every project |
| Project | AGENTS.md in the repository root | Team conventions, committed to the repo |
| Folder | AGENTS.md in a subfolder | Rules for one part of the codebase |
| Override | AGENTS.override.md at any level | Replaces the AGENTS.md next to it, for example a temporary rule |

How it loads:

- Codex reads the global file first, then walks from the project root down to your current folder.
- In each folder it checks AGENTS.override.md, then AGENTS.md, and uses at most one file per folder.
- It stops adding files once their combined size reaches 32 KiB. Raise the limit with project_doc_max_bytes in ~/.codex/config.toml, or split instructions across folders.

Other coding agents read AGENTS.md too, so one well-kept file can guide Codex, Cursor and Claude Code (which can import it with @AGENTS.md). More on this: [AGENTS.md vs CLAUDE.md vs SKILL.md](https://membase.com/blog/agents-md-vs-claude-md).

**Good for:** stable rules. Build and test commands, coding style, review rules.

**Not good for:** decisions you make while working. Codex won’t add them to AGENTS.md unless you ask.

## Codex Memories: memory Codex writes

Memories let Codex carry useful context from earlier threads into future work: your preferences, recurring workflows and lessons from past tasks.

**Turn it on** in the ChatGPT desktop app under **Settings > Personalization > Enable Codex memories**, or add this to ~/.codex/config.toml:

```toml
[features]
memories = true
```

How it works:

- Codex turns useful context from eligible past chats into local memory files. It skips active or short-lived sessions and redacts secrets.
- It updates memories in the background, after a chat has been idle for a while, so a memory may not appear right after a chat ends. It can also skip a pass when you’re close to your Codex rate limit.
- Type /memories in a session to choose whether that chat can use existing memories or be used to create new ones. This doesn’t change your global settings.
- The setting is per machine. Turning Memories on one computer doesn’t turn them on another.
- Treat the files as generated state. You can read them, but OpenAI doesn’t recommend editing them by hand as your main way to control memory.

**Memories v2.** When you turn Memories on in a fresh Codex home, the CLI stores them in ~/.codex/memories_v2/. If ~/.codex/memories/ already exists, it keeps using that folder. Set memories.version in config.toml to choose a version explicitly.

**Useful settings** in config.toml:

| Setting | What it controls |
| --- | --- |
| memories.generate_memories | Whether new chats can be used to create memories |
| memories.use_memories | Whether Codex adds existing memories to new sessions |
| memories.disable_on_external_context | When true, chats that used MCP tools, web search or tool search aren't used to create memories |

To start over, use **Delete Codex memories** in the same settings page.

Rules that must always apply belong in AGENTS.md, not in Memories.

## Why Codex forgets

Codex’s built-ins are designed for one developer, on one machine, in one tool. Outside that, they forget:

1. **On your other machines.** Memories live in ~/.codex on the machine that wrote them. A second laptop, a server or a cloud sandbox starts with nothing but what’s committed in AGENTS.md.
2. **For your teammates.** Memories are per user. A teammate’s Codex doesn’t know what yours learned last week.
3. **In your other AI tools.** Claude Code, Cursor and ChatGPT keep their own memory. A decision made in Codex doesn’t reach them.
4. **Past the size limit.** Codex stops loading AGENTS.md files once they add up to 32 KiB. Files further down the tree are left out.

And if Memories are off, which is the default, a decision you didn’t write into AGENTS.md is simply gone next session.

## What forgetting looks like

On Monday, you and Codex agree that list endpoints use cursor-based pagination and never offset. The old endpoints still use offset.

| When | Where | What Codex suggests |
| --- | --- | --- |
| Tuesday | Same laptop, Memories off | Offset: nothing saved the decision |
| Tuesday | Same laptop, Memories on | Cursor-based, if Codex kept it |
| Wednesday | Your other laptop | Offset: Memories didn’t come with you |
| Thursday | Your teammate’s Codex | Offset: the decision lives on your machine |
| Friday | Claude Code | Offset: Claude Code never saw the conversation |

Nothing is broken. The memory just isn’t where the work is.

## Your options for longer-lasting Codex memory

| Option | Setup | Works across machines | Shared with teammates | Shared with other AI tools | Cost |
| --- | --- | --- | --- | --- | --- |
| AGENTS.md, updated by hand | None | If committed to git | If committed to git | Agents that read AGENTS.md | Free |
| Codex Memories | One setting | No | No | No | Free |
| Local memory plugin | One install | No | No | Some | Usually free |
| Hosted memory plugin or MCP server | One install | Yes | Depends on the tool | Yes | Varies |
| Membase | One command | Yes | Yes, with a key scoped to the same Memory | Yes: Claude Code, Gemini CLI, Cursor, ChatGPT, Claude | Free, then $19/mo |

For a wider comparison, see [Best MCP Memory Servers in 2026](https://membase.com/blog/best-mcp-memory-servers).

## Add persistent memory with Membase

Membase is a memory layer for AI agents. It keeps one memory outside any single machine or tool, so Codex can save what matters and bring it back in the next session, wherever you work.

What it does differently:

- **Recalls on every prompt, automatically.** With the Codex hooks, relevant memory is added at session start and to every message you send. Codex doesn’t have to decide to look.
- **Never blocks you.** Recall waits up to 10 seconds; if Membase is slow, Codex moves on and the results arrive with your next prompt.
- **Saves in the background.** Your sessions are saved without slowing Codex down.
- **One memory, everywhere.** The same Memory works on every machine and in Claude Code, Gemini CLI and Cursor. Give each teammate’s agent its own key scoped to that Memory, and revoke it any time.
- **Every answer has a source.** Each search result points back to the session or document it came from.
- **Hosted or local.** Use the hosted service, or keep memory on your own machine with local mode.
- **Fewer tokens.** Membase’s engine scores 93.1% on LoCoMo while using up to 11x fewer tokens than the full history (our own numbers; [see the method](https://membase.com/research)).

**Set it up in 2 minutes:**

**1.** Sign up at [app.membase.com](https://app.membase.com), open Connect > Developer keys and create a key. Create a Memory named after your repo.

**2.** Add Membase to Codex:

```bash
export MEMBASE_API_KEY=mbk_your_key
codex mcp add membase --url https://api.app.membase.com/mcp-http --bearer-token-env-var MEMBASE_API_KEY
```

Run codex mcp list to check the connection.

**3.** For automatic recall on every prompt, install the Codex hooks: follow [Membase Use Case 01](https://membase.com/blog/membase-use-case-01-coding-agents). The same installer works for Claude Code and Gemini CLI. Codex hooks don’t currently run on Windows; there, use the MCP connection on its own.

**4.** Test it: decide something specific, quit, open a new session and ask about it without mentioning it.

**Tip:** add one line to your AGENTS.md, such as “Before starting a task, search Membase for past decisions about this code.” Codex then checks memory even without the hooks.

## Use it alongside AGENTS.md and Memories

You don’t have to choose. Each layer has its job:

| Layer | Keep here |
| --- | --- |
| AGENTS.md | Rules that should always apply: commands, coding style, review rules |
| Codex Memories | What Codex learns on this machine |
| Membase | Decisions and context that must follow you across machines, teammates and tools |

## Common mistakes

- **Putting everything in AGENTS.md.** Past 32 KiB, files stop loading. Keep rules there and let memory hold the rest.
- **Expecting Memories to be on.** They’re off by default, and set per machine. Turn them on, or decisions won’t carry over.
- **Editing the memories folder by hand.** It’s generated state. Put rules you want to control in AGENTS.md.
- **One memory for every repo.** Create one Memory per repository so projects don’t mix.

## Quick links

- [Membase web app](https://app.membase.com): create a key and a Memory
- [Membase Use Case 01](https://membase.com/blog/membase-use-case-01-coding-agents): install the hooks for Codex, Claude Code and Gemini CLI
- [How to Add Persistent Memory to Claude Code](https://membase.com/blog/claude-code-memory)
- [AGENTS.md vs CLAUDE.md vs SKILL.md](https://membase.com/blog/agents-md-vs-claude-md): instruction files for Codex and other coding agents
- [OpenClaw Memory](https://membase.com/blog/openclaw-memory): import Codex memory into OpenClaw, or share one memory with it
- [Codex Memories](https://learn.chatgpt.com/docs/customization/memories): OpenAI’s official documentation
- MCP server: [https://api.app.membase.com/mcp-http](https://api.app.membase.com/mcp-http)
- [Membase docs](https://docs.membase.com)

Membase has a free plan, then $19 or $69 a month.

See also: [Cross AI Memory: How to Use One Memory Across ChatGPT, Claude, Cursor and More](https://membase.com/blog/cross-ai-memory)

## Frequently Asked Questions

### Does Codex have memory?

Yes. AGENTS.md files you write load every session, and Memories, which Codex generates from past chats, can be turned on.

### Does Codex remember past conversations?

Not by default. Memories are off unless you turn them on. With them off, a new session starts from AGENTS.md, your repo and your prompt.

### How do I turn on Codex Memories?

In the ChatGPT desktop app, open Settings > Personalization and turn on Enable Codex memories. Or add memories = true under [features] in ~/.codex/config.toml.

### Where does Codex store memories?

On your machine, under ~/.codex: in memories_v2/ for a fresh setup, or memories/ if that folder already existed.

### What is Codex Memories v2?

The newer local memory store. A fresh Codex home uses ~/.codex/memories_v2/ by default; an existing ~/.codex/memories/ keeps being used. Set memories.version in config.toml to choose one.

### Why can’t I turn on Codex Memories?

The setting is per machine, so turning it on one computer doesn’t turn it on another. Check Settings > Personalization > Enable Codex memories in the ChatGPT desktop app, or the [features] flag in config.toml for the CLI.

### How big can AGENTS.md be?

Codex stops adding AGENTS.md files once their combined size reaches 32 KiB. Raise the limit with project_doc_max_bytes or split instructions across folders.

### Does Codex memory sync across machines?

No. Memories stay on the machine that wrote them. Only what you commit in AGENTS.md travels with the repo. Use a hosted memory layer to sync.

### Can Codex and Claude Code share memory?

They can share instructions through AGENTS.md, but not what each one learns. Connect both to the same memory layer, such as Membase.

### Can I use Membase with AGENTS.md and Codex Memories?

Yes. Keep rules in AGENTS.md, let Memories handle local learnings, and use Membase for what must follow you across machines, teammates and tools.
