Skip to content
Membase
Codex Memory: How to Add Persistent Memory to Codex CLI

Codex Memory: How to Add Persistent Memory to Codex CLI

Give Codex Long-Term Memory in 2 Minutes

Research
MembaseMembase Team
View the original post on Medium

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 threads, stored in ~/.codex/memories/. 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:

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

In this guide: Does Codex remember past conversations? · AGENTS.md · Codex Memories · Why Codex forgets · What forgetting looks like · Your options · Add persistent memory with Membase · 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:

LevelLocationUse it for
Global~/.codex/AGENTS.mdYour personal defaults in every project
ProjectAGENTS.md in the repository rootTeam conventions, committed to the repo
FolderAGENTS.md in a subfolderRules for one part of the codebase
OverrideAGENTS.override.md at any levelReplaces 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).

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.

How it works:

  • Turn it on in the Codex app settings, or add this to ~/.codex/config.toml:

    [features]
    memories = true
    
  • Codex turns useful context from eligible past threads into local files under ~/.codex/memories/. It skips active or short-lived sessions and redacts secrets.

  • Type /memories in a session to choose whether that thread can use existing memories or be used to create new ones.

  • Treat the files as generated state. You can read them, but OpenAI doesn’t recommend editing them by hand.

  • At launch, Memories aren’t available in the European Economic Area, the United Kingdom or Switzerland.

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.

WhenWhereWhat Codex suggests
TuesdaySame laptop, Memories offOffset: nothing saved the decision
TuesdaySame laptop, Memories onCursor-based, if Codex kept it
WednesdayYour other laptopOffset: Memories didn’t come with you
ThursdayYour teammate’s CodexOffset: the decision lives on your machine
FridayClaude CodeOffset: 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

OptionSetupWorks across machinesShared with teammatesShared with other AI toolsCost
AGENTS.md, updated by handNoneIf committed to gitIf committed to gitAgents that read AGENTS.mdFree
Codex MemoriesOne settingNoNoNoFree
Local memory pluginOne installNoNoSomeUsually free
Hosted memory plugin or MCP serverOne installYesDepends on the toolYesVaries
MembaseOne commandYesYes, with a key scoped to the same MemoryYes: Claude Code, Gemini CLI, Cursor, ChatGPT, ClaudeFree in beta

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).

Set it up in 2 minutes:

  1. Sign up at app.membase.com, open Connect > Developer keys and create a key. Create a Memory named after your repo.

  2. Add Membase to Codex:

    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. 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:

LayerKeep here
AGENTS.mdRules that should always apply: commands, coding style, review rules
Codex MemoriesWhat Codex learns on this machine
MembaseDecisions 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. Turn them on, or decisions won’t carry over.
  • Editing ~/.codex/memories/ 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.

Membase is in beta and free during the beta.

Frequently Asked Questions

Does Codex have memory?
Yes. AGENTS.md files you write load every session, and Memories, which Codex generates from past threads, 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?
Enable Memories in the Codex app settings, or add memories = true under [features] in ~/.codex/config.toml.
Where does Codex store memories?
In ~/.codex/memories/ on your machine.
Why can’t I turn on Codex Memories?
At launch, Memories aren’t available in the European Economic Area, the United Kingdom or Switzerland. AGENTS.md works everywhere.
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.
Back to all posts