Codex memory: AGENTS.md, memories and where they're stored
How Codex remembers between sessions in 0.172: AGENTS.md files, the opt-in memories feature, where ~/.codex keeps them, /memories, clearing, and resume.
Codex remembers things between sessions in three ways. AGENTS.md files are instructions you write, read at the start of every session: ~/.codex/AGENTS.md for you, and one per directory from the repository root down to where you started. Memories are notes Codex writes itself from your past chats, kept under ~/.codex/memories_v2/ (or memories/ on an older setup) and fed into later sessions; they are off by default, and codex features enable memories turns them on. Saved sessions are the third: codex resume reopens a whole conversation. As of December 1, 2026, with Codex 0.172.0.
The three kinds, side by side
| AGENTS.md | Memories | Saved sessions | |
|---|---|---|---|
Who writes it | You (or Codex, when you ask it to edit the file) | Codex, in the background | Codex, as you work |
Where | ~/.codex/AGENTS.md and the repository’s own files | ~/.codex/memories_v2/ or ~/.codex/memories/ | Under ~/.codex |
On by default | Yes | No | Yes |
What a new session gets | The whole file, every time | What Codex judged worth keeping from earlier chats | Nothing, unless you resume that session |
Shared with your team | Yes, if committed | No, it stays on the machine | No |
OpenAI’s memories page draws the line between the first two plainly: “Keep required team guidance in AGENTS.md or checked-in documentation. Treat memories as a helpful recall layer, not as the only source for rules that must always apply.” A rule Codex must follow goes in a file you control; memories catch what you never got round to writing down.
AGENTS.md: what you tell it to remember
Codex builds its instructions once when a session starts. From the AGENTS.md docs:
- Your own file first. In your Codex home,
AGENTS.override.mdif it exists, elseAGENTS.md; “Codex uses only the first non-empty file at this level.” This is where preferences that hold in every repository go. - Then the project, root first. From the repository root down to the directory you started in, at most one file per directory, and “files closer to your current directory override earlier guidance.”
- A size cap. Codex stops adding files at
project_doc_max_bytes, 32 KiB by default. The docs say to “raise the limit or split instructions across nested directories when you hit the cap.”
/init inside a session writes a starter AGENTS.md in the current directory. To check what actually loaded:
codex --ask-for-approval never "Summarize the current instructions."CopiedThe full discovery rules, the fallback filenames and how other agents read the same file are in what AGENTS.md is and which agents read it. Claude Code’s equivalent is CLAUDE.md, which it reads instead of AGENTS.md when both are present.
Memories: what Codex remembers on its own
With memories on, “Codex can turn useful context from eligible prior chats into local memory files” and inject them into later sessions. It does this in the background, not at the end of each chat. Per the docs and the configuration reference:
- It waits. A chat is considered once it has been idle for
memories.min_rollout_idle_hours, 6 hours by default, and only chats from the lastmemories.max_rollout_age_days(30 by default) are candidates. So a chat you finished an hour ago is not in your memories yet. - It skips some chats. Active and short-lived sessions are skipped, and in the source so are ephemeral sessions and sub-agents. Set
memories.disable_on_external_context = trueto keep chats that used MCP tools, web search or tool search out as well; it isfalseby default. - It costs usage. Writing memories runs a model on your account. Codex skips a pass when less than
memories.min_rate_limit_remaining_percentof your rate limit is left, 25% by default, “so Codex doesn’t spend quota when you’re near a limit.”memories.extract_modelandmemories.consolidation_modelchoose the models it uses. - Secrets are redacted, not guaranteed out. Codex “redacts secrets from generated memory fields,” and the docs still say: “Don’t store secrets in memories.”
The docs name no plan that memories need, and the ChatGPT website keeps a memory of its own that is separate from Codex’s.
Turn memories on or off
In the CLI, codex features enable memories writes the flag to your config.toml, and codex features disable memories turns it off there. The same setting by hand:
[features]
memories = trueCopiedTwo settings split it into halves, both true by default once the feature is on: use_memories decides whether existing memories are fed into new sessions, and generate_memories whether new chats become material for them. Setting generate_memories = false keeps what Codex already knows and stops it learning more:
[memories]
use_memories = true
generate_memories = falseCopiedFor one chat only, type /memories in the CLI (between tasks, not while one is running) and choose whether this chat can use existing memories and whether it can feed future ones. “Chat-level choices don’t change your global memory settings.” In the ChatGPT desktop app the switch is Settings > Personalization > Enable Codex memories, with Allow memories from tool-assisted chats beside it. Where config.toml lives and how a project’s file stacks on yours is in the Codex config.toml guide.
Where memories are stored
Under your Codex home, ~/.codex unless CODEX_HOME says otherwise. There are two stores, because a new format is being rolled in:
- A fresh setup uses
~/.codex/memories_v2/. - If
~/.codex/memories/already exists, Codex keeps using it. Settingmemories.version = "v2"(or"v1") under[memories]picks one explicitly, andmemories.dual_write = trueon v1 writes both while reading the old one.
The docs describe the contents as “generated summaries and supporting evidence from prior chats.” In the older memories/ folder the repository’s own memories README names the files: MEMORY.md, memory_summary.md, raw_memories.md, a rollout_summaries/ folder with one summary per chat used, and skills/. They are plain Markdown, so you can read them to see what Codex has kept. Editing them is another matter: the docs say to “treat these files as generated state” and not to rely on hand edits “as your primary control surface,” since they are Codex’s own output and a later background pass can rewrite them. To correct something Codex has wrongly learned, put the right rule in AGENTS.md.
There is one store per Codex home, not one per repository: the same memory folder serves every project you open as that user.
Clear or delete memories
The documented reset is in the ChatGPT desktop app: Settings > Personalization > Delete Codex memories, which resets “the selected machine’s memory store.” On a Mac where Computer History is available, the same button clears that too. The CLI has no listed command for it. Codex 0.172.0 does ship a hidden one, described in its source as “Internal: reset local memory state for a fresh start.” It empties the memories, memories_v2 and memories_extensions folders under your Codex home and clears the memory records in Codex’s local database. It cannot be undone, and because it is hidden and marked internal it may change or disappear in a later release:
codex debug clear-memoriesCopiedDeleting only the folders by hand leaves that database behind. The repository’s README says the per-chat extractions are stored there and the background pass rebuilds raw_memories.md and rollout_summaries/ from them, so some of what you deleted can come back. To stop new memories afterwards, disable the feature as above.
Saved sessions: the other kind of memory
Neither AGENTS.md nor memories brings back a conversation. For that, codex resume --last reopens the latest session in the current folder and codex resume opens a picker; /resume does the same from inside one. A resume reloads the full transcript, while memories carry only a summary of what mattered across many chats. Why a session is missing from the list, and what a resume restores, is in getting a Codex or Claude Code session back.
Codex also keeps a history file, ~/.codex/history.jsonl, on by default. Its config docs turn that off with persistence = "none" under [history], or cap its size with max_bytes.
On a server or a shared machine
- Memories live where Codex runs. A session on a server writes the server’s
~/.codex, not your laptop’s. The VS Code extension “uses the connected Codex host’s local memory store,” so over Remote-SSH that is the server too (Codex in VS Code covers the Remote-SSH setup). - One Linux user, one memory. Two people who log in as the same user share one Codex home, and with it one set of memories built from both people’s chats. A separate user each, or a separate
CODEX_HOMEeach, keeps them apart. - The files are readable text. Memory files, session transcripts and
history.jsonlhold what you and the agent said and saw, in plain text, in the same folder as the sign-in fileauth.jsonwhen Codex keeps it in a file. The docs advise reviewing the memory files before you share your Codex home, which includes copying it to another machine or into a backup someone else can open. On a machine others log in to, we would also close the folder to them withchmod 700 ~/.codex. Securing a VPS for Claude Code and Codex covers who else on the machine can reach it. - Scripted runs.
codex exec --ephemeralsaves no session, and the memory pipeline leaves ephemeral sessions out. For a job you do want saved but not learned from, we would pass the setting for that run alone,-c memories.generate_memories=false: the config reference says that with it off, “newly created threads are not stored as memory-generation inputs.”