What is agent memory in Claude Code, Codex, Cursor and Grok?
By Flavio
Agent memory is notes a coding agent keeps between sessions. How Claude Code, Codex and Grok Build store them, and what Cursor documents instead.
Agent memory is notes a coding agent keeps after the chat ends, so a later session can use them. It is not the context window. The window is what this turn can see. Memory is what the tool wrote down for a future turn.
How agent memory works
A session starts blank, apart from the instruction files and any memory the tool loads. During the chat, the agent can write a note. The next session reads that note back, or an index of notes, and then decides whether to open the rest.
Instruction files are the other half. You write CLAUDE.md, AGENTS.md or a rules file and commit it. Memory is usually generated, machine-local, and easy to confuse with those files. A rule that must always apply belongs in the file you can review. A memory is a recall layer.
Memory does not enforce anything. The model can ignore a note the same way it can ignore a paragraph in CLAUDE.md. A hook is what blocks a tool call.
Agent memory in each tool
Claude Code, Codex and Grok Build each document a memory store. The Cursor editor docs checked for this entry do not.
| Claude Code | Codex | Cursor | Grok Build | |
|---|---|---|---|---|
| What you write | CLAUDE.md, or AGENTS.md in its place |
AGENTS.md for rules that must apply |
Rules files. No coding-agent memory store documented | AGENTS.md and .grok/rules/ |
| What the agent writes | Auto memory under ~/.claude/projects/<project>/memory/ |
Files under ~/.codex/memories/ |
Not documented | Cross-session memory. The on-disk layout is not documented |
| Default | On in local sessions. Off by default in self-hosted sessions outside Claude Tag | Off until you enable it | Not documented | Not documented as on or off. --experimental-memory enables it. --no-memory disables it for the session |
| How you browse | /memory and /context |
/memories |
Not documented | /memory (alias /mem) |
| Shared with the team | Instruction files, if you commit them. Auto memory stays on the machine | AGENTS.md, if you commit it. Memories stay under the Codex home |
Rules, if you commit them | Instruction files, if you commit them |
Claude Code
Claude Code loads two things at the start of a conversation. CLAUDE.md is what you write. Auto memory is what Claude writes. AGENTS.md can load in place of CLAUDE.md. Both are context, not enforced configuration. To block an action, use a PreToolUse hook.
CLAUDE.md can live in a managed policy path, in ~/.claude/CLAUDE.md for you, in ./CLAUDE.md or ./.claude/CLAUDE.md for the project, and in ./CLAUDE.local.md for local notes you do not commit. /init writes a starter. /memory lists the files and can open the auto memory folder. /context shows which files loaded, under Memory files.
Auto memory is on by default in local sessions. Outside Claude Tag, a self-hosted session starts with it off. The /memory toggle writes autoMemoryEnabled to ~/.claude/settings.json. A project can set autoMemoryEnabled to false. CLAUDE_CODE_DISABLE_AUTO_MEMORY=1 turns it off. Background sessions, and sessions started by another Claude session, cannot turn it back on from the toggle.
Notes live in ~/.claude/projects/<project>/memory/. The project path comes from the git repo, so worktrees of that repo share one directory. MEMORY.md is the index. Topic files sit beside it. The first 200 lines of MEMORY.md, or the first 25KB, whichever comes first, load at session start. Topic files do not load until Claude reads them. The directory is machine-local. It is not copied to cloud sessions.
The main conversation’s auto memory is not loaded into subagents, except a fork of the current conversation. A subagent can have its own memory through its memory field.
If you say “always use pnpm, not npm”, Claude saves that to auto memory. If you say “add this to CLAUDE.md”, it writes the file instead. CLAUDE.md is delivered as a user message after the system prompt, not as part of the system prompt. Files over 200 lines can be followed less reliably. A file over 4 MiB is skipped entirely. See Memory.
OpenAI Codex
ChatGPT on the web uses ChatGPT memory. Local Codex, in the app, the CLI and the IDE, uses a separate store on the machine. The docs say to keep required team guidance in AGENTS.md. Memories are a recall layer, not the only source for a rule that must always apply.
Local memories are off by default. In the desktop app, Settings, then Personalization, then Enable Codex memories turns them on for that machine. Allow memories from tool-assisted chats chooses whether chats that used MCP tools or web search can become future memories. Delete Codex memories resets that machine’s store, and also clears Computer History when that feature is available.
In the CLI, /memories controls whether the current chat can use existing memories, and whether it can become input for future ones. That choice does not change the global setting. The IDE extension uses the connected host’s store.
In config.toml:
[features]
memories = true
Related keys include memories.generate_memories, memories.use_memories, memories.disable_on_external_context (alias memories.no_memories_if_mcp_or_web_search), memories.min_rate_limit_remaining_percent, memories.extract_model and memories.consolidation_model.
Codex stores memories under the Codex home, ~/.codex by default, in ~/.codex/memories/. The files include summaries, durable entries, recent inputs and evidence. Treat them as generated state. You can read them before you share that folder. Do not hand-edit them as the way you manage memory.
Codex skips active or short-lived sessions, redacts secrets from generated fields, and updates in the background after a chat has been idle. It can also skip a pass when the remaining rate-limit percentage is below the threshold. The docs do not give the idle time a number. See Memories.
Cursor
The Cursor docs checked for this entry do not document a persistent memory store for the coding agent in the editor. The Agent SDK has a memory reference, and Grok Bot has its own memory page. Those are different products.
What the editor does document is rules, and @ mentions for files, folders, terminals, past chats and diffs. Put a rule that must survive the chat in a rules file. See Rules and the rules glossary entry.
Grok Build
Grok Build does not publish a separate memory-feature page. The command list and the CLI reference document the controls.
/remember saves a memory note. /memory, also /mem, browses and manages memories. /dream runs memory consolidation. /flush writes conversation memory to disk now. grok memory clear clears cross-session memory files, with --workspace, --global or --all.
--experimental-memory enables cross-session memory. --no-memory disables memory for that session. The docs call the stored data cross-session memory files. They do not describe the directory layout or the file format. See Modes and commands and the CLI reference.
Details checked against each vendor’s documentation in November 2026.
A real example
This turns Claude Code auto memory off for your user, which is the setting the /memory toggle writes. A project that must not accumulate notes can set the same key to false in its own settings.
{
"autoMemoryEnabled": false
}
That does not remove CLAUDE.md. Instruction files still load. To turn Codex memories on, which is off until you do this, add the feature flag:
[features]
memories = true
A sentence you want every teammate to follow still goes in AGENTS.md or CLAUDE.md, not in either of these stores.
When to use agent memory
Use auto memory, Codex memories or /remember for a preference that is yours, on this machine, and not worth a pull request. The pnpm example in the Claude Code docs is that kind of note.
Use a committed instruction file when the next person, or the next cloud session, has to see the same rule. Auto memory does not travel with the repo, and a Claude Code cloud session does not load the laptop’s memory directory.
Use /memory or /memories when a session is following a note you did not write. Read it before you assume the agent remembered the right constraint.
Skip memory for secrets. Codex redacts generated fields and still tells you to review the files before you share the Codex home. Claude Code’s memory files sit in a directory under your user account. Neither store is a password manager.
Pitfalls
Claude Code only loads the first 200 lines of MEMORY.md, or the first 25KB, whichever comes first. A long index looks saved and is partly invisible on the next launch. Topic files are not loaded until Claude opens them, so a fact that lives only in a topic file can be missing at the start of the session.
Auto memory is shared by every worktree of the same git repo, and it stays on one machine. A note from a checkout you deleted last month can still load. A cloud session will not see it.
The /memory toggle cannot turn auto memory back on inside a background session or a session another Claude session started. The toggle tells you to run claude yourself and flip it there.
Codex memories are off until you enable them. Turning them on in one chat with /memories does not change the global setting. Deleting them also clears Computer History on that Mac when the feature is available.
Cursor’s coding agent will not grow a memory file for you from anything documented on the editor pages. If a rule matters, write it as a rule. A Grok Bot memory, or an Agent SDK memory, is not that store.
Grok’s --experimental-memory and --no-memory are session flags. The docs do not say the feature is on for every install. Check /memory in the session you are about to trust.
Related on flaviocopes.com
- AGENTS.md is the committed instruction file. Use it for a rule that memory is the wrong place for.
- How to document project decisions is the human record of why a choice was made, which neither the code nor a model memory file reliably keeps.
- Resume a coding agent session is the same chat continued. Memory is a later chat that only received the notes.
- Work Tracebook turns agent reports into a timeline you can read. That log is yours. It is not the memory the model loads next time.
Related glossary entries
- Rules: Project rules are durable instructions a coding agent loads for a repo. How they work in Cursor, Claude Code, Codex and Grok Build, and when to skip them.
- Sessions: A session is a saved coding-agent conversation you can resume later. How Claude Code, Codex, the Cursor CLI and Grok Build store, name, resume and fork one.
- Context window: The context window is everything a coding agent can see at once. How to check it, free it and keep it small in Claude Code, Codex, Cursor and Grok Build.
Want me to talk about your product? You can sponsor this site.