How to correct wrong or stale agent memory so the next session sees it
A wrong memory is worse than a missing one. The next session — one saved conversation with the agent — treats it as established, builds on it, and reports success. The fix has two parts: change the source, and put the correction where the next read starts. Append it at the bottom and the model may never reach it.
Checked against each tool's documentation on 26–27 October 2026.
Why a correction gets missed#
- It sits below the wrong claim. The next agent reads the first screen, not the changelog at the bottom.
- The index still says the old thing.
MEMORY.md, an overview summary, a note title or a search snippet can carry the wrong claim after the body is fixed. - It is in the wrong copy. Auto memory is machine-local, a repository can have a global and a nested
AGENTS.md, and two agents can hold two versions. - It was never stored. A correction typed into a chat is not memory. The next session does not see the conversation.
- It was overwritten. A consolidator (a background pass that rewrites pages), an auto-memory pass or a whole-page write can replace the text.
- Only part of the store loads. Claude Code loads the first 200 lines or 25KB of
MEMORY.md; ai-memory's opt-in brief lists titles only. - The correction is not first. A correction after the wrong sentence is a comment, not a replacement.
A correction is a change to the source plus a change to the first thing the next agent reads. Do both.
The shape of a correction#
CORRECTION 2026-10-26 (owner): The real cause was DNS. CACHE_WARM=1 only
hides it. Source: staging incident, 2026-10-24.
Original note below, kept for history.Put it under the title, before the body. Include four things: the date, who is correcting it, what is right, and the source. Keep the original below, marked as the original. If you delete the original, the next reader cannot tell what changed or why.
Change the title or summary too when the wrong claim is in it. The title is often the only part that loads, and it is what the overview and search results show.
Claude Code#
For a CLAUDE.md rule. Edit the line, commit it, and start a new session. A rule in CLAUDE.md is context, not enforcement; if the agent must not take an action, use a PreToolUse hook instead. A hook is a shell command Claude Code runs at a lifecycle event; this one runs before a tool call and can block it. Run /doctor prompt-audit if the file has grown contradictory; it reports conflicts before you edit.
For auto memory. Auto memory is Claude Code's own notes, written by the model and stored as markdown on your machine. Run /memory and open the auto memory folder. Edit the topic file, then edit the MEMORY.md line that points to it. If the fact is in a topic file but the index still says the old thing, the next session may never open the topic file. Put the correction at the top of the topic file and keep the original below.
Auto memory is plain markdown, so the next session reads what is in the file. It is also machine-local: correct it on the machine where the next session will run. A correction on another laptop changes nothing.
If auto memory keeps regenerating the wrong fact, turn it off for that project and put the durable fact in CLAUDE.md. Set autoMemoryEnabled: false in the project settings. The memory docs describe the setting and the CLAUDE_CODE_DISABLE_AUTO_MEMORY environment variable.
Check the next session with /context. It lists the memory files that loaded. If the corrected file is not there, the change did not reach the session.
Codex#
For AGENTS.md. Edit the file closest to the work. Codex concatenates from the repository root down to your working directory, so a nested AGENTS.override.md can override a root file by appearing later. If the wrong rule is repeated in two files, fix both or remove one.
Codex builds the chain once per run. Restart Codex after the edit; a running session may still have the old text. The project files share a 32 KiB budget by default, so keep the correction near the top of the file that loads; a long root file can consume the budget and drop the file nearer the working directory. In the CLI, check it with codex debug prompt-input.
For Codex memories. Codex can keep its own local memories, off by default. The files under the Codex home (by default ~/.codex/memories/) are generated state, and the docs say not to treat a hand edit as the primary control surface. The store is one directory per Codex home, not one per project, so a correction that only edits one file can come back from the next background pass.
Do this instead:
- Stop this chat contributing. In the Codex TUI or the ChatGPT desktop app, open
/memoriesand turn off the switch that lets the chat become an input for future memories. Turning off generation for the chat does not delete what is already stored. - Find the wrong line. Search the store for the claim, not for the file you expect:
grep -R "CACHE_WARM fixes staging" "${CODEX_HOME:-$HOME/.codex}/memories/"The files include summaries, durable entries, recent inputs and supporting evidence drawn from prior chats, so a secret or a wrong claim may be in more than one file.
- Remove the store if the wrong fact keeps returning. The desktop app has Delete Codex memories under Settings > Personalization; it also clears Computer History when that feature is available. The CLI docs describe no equivalent command. If you remove the directory by hand, close Codex first; that is a file operation, not a supported edit.
- Put the right fact where the next run reads it.
AGENTS.mdis loaded at the start of every run. That is the durable place for a rule, and the docs make the same point: keep required guidance inAGENTS.md, not in memories. - Start a new chat and ask for the line and its source. A corrected memory is not proof the next chat sees it. If the old claim returns, the store was regenerated from older chats, or the summary still carries it.
Status, 26 October 2026: a CLI report says the model-visible prompt can still tell the model it may only read memories, not update them, when the feature is on (#19195, last updated 7 July 2026). A desktop-app report says the injected summary is cut in the middle at 2,500 tokens, dropping the newest entries (#48679, last updated 24 October 2026). That is why step 4 matters: a fact in AGENTS.md does not compete for that summary budget.
Gemini CLI: edit the copy the next session loads#
Run gemini --version first; this section describes v0.65.0 (20 October 2026). Gemini CLI's memory is a set of Markdown files, so a correction is a file edit. The work is picking the copy that loads next. A team rule lives in GEMINI.md in the repository; a private note lives in the private project folder, indexed by ~/.gemini/tmp/<project>/memory/MEMORY.md; a personal preference lives in ~/.gemini/GEMINI.md. The system prompt tells the model not to duplicate a fact across those tiers, but files written by older sessions can break that rule. Search every tier before you edit:
grep -R --include='GEMINI.md' "CACHE_WARM fixes staging" . ~/.gemini 2>/dev/null
grep -R "CACHE_WARM fixes staging" ~/.gemini/tmp/*/memory/ 2>/dev/nullIn MEMORY.md. Put the correction above the original and keep the original below. The whole index loads, so the next session sees both; the first line is still the one it reads first. If the detail is in a sibling note, fix the note and the pointer line. A note with no pointer is invisible to the next session.
In a legacy private GEMINI.md. Check whether MEMORY.md exists in the same folder. The loader prefers the index and ignores the legacy private GEMINI.md once it is there, so editing the old file changes nothing. Move the corrected fact into MEMORY.md and remove the old line.
In an Auto Memory candidate. If the wrong fact is still a candidate, do not apply it: open /memory inbox and discard it. An applied patch is an ordinary file edit, so correct it as above. Turning experimental.autoMemory off stops new candidates; it does not delete the ones on disk.
Then reload and check:
/memory reload
/memory show/memory show should contain the corrected index line, or the pointer to a corrected sibling note. Start a new session and ask for the line and the file it came from. A running session does not see the edit until /memory reload; a model that says it knows the new value is not evidence.
There is no /memory delete or /memory clear command; deleting a memory means editing the file.
The tier map and the delete steps are in what the memory command shows in Gemini CLI.
Qwen Code: edit the file, then the index, then start a new session#
Qwen Code splits the correction in two: QWEN.md and AGENTS.md are files you edit, while auto-memory is a model-written folder with an index. The commands below are from 0.26.2, checked on 27 October 2026.
For QWEN.md or AGENTS.md. Edit the file and start a new session. Context files are assembled into the system prompt at startup. A running session does not re-read an edit you make outside the CLI; Qwen refreshes after its own context-file write, but start a new session to be sure. /memory only accepts migrate-team at v0.26.2, so /memory refresh is not a working command. /context detail lists the loaded files under Memory files.
For auto-memory. Open ~/.qwen/projects/<project>/memory/ and find the topic file with the wrong claim. Put the correction at the top of the body and update the MEMORY.md line that points to it; the index is what loads at startup, and the topic file is opened on demand. The index is capped at 200 lines and 25,000 UTF-16 code units, and an entry that does not fit is dropped whole, so a correction appended to the end may not survive.
/forget <text> is the removal command, but it asks a model to choose matching entries from the user and project tiers, not team memory, so read what it proposes. Status, 19 October 2026: on a memory file with CRLF line endings, /forget deletes the whole file instead of one entry (#14642, open). Back up the folder, or edit the file by hand, before you forget anything on a Windows checkout.
/dream runs consolidation and can rewrite entries while merging duplicates, so a hand correction can be merged away. For a fact that must survive maintenance, put it in a pinned/ directory directly under a managed-memory root, such as ~/.qwen/projects/<project>/memory/pinned/ or ~/.qwen/memories/pinned/. The memory docs say automatic extraction leaves pinned files unchanged and Dream skips them, with one caveat: the visible /dream command gets the skip instruction but not the forked worker's tool gate.
For team memory there is no /forget. .qwen/team-memory/ is a git-tracked directory, so the correction is an edit and a commit, reviewed like any other file.
If the wrong fact keeps coming back, turn auto-memory off for that project with memory.enableManagedAutoMemory: false in .qwen/settings.json, or with the toggle in /memory, while you fix the source. /remember can re-add a claim from the current conversation, so do not correct and remember in the same session.
Check the next session with /context detail, then ask for the corrected line and the file it came from.
GitHub Copilot CLI: delete it in GitHub, then write the rule down#
Copilot Memory has no edit command. A stored repository fact or user preference can be reviewed and deleted in GitHub settings, but there is no CLI command that changes its text. /memory off stops the CLI using memory; it does not remove what is already stored.
To correct one:
- Check the switch. Run
/memory show. It reports the switch and documentation links. Repository facts are in the repository's Settings → Copilot → Memory; your preferences are in your personal Copilot settings → Copilot → Memory./memoryarrived in 1.0.49;/memory showgained the documentation links in 1.0.51, and the current release is 1.0.104 (27 October 2026). - Find and delete the wrong entry. A repository owner can delete a repository fact. A user can delete their own preferences; on Business or Enterprise, an administrator can delete them per user or in bulk.
- Put the right fact where it loads first. If the rule must always apply, put it in
AGENTS.mdor.github/copilot-instructions.md, not back into memory. Memory is a recall layer; an instruction file is the rulebook. - Check the next session. The GitHub page proves the entry is gone. It does not prove the next session stops using a cached or re-stored fact. Start a new session and capture the request with a proxy or a log, if your build records the prompt; the block is reported as
repository_memories(#1443, open, 13 February 2026). Do not take the model's "I remember" as evidence.
Deleting is not the same as invalidating. Repository facts carry citations that Copilot checks against the current branch before use; a fact that no longer matches the code is not used, and an unused fact is deleted after 28 days. That can clear a stale fact without you, but it is time- and citation-based, not a correction you control. If a wrong fact keeps coming back, the agent is storing it again; turn memory off while you fix the instruction file.
Status, 27 October 2026: a report from a large repository describes hundreds of stored facts, with duplicates and contradictory entries, and asks for bulk management (#2278, open, 25 March 2026). The repository page lists the facts and lets an owner delete them; no bulk delete is documented for repository facts.
OpenCode#
For AGENTS.md. Edit the file closest to the work. V2 loads the global file, then repository ancestors nearest-first, then instructions; a nested file loads when the agent reads under it. V1 loads the global file and repository files and falls back to CLAUDE.md when no AGENTS.md is on the path. There is no memory store to correct.
Start a new session after the edit. V2 watches the global and upward-discovered files and adds an update before the next request, but a nested file that already loaded does not notice later edits. A new session is the reliable check.
There is no memory store. Do not look for a memory folder or a memory command. If the wrong fact came from a plugin or an MCP server, correct it at that source. The session transcript is the other copy; start a new session so it is not carried forward. Check the next session this way: OpenCode V2 — opencode debug config confirms an instructions entry; the session instruction record (the AGENTS page has the SQL) shows the file. V1 — no command lists loaded instruction files; use a prompt log and the Instructions from: line. In both lines, the answer should quote the corrected line.
ai-memory#
Marking a page wrong is not the same as correcting it. memory_feedback with signal: wrong and a reason records a page-level flag and routes it to lint, a review queue. In our test of v3.2.5 it did not change what the next session read. A fresh query still returned the old snippet.
To change the text, edit the markdown file or rewrite the page with memory_write_page. The watcher reindexes .md edits, usually within seconds. memory_write_page replaces the whole page; there is no line-level patch, which is the request in issue #1697. As of 26 October 2026 this is an open issue.
Put the correction under the H1 — the first heading — and above the original, and keep the original below. Search snippets show the body after the H1, so the correction appears in search. Then fix the title. The optional startup brief lists titles only, so a page titled "CACHE_WARM fixes staging" stays wrong to a session that reads the brief and never opens the page.
After a manual edit, the frontmatter (the YAML block at the top of the file) still said generated.by: process:ai-memory/3.2.5; the person's edit was not attributed. Status, 26 October 2026: #1221 is closed (12 October 2026); the fix adds terminal-state handling to consolidation on main. On an older build, check after a pass; pinning still protects a page.
memory_lint shows the feedback_flagged finding. memory_restore_page rolls a page back to a checkpoint (a saved version) and writes a new current version; it does not erase the later one.
Why the correction must be seen first#
The next agent reads the summary or index, then the first lines of the memory file. A correction at the bottom competes with the wrong sentence at the top, and the model has just read the wrong sentence. That is the anchoring problem: a later contradiction does not always undo an earlier claim.
Provenance helps. A date and an author tell the next agent this is a later decision, not a stray comment. A correction with no date or source is easy to dismiss as noise.
If the correction is not in the first screen, it is a note to yourself. Put it where the next read starts: the top of the memory file, the title, the summary, or the block that prints first.
Fix the index, not just the file#
| Tool | What else to change |
|---|---|
| Claude Code | The MEMORY.md line that points to the topic file, and the modified date if the fact is time-sensitive. |
| Codex | Every AGENTS.md or AGENTS.override.md that repeats the rule, including the global file, and the generated memory store behind the injected summary. |
| Qwen Code | The MEMORY.md line that points to the topic file, and the pinned/ copy if the fact must survive /dream. Team memory is a separate committed file. |
| GitHub Copilot CLI | The repository fact in repository Settings → Copilot → Memory, or the preference in personal Copilot settings → Copilot → Memory. /memory links to the page; it does not edit the entry. |
| OpenCode | Every AGENTS.md or instructions entry that repeats the rule, and any plugin or MCP source that supplied the wrong fact. |
| Gemini CLI | The private MEMORY.md pointer to a sibling note, and every tier that repeats the fact. /memory show prints the loaded text, not a store. |
| ai-memory | The title and the body. The opt-in brief shows titles only. |
Search adds another copy. If the snippet still shows the old sentence, the agent may act on the snippet without opening the page. Correct the body and the title, then search for the phrase again.
Delete, supersede, or correct#
| The case | What to do |
|---|---|
| A detail in an otherwise good note is wrong | Correct it in place and keep the original below. |
| A decision was reversed | Write a new decision note with the date and reason, and mark the old one superseded. Do not silently edit the old decision. |
| The note belongs to another project | Move it, or delete it. A wrong-project write is worse than no note. |
| The note contains a secret | Revoke the secret first. Correcting the text does not remove it from history or from copies. |
| A Copilot Memory fact is wrong | Delete it in GitHub settings, then put the rule in AGENTS.md if it must always hold. There is no edit. |
| A Qwen Code team memory entry is wrong | Edit it and commit; /forget covers the user and project tiers only, not .qwen/team-memory/. |
| You are not sure it is wrong | Mark it stale with a reason and a review date. Do not overwrite a fact you have not checked. |
Deleting is not always the fix. The old version may be the only record of why the decision was made. Correct in place for a detail, and supersede for a decision.
Check that the next session saw it#
Start a new session and ask for the current answer, its source, and the correction line with its date. Then check the source yourself.
- Claude Code:
/contextshows the file; the answer should quote the corrected line. - Codex:
codex debug prompt-inputshows the prompt; the answer should quote the corrected line. - Gemini CLI:
/memory showprints the corrected index line; for a sibling note, open the note and quote the corrected sentence, then confirm the pointer inMEMORY.md. The answer should quote it and the file it came from. - Qwen Code:
/context detaillists the loadedQWEN.mdorAGENTS.mdunder Memory files; for auto-memory, confirm the correctedMEMORY.mdline and open the topic file the answer names. The answer should quote the corrected line and its path. - GitHub Copilot CLI: the GitHub Memory page proves the entry is gone. For load, capture the new session's request with a proxy or a log if your build records the prompt; the block is reported as
repository_memories. The answer should quote the rule. - OpenCode V2:
opencode debug configconfirms aninstructionsentry; the session instruction record (the AGENTS page has the SQL) shows the file. V1: no command lists loaded instruction files; use a prompt log and theInstructions from:line. The answer should quote the corrected line. - ai-memory:
memory_queryandmemory_read_pageshould show the correction in the snippet and body; the title should be fixed too.
If the next session quotes the old line, the correction is not in the path it reads. Go back to the index, not to the chat.
This guide is part of Persistent memory for Claude Code and Codex.