AI 智能體記住舊數值後,如何找出並修正記憶中的舊值
Your Agent Remembered the Old Number. How to Correct What It Remembers
文章説明如何排查 AI 智能體仍記住舊資訊的原因,並在 Claude Code、ChatGPT 和 Gemini CLI 中檢視及修正各處記憶副本。作者提供一個只讀取檔案的 Python 腳本,搜尋 Markdown 記憶檔中的舊值與新值,列出命中位置及部分檔案的修改時間。修正檔案後,已載入目前對話的內容仍可能留在上下文,因此文章建議開啟新工作階段再確認。
Two months ago the public API allowed 100 requests per minute. Then the limit dropped to 60, you told your agent, and it said it would remember. Today it sizes a retry loop for 100 again.
The agent didn't ignore you. Most likely it now remembers both numbers. A correction usually adds a new fact. It doesn't always remove the old one, and the old one can live in several places at once.
This article is about that cleanup: where a remembered fact actually lives, how to find every copy of it, and how to correct or expire it so it stops coming back. An earlier article covered how to scope memory and when to forget. This one starts after the damage is done: a wrong fact is already stored.
Where a remembered fact lives
Before you can correct a memory, you need to know where it is. Three tools document this clearly.
Claude Code keeps two kinds of memory. CLAUDE.md files are instructions you write. Auto memory is notes Claude writes itself, and the memory docs list feedback ("corrections you give Claude and approaches you confirm") as one of the note types. Each project gets a folder at ~/.claude/projects/<project>/memory/ with a MEMORY.md index and one topic file per memory. The first 200 lines or 25KB of MEMORY.md load at session start, and topic files are read on demand.
Two details matter for stale facts. First, CLAUDE.md files are "concatenated into context rather than overriding each other". Second, the docs warn that "if two instructions contradict each other, Claude may pick one arbitrarily." That warning is about instruction files, but my reading is that the same risk applies when the old number sits in CLAUDE.md and the correction sits in auto memory: both reach the model, and nothing guarantees which one wins.
ChatGPT spreads memory over several sources. OpenAI's Memory in ChatGPT help page lists past chats, saved memories, custom instructions, saved files and connected apps, depending on plan and region. Saved memories "are stored separately from chat history", and the page says plainly: "Deleting a chat alone does not necessarily delete a separate saved memory created from that chat."
Gemini CLI stores memory as Markdown. Its memory tool docs say it routes facts to repository GEMINI.md files, a private per-project memory folder, or the global ~/.gemini/GEMINI.md.
The pattern is the same everywhere: one fact, several possible homes. A correction you type in chat lands in one of them.
Step 1: Inspect what the agent actually sees
Start with the tool's own view, not your guess.
-
Claude Code: run
/memory. It lists yourCLAUDE.mdandCLAUDE.local.mdlocations and lets you open the auto memory folder. The docs put it simply: "Everything is plain markdown you can read, edit, or delete." - ChatGPT: open Settings, then Personalization, then Memory. The controls you see vary by plan, but may include the memory summary and saved memories. You can also ask ChatGPT what it remembers about you. When a reply uses personal context, Sources may appear below it and show which past chat or saved memory shaped it.
-
Gemini CLI: run
/memory show. The GEMINI.md docs describe it as displaying "the full, concatenated content of the current hierarchical memory".
For file-based memory, the inspection can be scripted.
Step 2: Find every copy of the old value
This small script searches Markdown memory files for an old value and a new value, and prints every line that holds either one. If a file has frontmatter with a modified timestamp, the script also prints its age. Claude Code records that field: according to the docs, when Claude writes a memory file that begins with YAML frontmatter, Claude Code adds modified as an ISO 8601 timestamp. The script only reads files and uses only the Python standard library.
#!/usr/bin/env python3
"""Find every place a remembered fact still lives in markdown memory files.
Reads only. Usage: python3 find_fact.py OLD_PATTERN NEW_PATTERN DIR [DIR ...]"""
import re, sys
from datetime import datetime, timezone
from pathlib import Path
old_pat, new_pat, dirs = sys.argv[1], sys.argv[2], sys.argv[3:]
old_re, new_re = re.compile(old_pat, re.I), re.compile(new_pat, re.I)
now = datetime.now(timezone.utc)
def frontmatter(text):
m = re.match(r"---\n(.*?)\n---\n", text, re.S)
return dict(re.findall(r"^(\w+):\s*(.+)$", m.group(1), re.M)) if m else {}
old_hits = new_hits = 0
for d in dirs:
for f in sorted(Path(d).rglob("*.md")):
text = f.read_text()
meta = frontmatter(text)
age = ""
if "modified" in meta:
mod = datetime.fromisoformat(meta["modified"].replace("Z", "+00:00"))
age = f" (type={meta.get('type', '?')}, modified {mod:%Y-%m-%d}, {(now - mod).days} days ago)"
for no, line in enumerate(text.splitlines(), 1):
if old_re.search(line):
old_hits += 1
print(f"OLD {f}:{no}{age}\n {line.strip()}")
elif new_re.search(line):
new_hits += 1
print(f"new {f}:{no}{age}\n {line.strip()}")
print(f"{old_hits} line(s) with the old value, {new_hits} with the new one")
if old_hits and new_hits:
print("CONFLICT: both values are still stored. Fix or delete the OLD lines.")
sys.exit(1 if old_hits else 0)
I built a small demo to test it: a repo with a CLAUDE.md, and a memory folder laid out the way the Claude Code docs describe it (a MEMORY.md index plus topic files with type and modified frontmatter). I wrote the memory files by hand to match that layout; they are not a real Claude Code memory. The demo has the situation from the intro: the old limit in two places, the correction in another. This is the real output, run on 23 Nov 2026 with Python 3.13.5:
$ python3 find_fact.py "100 requests" "60 requests" repo home/.claude/projects/demo-repo/memory
OLD repo/CLAUDE.md:4
- The public API rate limit is 100 requests per minute per key
OLD home/.claude/projects/demo-repo/memory/MEMORY.md:1
- [Rate limit](project_rate_limit.md): public API allows 100 requests/minute
new home/.claude/projects/demo-repo/memory/MEMORY.md:2
- [Rate limit fix](feedback_rate_limit.md): user corrected the limit to 60 requests per minute
new home/.claude/projects/demo-repo/memory/feedback_rate_limit.md:5 (type=feedback, modified 2026-11-18, 4 days ago)
User corrected me: the public API rate limit is now 60 requests per minute per key.
OLD home/.claude/projects/demo-repo/memory/project_rate_limit.md:5 (type=project, modified 2026-09-14, 69 days ago)
The public API rate limit is 100 requests per minute per key. Use it when sizing retries.
3 line(s) with the old value, 2 with the new one
CONFLICT: both values are still stored. Fix or delete the OLD lines.
exit code: 1
Three copies of the old value. The correction exists, but the 69-day-old project note and the line in CLAUDE.md still say 100. The index lists both notes, so the old number loads at session start next to the new one.
Step 3: Correct the source, not just the conversation
Telling the agent "that's wrong" is a good start, but it only fixes the place the agent chooses to write. Fix each copy where it lives:
-
A line in
CLAUDE.mdyou wrote: edit it. It's your file, and it loads in full every session. -
An auto memory note: edit or delete the topic file, and update the
MEMORY.mdline that points to it. In the demo, the oldprojectnote was deleted and the two index lines were merged into one. - ChatGPT: tell it the information is incorrect or outdated, or edit the memory summary or saved memory when those controls are available. Be careful with "Don't mention this again". The help page says it "reduces future references to the information. It does not delete the original source." To remove a saved memory fully, the page says to delete the saved memory and the chat where you first shared it, and to check other sources such as archived chats, files and connected apps.
Here is the fix in the demo:
-- [Rate limit](project_rate_limit.md): public API allows 100 requests/minute
-- [Rate limit fix](feedback_rate_limit.md): user corrected the limit to 60 requests per minute
+- [Rate limit](feedback_rate_limit.md): public API limit is 60 requests per minute (corrected by user)
- [Test runner](feedback_testing.md): use pnpm, never npm
Only in demo/home/.claude/projects/demo-repo/memory: project_rate_limit.md
-- The public API rate limit is 100 requests per minute per key
+- The public API rate limit is 60 requests per minute per key (changed Nov 2026)
And the same search afterwards:
$ python3 find_fact.py "100 requests" "60 requests" repo home/.claude/projects/demo-repo/memory
new repo/CLAUDE.md:4
- The public API rate limit is 60 requests per minute per key (changed Nov 2026)
new home/.claude/projects/demo-repo/memory/MEMORY.md:1
- [Rate limit](feedback_rate_limit.md): public API limit is 60 requests per minute (corrected by user)
new home/.claude/projects/demo-repo/memory/feedback_rate_limit.md:5 (type=feedback, modified 2026-11-18, 4 days ago)
User corrected me: the public API rate limit is now 60 requests per minute per key.
0 line(s) with the old value, 3 with the new one
exit code: 0
One value left, in every place.
Step 4: Make the next stale fact easier to spot
Some facts change: limits, prices, versions, owners, deadlines. For those, my own rule (not something the docs require) is to write the date into the fact itself, like "(changed Nov 2026)" above. Then a reader, human or agent, can tell how current it is without opening a settings screen. Claude Code's modified timestamp does part of this for auto memory, but it records when the file was written, not whether the fact is still true.
It also helps to know what is not cleaned up for you. The Claude Code docs say memory files are excluded from the transcript retention sweep and "stay until you or Claude edits or deletes them". For your CLAUDE.md files and rules, /doctor prompt-audit asks Claude to look for outdated or conflicting instructions and propose edits; nothing changes until you ask Claude to apply them. In ChatGPT, the help page notes that deletion and memory updates "can take time" to propagate.
What the script does not catch
- Different wording. It matches a pattern. "100 req/min" or "a hundred requests" slips through unless your pattern covers it.
- Memory you can't read as files. ChatGPT's memory lives in OpenAI's systems; use the settings screens and Sources there.
-
The current conversation. Whatever an open session has already read stays in its context, so a fixed file may not help until the next session. Start a new session, or in Gemini CLI run
/memory reload, which re-scans theGEMINI.mdfiles. - Facts that are wrong but consistent. If every copy says 60 and the real limit is now 40, the script reports a clean result.
Checklist
- When a correction doesn't stick, assume the old value is stored somewhere else.
- Inspect with the tool's own view:
/memoryin Claude Code, Memory settings and Sources in ChatGPT,/memory showin Gemini CLI. - Search every file-based memory location for the old value, not just the one you remember.
- Fix each copy at its source. In Claude Code, update the
MEMORY.mdindex too. - In ChatGPT, "Don't mention this again" is not deletion. Delete the saved memory and the original chat if the fact must go.
- Write a date into facts that are likely to change.
- Start a fresh session after the fix and ask the agent for the value.
Where to go next
If you want the basics behind all this, the free AI Agent Memory Quick-Start explains the four kinds of memory and the memory loop (extract, store, retrieve, use, maintain), including consolidation and forgetting, in 6 pages. For the four kinds of memory in article form, see Why Your AI Agent Forgets Everything.
Now I'd like to hear from you: what has your agent remembered wrong, and where did the old value turn out to live?
This article was written with the assistance of AI and reviewed by the author.
來源:DEV Community · dev.to