Codex memory: AGENTS.md, memories and MCP
How OpenAI Codex remembers across sessions: AGENTS.md in ~/.codex and your repo, local memories, codex resume, and a shared memory server over MCP.
Codex has three kinds of memory. AGENTS.md files are instructions you write, read at the start of every session.
Local memories are notes Codex writes from your past chats, off by default and kept on your machine. codex resume
reopens one saved chat. For memory shared across repos, machines and teammates, you add an MCP memory server in
~/.codex/config.toml.
How Codex reads AGENTS.md
The Codex AGENTS.md docs describe this order:
- Global. In your Codex home (
~/.codex, orCODEX_HOMEif set), Codex readsAGENTS.override.mdif it exists, otherwiseAGENTS.md. Only the first non-empty file counts. - Project. Codex starts at the project root (usually the git root) and walks down to your current directory.
In each directory it checks
AGENTS.override.md, thenAGENTS.md, then any names inproject_doc_fallback_filenames. It takes at most one file per directory. - Merge. Files are joined from the root down. Files closer to your current directory come later, so they override earlier guidance.
Details that matter in practice:
- An
AGENTS.override.mdreplaces theAGENTS.mdin the same directory.~/.codex/AGENTS.override.mdis a temporary global override; delete it to get the base file back. - Empty files are skipped.
- The combined size stops at
project_doc_max_bytes, 32 KiB by default. Past that, Codex adds no more files. Raise the limit or split rules into nested directories. - Codex builds the chain once per run. In the TUI that is once per session, so restart Codex after you edit a file.
/initwrites anAGENTS.mdscaffold in the current directory (slash commands).
To read other file names too, list them in ~/.codex/config.toml:
project_doc_fallback_filenames = ["TEAM_GUIDE.md", ".agents.md"]
project_doc_max_bytes = 65536To check what loaded, run codex --ask-for-approval never "Summarize the current instructions." from the repo root.
The IDE extension shares its agent settings with the CLI through config.toml
(IDE settings).
Codex memories
Codex can also write its own notes. Codex memories turn useful context from past chats into local memory files:
- Off by default. Turn them on with
memories = trueunder[features]inconfig.toml, or in the app underSettings,Personalization. - Generated in the background, after a chat has been idle for a while. Active and short chats are skipped.
- Stored under your Codex home (
~/.codex/memories/, ormemories_v2/in a fresh home). - Secrets are redacted from generated fields, but OpenAI says they are not guaranteed absent. Review the files before you share your Codex home.
/memoriesin the TUI controls whether the current chat uses memories and whether it can become input for new ones.
Settings such as memories.use_memories, memories.generate_memories and memories.disable_on_external_context
(which skips chats that used MCP tools or web search) are in the same docs.
Two limits. The memories are local to one Codex home, and the docs describe no sharing with a team. OpenAI also says
to keep required team guidance in AGENTS.md or checked-in docs, and to treat memories as a recall aid, not the only
place for rules that must always apply.
ChatGPT on the web uses ChatGPT memory, which is separate from local Codex memories.
Resuming a session
Resume is not memory, but it often solves the same problem: picking up where you stopped.
codex resumeopens a picker.--lasttakes the most recent chat in the current directory,--allsearches all directories, or pass a session ID./resumeinside the TUI does the same and reloads the chat's transcript.codex exec resume --last "next step"continues a non-interactive run.codex forkcopies a saved chat into a new one.
See the CLI reference. A resumed chat only knows what was said in that chat.
Add an MCP server in config.toml
Codex keeps MCP servers in ~/.codex/config.toml, shared by the CLI, the IDE extension and the ChatGPT desktop app
(Codex MCP docs). A trusted project can add its own in
.codex/config.toml. Each server gets a [mcp_servers.<name>] table:
[mcp_servers.context7]
command = "npx"
args = ["-y", "@upstash/context7-mcp"]
[mcp_servers.figma]
url = "https://mcp.figma.com/mcp"
bearer_token_env_var = "FIGMA_OAUTH_TOKEN"Or use the CLI: codex mcp add <name> -- <command> for a local server, --url for a remote one, and
codex mcp login <name> for OAuth. codex mcp list shows what is set up, and /mcp lists the tools in a session.
Where AGENTS.md and local memories stop
- Lessons from chat. A correction lands in
AGENTS.mdonly if someone edits the file. Local memories may pick it up, but only on your machine. - Teammates. Another person's Codex never sees your memories.
- Other agents. Claude Code and Cursor do not read Codex memories.
- Knowledge beyond one repo. Servers, accounts and deploy steps have no natural
AGENTS.md. - Rules that must hold. A line in
AGENTS.mdis guidance.
If you work alone in one repo, an AGENTS.md in git plus local memories is often enough. Stop there.
A shared memory server: axs brain
An MCP memory server gives every agent the same store. Over MCP alone, though, the agent has to decide to search,
and agents rarely search for what they do not know they are missing. Codex also supports
hooks (SessionStart, UserPromptSubmit, PreToolUse and more), which a
memory service can use to push memories in.
axs brain uses both. For Codex it adds:
- Memories that come to the agent: your always-on rules at session start, the memories of a project on the first work there, and matching memories on every prompt.
- Lessons saved while you work. When you correct the agent, axs brain asks it to save a short memory. It checks for near-duplicates and refuses secrets.
- One store for Claude Code, Codex and Cursor, with private and team spaces. See Memories and spaces.
- Rules that block a command, ask first or remind, from the hooks.
Setup
Install the axs CLI, then:
axs login
axs install codexThis adds the axs brain hooks to ~/.codex/hooks.json and the MCP server to ~/.codex/config.toml (or
$CODEX_HOME). The token goes into ~/.config/axs-brain/codex.json, a file only you can read, never into the Codex
config. Then start Codex, type /hooks and trust the axs brain hooks: Codex skips new hooks until you trust them.
Without the CLI, the dashboard (Connect a tool) shows a one line installer for macOS and Linux. See
Connect your agents. axs uninstall codex takes only the axs entries out again.
Your existing AGENTS.md can be imported, one memory per rule or fact, and the file stays as
it is. See Plans and billing.
FAQ
Does Codex have persistent memory?
Yes, two kinds. AGENTS.md files load in every session. Local memories, once turned on, carry context from past
chats. Both stay on your machine unless you commit AGENTS.md to git.
Where is the global AGENTS.md for Codex?
~/.codex/AGENTS.md, or AGENTS.md in CODEX_HOME if you set it. AGENTS.override.md in the same place wins.
Why does Codex ignore part of my AGENTS.md?
Check the 32 KiB project_doc_max_bytes limit, an AGENTS.override.md in the same directory, and whether you
restarted Codex after the edit.
Can teammates share Codex memories?
Not through Codex memories, which are local. Share rules through AGENTS.md in git, or a memory server over MCP.
Can I keep AGENTS.md and use axs brain?
Yes. Codex keeps reading your AGENTS.md files. axs brain adds memories and rules on top.
CLAUDE.md vs AGENTS.md: one file for all coding agents
CLAUDE.md is Claude Code's instruction file, AGENTS.md the open format Codex, Cursor and others read. How to keep one file for every agent, and its limits.
Share Cursor rules across a team and many repos
Share Cursor rules with your team: .cursor/rules in git, AGENTS.md, Team Rules, a team plugin marketplace, or synced files across repos. The tradeoffs.