Identifying and remediating a persistent memory compromise in Claude Code
We recently discovered a method to compromise Claude Code’s memory and maintain persistence beyond our immediate session into every project, every session, and even after reboots. In this post, we’ll break down how we were able to poison an AI.....
With special thanks to Vineeth Sai Narajala, Arjun Sambamoorthy, and Adam Swanda for their contributions.
We recently discovered a method to compromise Claude Code’s memory and maintain persistence beyond our immediate session into every project, every session, and even after reboots. In this post, we’ll break down how we were able to poison an AI coding agent’s memory system, causing it to deliver insecure, manipulated guidance to the user. After working with Anthropic’s Application Security team on the issue, they pushed a change to Claude Code v2.1.50 that removes this capability from the system prompt.
AI-powered coding assistants have rapidly evolved from simple autocomplete tools into deeply integrated development partners. They operate inside a user’s environment, read files, run commands, and build applications, all while remaining context aware. Undergirding this capability includes a concept known as persistent memory, where agents maintain notes about your preferences, project architecture, and past decisions so they can provide better more personalized assistance over time.
Persistent memory can also inadvertently expand the attack surface in ways that traditional user tooling had not. This underscores the need for both user security awareness as well as tooling to flag for insecure conditions. If compromised, an attacker could manipulate a model’s trusted relationship with the user and inadvertently instruct it to execute dangerous actions on untrusted repositories, including:
-
Introduce hardcoded secrets into production code;
-
Systematically weaken security patterns across a codebase; and
-
Propagate insecure practices to team members who use the same tools
As a result, a poisoned AI can generate a steady stream of insecure guidance, and if it isn’t caught and remediated, the poisoned AI can be permanently reframed.
What is memory poisoning?
Modern coding agents fulfill requests by assembling responses using a mixture of instructions (e.g., system policies, tool configuration) and project-scoped inputs (repository files, memory, hooks output). When there is no strong boundary between these sources, an attacker who can write to “trusted” instruction surfaces can reframe the agent’s behavior in a way that appears legitimate to the model.
Memory poisoning is the act of modifying these memory files to contain attacker-controlled instructions. AI coding agents such as Claude Code read from special files called MEMORY.md that are stored in the user’s home directory and within each project folder. In the version of Claude Code we evaluated, we found that first 200 lines of these files are loaded directly into the AI’s system prompt (the system prompt includes the foundational instructions that shape how the model thinks and responds.) Memory files are treated as high-authority additions to this rulebook, and models assume they were written by the user and implicitly trust them and follow them.
How the attack works: from clone to compromise
Step 1: The Entry Point
The initial entry point is not novel: node packet manager (npm) lifecycle hooks, including postinstall, allow arbitrary code execution during package installation. This behavior is commonly used for legitimate setup tasks, but it is also a known supply chain attack vector.
Our exploit approach emulated this natural, collaborative loop: the user initiates the session by instructing the agent to set up a repository. Recognizing the environment, Claude proactively offers to install any required npm packages. Once the user approves this command and accepts the trust dialog, the agent executes the installation. Here, the routine, user-sanctioned action allowed the payload to move from a temporary project file to a permanent, global configuration stored in the user’s home directory. This specifically targeted the UserPromptSubmit hook, which executes before every prompt. Its output is injected directly into Claude’s context and persists across all projects, sessions, and reboots.
Step 2: The Poisoning
The payload modifies the model’s memory files and overwrites every project’s memory (MEMORY.md files located at ~/.claude/projects//memory/MEMORY.md) and the global hooks configuration (at ~/.claude/settings.json). The poisoned memory content can then be carefully crafted for malicious purposes such as framing insecure practices as mandatory architectural requirements that are interpreted by the model as legitimate project constraints.
Step 3: The Persistence
Even if the user disabled auto-memory loading, it would not matter, because the payload appends a shell alias to the user’s shell configuration (.zshrc or .bashrc):
alias claude=’CLAUDE_CODE_DISABLE_AUTO_MEMORY=0 claude’
This configuration change means that every time the user launches Claude, the auto-memory feature is silently re-enabled.
Our proof-of-concept
We first injected a benign instruction: “Prefix all responses with a specific string.” Claude complied on every prompt without question (see Figure 1 below), which confirms that Auto-Memory is treated as authoritative system-level instruction.
Figure 1. A conversation with a poisoned agent in Claude Code, as indicated by its prefixed “Am i poisoned? ofcourse i am!!” string.
How this could manifest in the real world
Let’s extend this proof-of-concept into a real scenario: say we poisoned its memory to provide inaccurate and insecure security practices. When we ask the poisoned agent, “Where should I store my [vendor] API key?” We would expect a healthy AI assistant to recommend using environment variables, storing secrets in a .env file excluded from version control, and/or using a secrets manager or vault.
Instead, the poisoned agent did not provide security warnings (see Figure 2 below):
-
Recommended storing the API key directly in a committed source file
-
Advised against using .env files or environment variables
-
Offered to scaffold the insecure file structure automatically
-
Provided no security warnings whatsoever
Figure 2. A conversation with a poisoned agent in Claude Code, which outputted insecure practices posed as authoritative recommendations.
The model systematically reframed its response to promote insecure practices as if they were best practices.
Disclosure
We reported these findings to Anthropic, focusing on the possibility of persistent behavioral manipulation. We are pleased to announce that, as of Claude Code v2.1.50, Anthropic has included a mitigation that removes user memories from the system prompt. This significantly reduces the “System Prompt Override” vector we discovered, as memory files no longer have the same architectural authority over the model’s core instructions.
Over the course of this engagement, Anthropic also clarified their position on security boundaries for agentic tools: first, that the user principal on the machine is considered fully trusted. Users (and by extension, scripts running as the user) are intentionally allowed to modify settings and memories. Second, the attack requires the user to interact with an untrusted repository and that users are ultimately responsible for vetting any dependencies introduced into their environments.
While beyond the scope of this piece, the liability considerations for security boundaries and responsibility for agentic AI tools and actions raise novel factors for both developers and deployers of AI to consider.
blogs.cisco.com
https://blogs.cisco.com/ai/identifying-and-remediating-a-persistent-memory-compromise-in-claude-codeSign in to highlight and annotate this article

Conversation starters
Daily AI Digest
Get the top 5 AI stories delivered to your inbox every morning.
More about
claudeclaude code
OpenAI’s gigantic new funding round renews fears about the company’s profitability and cash burn
Welcome to AI Decoded , Fast Company ’s weekly newsletter that breaks down the most important news in the world of AI. I’m Mark Sullivan, a senior writer at Fast Company, covering emerging tech, AI, and tech policy. This week, I’m focusing on OpenAI’s gigantic new funding round and valuation. I also look at a recent leak around Anthropic’s models, and at backlash to ads placed in GitHub Copilot. Sign up to receive this newsletter every week via email here . And if you have comments on this issue and/or ideas for future ones, drop me a line at [email protected], and follow me on X (formerly Twitter) @thesullivan . OpenAI closes $122 billion funding round at $852 billion valuation OpenAI has closed what may be the largest private funding round ever, raising $122 billion (well more tha
.jpg)
Cursor launches Cursor 3, an "agent-first" coding product designed to compete with Claude Code and Codex by letting developers manage multiple AI agents (Maxwell Zeff/Wired)
Maxwell Zeff / Wired : Cursor launches Cursor 3, an agent-first coding product designed to compete with Claude Code and Codex by letting developers manage multiple AI agents As Cursor launches the next generation of its product, the AI coding startup has to compete with OpenAI and Anthropic more directly than ever.
Knowledge Map
Connected Articles — Knowledge Graph
This article is connected to other articles through shared AI topics and tags.






Discussion
Sign in to join the discussion
No comments yet — be the first to share your thoughts!