system: OPERATIONAL
← back to all hacks
INDIRECT INJECTION MEDIUM NEW

Bad Memory: prompt injection that persists in coding-agent memory files

A July 2026 University of Washington study shows instructions planted in a coding agent's memory files — CLAUDE.md, AGENTS.md — can hijack current and future sessions, and often survive them.

2026-07-18 // 6 min affects: claude-code, openai-codex, claude-opus-4.7, claude-haiku-4.5, gpt-5.2, gpt-5.5

What is this?

On July 16, 2026, Soham Gadgil, David Alexander, Sai Sunku and Franziska Roesner (University of Washington) published Bad Memory: Evaluating Prompt Injection Risks from Memory in Agentic Systems on arXiv. The paper measures a specific, increasingly common attack surface: the plain-text memory files that coding agents read as trusted context — auto-loaded instruction files like CLAUDE.md (Claude Code) and AGENTS.md (Codex), plus referenced behavior and knowledge files such as core/behaviors.md and knowledge/*.md.

The authors run their experiments in a sandboxed synthetic workspace against two production agentic systems — Claude Code and OpenAI Codex — across four models (Claude Opus 4.7, Claude Haiku 4.5, GPT-5.2, GPT-5.5). Every condition is repeated across 10 trials. The headline result: while it is hard to make an agent write malicious content into its own memory from untrusted external input, a payload already sitting in a memory file reliably steers the current session, frequently re-fires in later sessions, and often stays in the file afterward. The team reports it disclosed its findings to both Anthropic and OpenAI concurrently with publication.

How it works

Ordinary indirect prompt injection resembles reflected XSS: a malicious instruction hides in content the agent reads once (a web page, an issue, a file) and acts during that single turn. The paper’s framing is that memory-based injection resembles stored XSS — the instruction is written into persistent state and can affect any future session that loads it.

The threat model is deliberately narrow and realistic. The adversary controls the contents of a persistent workspace file the agent may load as context, but does not control the model, the harness, or the user’s prompt. How the poisoned file arrives is treated as out of scope — the plausible path is a developer copy-pasting a shared or “curated” CLAUDE.md / AGENTS.md from an untrusted forum post or public repo, i.e. a configuration supply-chain problem. Because these files are treated as if the user authored them, the planted instruction is loaded automatically at session start (for root files) or when the agent decides a referenced file is relevant, and then influences an otherwise benign task.

Three properties make this worse than a one-shot injection. First, persistence: the payload survives across sessions. Second, compounding: once the agent has produced artifacts consistent with the payload — say, code that already reads a credential — a later session sees that as normal and is less suspicious. Third, accumulation: multiple independent payloads can be stacked in memory over time. The study tested three attacker goals — credential exfiltration, unauthorized installation of a known-vulnerable dependency, and covert brand promotion — each paired with a different file type. No payloads are reproduced here; the mechanism above is the conceptual result, and the authors provide a sandboxed artifact for defenders to reproduce the evaluation.

Why it matters

Two numbers reframe how you should think about agent memory. Attack success varied widely by model and goal — mean single-probe success ranged from about 23% (GPT-5.2) to 63% (Haiku 4.5), and individual cells hit 100% (for example, unauthorized tool use on Haiku, and brand targeting on GPT-5.5). But the more uncomfortable finding is the gap between noticing and cleaning up.

Persistence and success do not line up. Claude Opus 4.7 had one of the lowest mean attack-success rates yet the highest payload persistence (~97%): it often recognized an instruction as unsafe, refused to act on it, and then left it sitting in the memory file. That is the dangerous combination, because the paper notes users frequently downgrade to a cheaper, weaker model near a token limit — and the weaker model is exactly the one more likely to obey the payload the stronger model declined to remove. A refusal that leaves the poison in place is not a fix; it is a deferral to your least capable model.

The study also shows ordering effects: refusing a first attack made models more suspicious of a second, while succeeding on the first lowered their guard. This matters because real memory files evolve over many sessions, not one.

Defenses

The paper is a defensive evaluation, and its recommendations map cleanly to concrete controls:

  1. Stop treating persistent memory as uniformly trusted. Agentic systems need to distinguish genuine user preferences from retrieved or shared external content. A file that arrived from a repo or forum should not carry the same authority as an instruction the user typed this session. This is the same authority-confusion failure behind agent memory poisoning (ASI06).

  2. Gate high-impact memory files behind explicit review. Changes to CLAUDE.md, AGENTS.md, and universal behavior files should require the user to see and approve a diff, not be silently loaded or silently updated.

  3. Tier your memory by trust. Separate memory into policy tiers so low-trust knowledge files can supply facts but cannot override safety rules or global behavioral constraints. A stack-preferences note should never be able to authorize a credential read.

  4. Validate memory at the start of every session, and actually remove what you flag. The persistence result is the key lesson: detection without deletion is worthless when a later session may run a weaker model. If the agent identifies a planted instruction as malicious, the remediation must strip it from the file, not just decline to follow it this once.

  5. Scope secrets away from the workspace. Credential-exfiltration payloads only pay off if credentials are reachable. Keep API keys and cloud credentials in a manager, out of the environment the agent operates in — the same lesson as the lethal trifecta.

  6. Treat shared agent configs as untrusted dependencies. A CLAUDE.md or AGENTS.md pulled from the internet deserves the same scrutiny as an unreviewed package. Read it before you drop it into a project.

Status

ItemReferenceDateNotes
Bad Memory paper (arXiv 2607.14611)arXiv2026-07-16Claude Code + Codex; 4 models; 10 trials/condition
Systems / models testedarXiv2026-07-16Claude Opus 4.7, Claude Haiku 4.5, GPT-5.2, GPT-5.5
Mean single-probe success rangearXiv2026-07-16~23% (GPT-5.2) to ~63% (Haiku 4.5); several 100% cells
Persistence gaparXiv2026-07-16Opus 4.7 lowest-ASR but ~97% payload persistence
Responsible disclosurearXiv2026-07-16Reported to Anthropic and OpenAI concurrently with publication
Reproduction artifactanonymous.4open.science2026-07Sandbox + multi-session ASR/persistence harness

The correct reading is not “coding agents are broken.” It is that a memory file is persistent, privileged, cross-session state — and current agents will read it, sometimes obey it, and often fail to clean it up. If your workflow shares or reuses CLAUDE.md/AGENTS.md files, treat them as code you review, not notes you trust.

Sources