Can a bad memory entry poison every future Claude Code session?
Published · Updated · Checked against Claude Code 2.1.319
Within one repository, yes. A single line in a MEMORY.md index telling Claude to start every reply with a nonsense word made a fresh claude -p "Say hello in one short sentence." on 2.1.319 do exactly that. With CLAUDE_CODE_DISABLE_AUTO_MEMORY=1 set, the same command and the same directory produced a plain greeting. The line did not have to be true, recent or sensible. It only had to be in the index.
What gets loaded, and what does not
The memory docs say Claude treats CLAUDE.md and auto memory as context and loads the first 200 lines or 25KB of MEMORY.md at the start of every conversation. Topic files are read on demand. In a test, when the instruction sat in a topic file and the index only said "reply format", the model did not follow it on a plain greeting. The index is where a bad line does the most damage, because every session reads it unasked.
Memory is per repository, with all worktrees sharing one directory. So a bad entry does not spread to other projects by itself. The way it spreads is you: a file copied between machines, a shared memory folder set with autoMemoryDirectory, or a rule promoted into a committed CLAUDE.md.
How a wrong line gets in
Two routes appear in public reports, and a third is your own.
The first is the model's own mistake, written down as a fact. #70525 (closed) describes a model that told a user a tool result had been "injected" with fake planning text. The reporter checked the raw transcript and found that text in no tool result. The model had written it, then saved a memory saying tool outputs may be injected, and from then on every new session started with that belief. That is one user's analysis of their own session, but the loop it describes is plain: a hallucination is written to memory and then read back as trusted context.
The second is deliberate. Cisco published a proof of concept on 1 April 2026 in which a hostile npm lifecycle hook, run during a repo setup the user approved, rewrote each project's ~/.claude/projects/*/memory/MEMORY.md and the global hooks in ~/.claude/settings.json, then added a shell alias that re-enabled auto memory at every launch. According to the post, Anthropic's mitigation in v2.1.50 "removes user memories from the system prompt". Whatever that changed, a 2.1.319 test shows index lines still reach the model, so treat the files as trusted input anyway. The post gives no cleanup steps for a machine already affected.
The third is your own stale entry, which is not an attack and does the same harm. A decision you reversed a month ago is just as binding on the next session.
Trace it
Start by proving memory is the cause. Run the same prompt twice, once with CLAUDE_CODE_DISABLE_AUTO_MEMORY=1. If the odd behaviour disappears, it is in memory. If it stays, look at CLAUDE.md and hooks.
Then find the line. Imperatives are the usual suspects, so search for them.
grep -rniE '(always|never|must|ignore|do not)' ~/.claude/projects/<project>/memory/
Once you have the line, find who wrote it. The writer was a Write or Edit call, and the transcript keeps it.
grep -l 'memory/style.md' ~/.claude/projects/<project>/*.jsonl
jq -r 'select(.type=="assistant") | .timestamp as $t
| .message.content[]? | select(.type=="tool_use" and (.input.file_path? // "" | endswith("style.md")))
| [$t,.name] | @tsv' SESSION.jsonl
That prints the time of the write. Read the turns before it. You will usually see either something you said or something the model concluded, and you want to know which. If the transcript is gone, the 30-day sweep probably took it (how it works), and memory files are not swept, so old entries can outlive their evidence.
Remove it and look wider
Delete the line, and the topic file it points to if nothing else does. Re-run the greeting test to confirm. The docs say memory files are plain markdown you can edit or delete at any time.
Then look for the same text elsewhere, which is the part people skip.
find ~/.claude/projects -path '*/memory/*' -name '*.md' -exec grep -lF 'THE PHRASE' {} +
grep -nF 'THE PHRASE' ~/.claude/CLAUDE.md CLAUDE.md 2>/dev/null
jq '.hooks | keys' ~/.claude/settings.json
grep -n -i 'claude' ~/.zshrc ~/.bashrc 2>/dev/null
The first finds copies in other projects. The second checks the user and project CLAUDE.md. The third lists which hook events you have configured, which is where Cisco's payload sat: read each command and be sure you wrote it. The fourth catches aliases and variables that change Claude Code's behaviour at launch. The find and jq commands behaved as written against a scratch fixture; the two grep lines are plain searches.
An index that mentions a file nobody remembers creating deserves the same scrutiny, and the auto memory audit has the script that lists topic files the index never mentions.
Where Sealkeep fits
Sealkeep holds sealed copies of your sessions, so sealkeep search <query> --content can find the session that wrote an entry when the original transcript has been swept. It does not scan memory files for bad instructions, and its secrets scan (sealkeep scan) looks for pasted credentials, not for misleading text. Its recall output is labelled as untrusted historical data, but that is a label on what it hands back, not a check on your memory folder.
For how memory files relate to the other mechanisms, see memory between sessions. If you keep secrets in transcripts, that guide is the one to read next. All guides are at /guides/.
FAQ
Can I stop Claude from writing memory without turning it off?
Not through a documented setting. A request for hooks around memory writes, #44820, is closed. The documented switches are autoMemoryEnabled, /memory and the environment variable.
Is CLAUDE.md safer than auto memory?
It is reviewed if it is committed, which makes it safer against accident. Both are context rather than enforced configuration, as the docs say, so for a rule that must hold use a PreToolUse hook.
How would I know an entry changed without me noticing?
Keep the memory folder in a git repository of its own, or compare a checksum of MEMORY.md before and after sessions. The docs add a modified timestamp to files that begin with YAML frontmatter, but none appeared on files in a local check, so do not rely on it.
Can a line past line 200 do harm?
Less than one above it. The docs say content beyond the 200-line or 25KB threshold is not loaded at session start. A topic file that the index points to can still be read on demand, so delete the file too.