Updated
How to give AI agents persistent memory, and what each agent remembers
Why agents forget between sessions, what Claude Code, Codex, Gemini CLI and Copilot keep natively, and how to give AI agents persistent memory across tools.
AI agents forget between sessions because the model stores nothing. Everything an agent seems to know sits in its context window, the block of text the tool sends to the model on every turn. When the session ends, that block is gone, and the next session starts from whatever the tool loads from disk.
To give an agent persistent memory, you give it a durable place outside the model and a habit of reading it. Claude Code, Codex, Gemini CLI and GitHub Copilot CLI all load instruction files at startup, and each keeps some memory it writes for itself. That built-in memory stays inside one tool and mostly on one machine. This guide covers those four coding agents plus the Claude app, then how to keep memory that follows you between them.
Why agents lose context
Closing the terminal, running /clear or starting a new chat throws away the context window. Most tools save the transcript to disk. A fresh session does not read it back, except through a resume command or a memory feature that summarizes old sessions in the background, such as Codex memories or Gemini CLI’s Auto Memory.
Long sessions lose detail before they end. Near the context limit, the tool replaces older messages with a summary, and Copilot CLI starts doing this at about 80 percent of the window. A constraint you stated early can vanish while the session is still open. Claude Code re-reads the project root CLAUDE.md after /compact, which is why anything that must survive belongs in a file.
Subagents get their own context window and a short brief. In Claude Code, the main conversation’s auto memory is not loaded into an ordinary subagent; a fork inherits it, and a subagent can keep a separate memory of its own through its memory field. For a multi-step research run, have each step append findings to a working file and pass the next step its path.
What each agent keeps on its own
This table follows each vendor’s documentation as of October 2026, including which agents read AGENTS.md, the cross-tool instruction file.
| Agent | Instruction files it loads | Reads AGENTS.md |
Memory it writes itself | Getting an old session back |
|---|---|---|---|---|
| Claude app | None; projects hold instructions | No | Memory topics on Anthropic’s servers | Chat search on paid plans |
| Claude Code | CLAUDE.md, CLAUDE.local.md, .claude/rules/ |
Yes, when no CLAUDE.md is on the path (v2.1.277+) |
Auto memory under ~/.claude/projects/, on by default |
claude --continue, claude --resume, /rewind |
| Codex CLI | AGENTS.md, AGENTS.override.md |
Yes, it is the native file | Memories under ~/.codex/memories/, off by default |
codex resume, codex fork |
| Gemini CLI | GEMINI.md |
Only if added to context.fileName |
Edits memory files when asked; Auto Memory is experimental | gemini --resume, /resume, /chat save |
| Copilot CLI | .github/copilot-instructions.md, ~/.copilot/copilot-instructions.md, .github/instructions/ |
Yes, along with CLAUDE.md and GEMINI.md |
Copilot Memory on GitHub’s servers, in public preview | copilot --continue, copilot --resume |
The Claude app
Memory in the Claude app saves topics about you as you chat, such as your role, projects and preferences. Anthropic’s help center says it is on by default for Free, Pro and Max, and off on Team and Enterprise until an owner enables it. You can read, edit, pause or reset it under Settings, Memory. None of it reaches Claude Code.
Claude Code
Claude Code has two mechanisms. CLAUDE.md files are instructions you write: a personal ~/.claude/CLAUDE.md, a project ./CLAUDE.md and a gitignored ./CLAUDE.local.md, concatenated with the nearest read last.
Auto memory is what Claude writes for itself from your corrections and preferences, in one directory per repository at ~/.claude/projects/<project>/memory/. A MEMORY.md index loads into every session up to its first 200 lines or 25KB, and Claude opens the topic files beside it on demand. It stays on that machine. Toggle it from /memory, or set CLAUDE_CODE_DISABLE_AUTO_MEMORY=1.
Transcripts are saved as JSONL at ~/.claude/projects/<project>/<session-id>.jsonl. claude --continue reopens the latest session in the current directory, claude --resume opens a picker, and /rewind (or Esc twice) rolls code and conversation back to an earlier prompt. Transcripts are deleted after cleanupPeriodDays, 30 days by default, while the memory directory is exempt.
Codex CLI
Codex reads ~/.codex/AGENTS.md (or AGENTS.override.md when present), then checks each directory from the project root down to your working directory for the same names. The combined text is capped at 32 KiB by default through project_doc_max_bytes. Codex reads CLAUDE.md only when you add it to project_doc_fallback_filenames in ~/.codex/config.toml.
Codex memories are off by default. Switch the feature on in config.toml, or with Enable Codex memories under Settings, Personalization in the ChatGPT desktop app:
[features]
memories = true
Codex then summarizes eligible past sessions in the background, once they have been idle for a while, into files under ~/.codex/memories/. Inside a session, /memories decides whether the current chat uses existing memories or contributes new ones. OpenAI calls these files generated state and advises keeping rules that must always apply in AGENTS.md. codex resume --last reopens the most recent session in the current directory.
Gemini CLI
Gemini CLI loads ~/.gemini/GEMINI.md, then GEMINI.md files in your workspace and its parent directories, then more as tools touch other folders. Inside a session, /memory show prints the full concatenated context, /memory list prints the file paths, and /memory reload picks up edits made outside the session.
Current releases (v0.63.0, October 2026) have no /memory add command. You ask the agent in plain words to remember something, and it edits a repository GEMINI.md, a private per-project memory folder or the global file, depending on scope. An experimental Auto Memory feature, enabled with "experimental": { "autoMemory": true } in settings.json, mines past sessions and queues proposed changes for you to approve in /memory inbox.
Sessions are saved automatically under ~/.gemini/tmp/ for 30 days by default. gemini --resume reopens the latest, and /chat save <tag> bookmarks a point you can return to with /chat resume <tag>.
GitHub Copilot CLI and Copilot Memory
Copilot CLI merges every instruction file it finds: AGENTS.md, CLAUDE.md and GEMINI.md at the Git root and in your working directory, .github/copilot-instructions.md, path-scoped files under .github/instructions/, and your personal ~/.copilot/copilot-instructions.md. GitHub’s custom instructions docs state that it removes only identical duplicates and defines no precedence between files. /instructions shows which files are active.
Copilot Memory is GitHub’s hosted memory, in public preview and written by Copilot CLI, the cloud agent and code review. It stores facts per repository and preferences per user, and deletes anything unused for 28 days. Individual paid plans have it on by default, while Business and Enterprise need an administrator to allow it. copilot --continue resumes the latest session.
Carrying context from one agent to another
Two kinds of context need moving between tools: the instructions you wrote, and the record of what was decided.
In a repository, use one AGENTS.md
Put shared project instructions in AGENTS.md at the repository root. Codex and Copilot CLI read it as it stands. Claude Code reads it when no CLAUDE.md or CLAUDE.local.md sits in the working directory or above it.
For Claude-only rules, keep them in a CLAUDE.md and set Project instructions to claude-md-and-agents-md in /config, which loads both files on that machine. The other route is a CLAUDE.md whose first line is @AGENTS.md. That import works in every Claude Code session, but Copilot CLI also expands @ imports in CLAUDE.md and loads AGENTS.md directly, so it may read the shared text twice.
Gemini CLI needs one setting, in the project’s .gemini/settings.json or your user settings:
{
"context": {
"fileName": ["AGENTS.md", "GEMINI.md"]
}
}
What to put in CLAUDE.md covers what belongs in the file, and the advice applies to AGENTS.md unchanged.
Personal files: a symlink or a one-way copy
Your personal rules live in ~/.claude/CLAUDE.md, ~/.codex/AGENTS.md, ~/.gemini/GEMINI.md and ~/.copilot/copilot-instructions.md. Keep one canonical file, say ~/agent-rules.md, and point the others at it. Claude Code can import it with @~/agent-rules.md in ~/.claude/CLAUDE.md, and imports in user-level files load without an approval prompt. For the other three, a symbolic link makes each expected path open the canonical file:
ln -s ~/agent-rules.md ~/.codex/AGENTS.md
ln -s ~/agent-rules.md ~/.gemini/GEMINI.md
ln -s ~/agent-rules.md ~/.copilot/copilot-instructions.md
On Windows, New-Item -ItemType SymbolicLink -Path "$HOME\.codex\AGENTS.md" -Target "$HOME\agent-rules.md" does the same, with Developer Mode on or from an elevated prompt.
Many editors and agents save atomically, writing a temporary file and renaming it over the original. That rename replaces the link with an ordinary file, and from then on the agent reads a private copy your edits never reach. Claude Code’s Edit and Write tools refuse to write through a symlink, so Claude edits the target and the link survives. Check the others now and then with ls -l ~/.codex/AGENTS.md, where a line without -> means the link is gone.
A one-way copy trades that fragility for a different cost: anything an agent wrote into its own copy is overwritten on the next run.
#!/bin/sh
src="$HOME/agent-rules.md"
for dest in "$HOME/.codex/AGENTS.md" "$HOME/.gemini/GEMINI.md" "$HOME/.copilot/copilot-instructions.md"; do
mkdir -p "$(dirname "$dest")"
cp "$src" "$dest"
done
Getting the canonical file onto a second machine is covered in syncing CLAUDE.md, AGENTS.md and skills between machines.
Switching tools in one move
Claude Code and Codex both ship an /import command for a one-time migration. Claude Code’s version (v2.1.213 or later) appends another agent’s instruction files to the matching CLAUDE.md and brings over MCP servers, commands, subagents and skills. Codex’s version takes instructions, settings, skills, MCP configuration, hooks, subagents and up to 50 chats from the last 30 days from Claude Code or Cursor. Per OpenAI’s import table, it also brings Claude Code project memories into Codex memories.
Memory moves in that one direction only. Claude Code imports no memory from Codex, and Gemini’s memory files and Copilot Memory have no import path at all. Before switching, open the old agent’s memory and move what you need into AGENTS.md or notes you keep yourself. The largest loss is usually context that was only ever spoken in chat.
Skills move more easily, since Claude Code and Codex both use folders containing a SKILL.md file. Claude Code loads personal skills from ~/.claude/skills/ and Codex from ~/.agents/skills/, so copying a folder across, or letting /import do it, carries a skill over.
Auditing what an agent remembers
Start with the tool’s own view, which resolves imports and parent directories for you.
| Agent | See what loaded this session | Open what it saved |
|---|---|---|
| Claude app | Not applicable | Settings, Memory, the Topics list |
| Claude Code | /context, under Memory files |
/memory, then open the auto memory folder |
| Codex CLI | codex --ask-for-approval never "Summarize the current instructions." |
ls ~/.codex/memories/ |
| Gemini CLI | /memory show and /memory list |
The files /memory list names, and /memory inbox |
| Copilot CLI | /instructions |
Repository Settings, Copilot, Memory on GitHub, and your personal Copilot settings |
From a shell, every Claude Code project’s auto memory index is one command away:
cat ~/.claude/projects/*/memory/MEMORY.md
Reversed decisions cost the most, because an agent acts confidently on a choice you overturned months ago. Contradictions come next: Copilot sets no precedence between files, and Claude’s docs say it may pick between conflicting instructions arbitrarily. Remove anything the code already states, since the copy goes stale.
Delete secrets and personal details about colleagues outright, because memory files get synced, shared and pasted into transcripts. Watch size too. A MEMORY.md past 200 lines loses everything below the cut at the next session start.
As a working habit, read the memory files once a month and before any large piece of work, and to keep each index or learnings file short enough to read in one sitting. When a decision has changed, record the replacement and mark the old entry as replaced, so whoever proposes it again sees why it was dropped.
Approaches to durable memory
Hosted memory, like the Claude app’s or Copilot Memory, needs no setup and follows you across devices with no sync product to buy. Memory that outlasts one tool takes one of these forms.
| Approach | What it is | Where it wins | What it costs |
|---|---|---|---|
| Instruction files | AGENTS.md, CLAUDE.md, GEMINI.md |
Standing rules every session needs | Loaded in full every session, so history bloats them |
| Built-in memory | Auto memory, Codex memories, Copilot Memory | No setup | One tool, mostly one machine, and the tool decides what to keep |
| Notes the agent writes | A decisions file, or a folder of small notes such as Jotura’s memory notes | Readable, diffable, works with any agent that has a shell | You add the read and write habit to the instructions |
| MCP memory server | A process the agent calls through the Model Context Protocol | Structured save and recall as real tools | Another process to run; contents sit in the server’s format |
| Memory services and vector stores | Mem0, Letta, Zep, or embeddings in Chroma or pgvector | Fuzzy recall across very large sets, shared by many clients | An account or infrastructure, and contents you cannot read start to finish |
The last row earns its keep once recall must work across tens of thousands of entries, and vector database vs markdown for agent memory works through where that line sits. Developers building on the Claude API also have Anthropic’s memory tool, which lets Claude read and write memory files that the application stores wherever it chooses.
For your own coding agents, start with notes the agent writes. A single decisions file costs nothing, and a notes vault with one note per memory takes over once that file grows past a few hundred entries.
Start with a decisions file
The cheapest version that works is one file in the repository, docs/decisions.md, with an entry per settled question:
## 2026-10-10 Generate thumbnails at upload time
On-request generation made the first gallery load slow and kept the image worker busy.
Rejected: a hosted image-transform service, because of per-request pricing.
Open: backfill thumbnails for photos uploaded before this change.
Then add two lines to AGENTS.md:
Before proposing an approach, read docs/decisions.md and say which entries apply.
When a decision is settled, append an entry: date, decision, reason, rejected options.
The read instruction matters more than any file layout. Expect the write half to slip sometimes, because an end-of-task instruction competes with everything else in context and a session that ends abruptly never reaches it.
A single file runs out at a few hundred entries. The agent reads all of it to find one answer, and a reversed decision looks identical to a live one. Two agents rewriting the same file can also erase each other’s entries, which one file per memory mostly avoids, since two agents rarely create the same new file.
Memory notes in a Jotura vault
Jotura is a markdown notes app that keeps plain .md files on your own disk, with desktop apps for macOS, Windows and Linux. Its command-line tool, jotura, came later and includes a small memory system built on ordinary notes. Once you install the Jotura skills, your agent runs it as part of the task.
At the start of a session the agent calls jotura context with the task, which returns your vault’s conventions note, open follow-ups and the memories relevant to the task. Before proposing an approach it searches past decisions. When something is settled, it writes one note per memory, of kind decision, fact or followup:
---
kind: decision
status: active
importance: normal
date: 2026-10-10
project: photo-api
---
# Uploads go straight to object storage with presigned URLs
Proxying uploads made the API host carry every file twice, once in and once out.
Revisit if we need server-side virus scanning before storage.
It lands at Memory/Decisions/2026-10-10 uploads-go-straight-to-object-storage-with-presigned-urls.md. When you reverse a decision, the agent marks the old note superseded and links it to the new one, so recall returns the current answer while the history stays readable. By default, recall leaves out superseded and resolved notes, along with active notes older than 180 days.
Your part is reading. The desktop app’s Agent Memory tab shows every memory on a timeline, filterable by kind, project, status and importance, with replaced decisions chained to their successors. Edit a note there and the next session reads the fix. The one command worth running yourself is a periodic sweep:
jotura memory doctor
It lists decisions and facts past 180 days for you to confirm or supersede, and follow-ups open more than 60 days. It also flags superseded-by links whose target note is gone, and a default Memory/ folder sitting beside a namespaced one.
In Claude Code, the skills install from a plugin marketplace inside a session:
/plugin marketplace add adamrichardson14/jotura-agents
/plugin install jotura@jotura-agents
For Codex, Gemini CLI and Copilot CLI, copy the skill files from the jotura-agents repository into wherever that agent loads skills, which for Codex is ~/.agents/skills. To load the context pack before your first prompt, add a SessionStart hook that runs jotura context to your own Claude Code settings, which Jotura leaves alone.
The agent needs shell access to run the CLI, since Jotura has no MCP server. Recall by meaning uses an index only the desktop app builds, and without it recall falls back to keyword search, so a note about presigned uploads will not surface for “where attachments get saved”. Jotura is closed source. Jotura Sync carries the notes between your computers, end-to-end encrypted, for £4 or $5 a month with no free trial, on the pricing page; the notes are plain files, so other file sync works too.
MCP memory servers
A memory server turns save and recall into tools the agent calls. The reference implementation, @modelcontextprotocol/server-memory, keeps a knowledge graph in a JSONL file. Set MEMORY_FILE_PATH to an absolute path you control. The default file sits inside the package’s install directory, where a cache clean or a version update can lose it:
claude mcp add memory -e MEMORY_FILE_PATH=/home/you/agent-memory.jsonl -- npx -y @modelcontextprotocol/server-memory
Give Codex, Gemini CLI and Copilot CLI the same command and path in their MCP configuration, and they share one graph. The agent still has to decide to call the tools. CLI tools vs MCP servers for agents weighs that trade more broadly.
Frequently asked questions
Why does my AI agent forget everything between sessions?
The model stores nothing between requests. The tool rebuilds the context from scratch for each session, loading only instruction files and any memory files it keeps on disk. Anything said in an earlier chat and never written to a file is gone unless you resume that exact session.
Does Claude Code remember between sessions?
It loads your CLAUDE.md files and the first 200 lines of MEMORY.md, the auto memory index Claude writes from your corrections, on that machine. The conversation itself returns only when you resume it with claude --continue or claude --resume.
Does Codex CLI remember previous sessions?
Only with memories switched on, through memories = true under [features] in ~/.codex/config.toml or the ChatGPT desktop app’s settings. Codex then summarizes idle past sessions into ~/.codex/memories/. Otherwise a new session knows only your AGENTS.md files, and codex resume reopens one saved session.
Does Gemini CLI have memory?
Gemini CLI loads GEMINI.md files every session, and when you ask it to remember something it edits one of them or a private per-project memory file. /memory show prints everything it loaded. Sessions are saved automatically for 30 days and reopen with gemini --resume.
Does GitHub Copilot CLI remember anything?
It loads every instruction file it finds, including AGENTS.md, CLAUDE.md and GEMINI.md, at the start of each session. With Copilot Memory enabled, it also stores repository facts and personal preferences on GitHub, deleting any unused for 28 days. copilot --continue resumes the previous session.
How do I see what Claude remembers?
In the Claude app, open Settings, Memory to read, edit or delete each topic. In Claude Code, run /memory and open the auto memory folder, or read ~/.claude/projects/<project>/memory/MEMORY.md directly. /context shows which instruction files loaded in the current session.
Can Claude Code and Codex share memory?
They share instructions through one AGENTS.md, which both read. Codex’s /import can copy Claude Code’s project memories into Codex memories once, and nothing flows back the other way. For an ongoing shared record, keep notes in a folder both agents read and write, and point to it from AGENTS.md. With the Jotura skills installed in both, they log to and recall from the same memory notes in your vault.