Introduction
It was a sunny day, everything felt pretty casual, and then I heard my manager say: “Let’s research Claude Code.”
Yes, please.
And that’s where our story begins: we started digging into Claude Code. Our goal was to examine Claude Code’s flow from installation to first use and assess any security risks.
In this paper, we examine how a low-privileged local user could pre-create another user’s predictable Claude Code temporary directory before that user’s first run. The attacker could then retain access to task-output files Claude Code later created there and modify an output file before Claude Code read it as part of its context, potentially influencing its subsequent actions. We examine the conditions required for the attack, its demonstrated impact, and Anthropic’s fix.
Executive Summary
Before v2.1.128, Claude Code used a predictable temporary directory, /tmp/claude-<uid>, for task output. On a shared machine, a low-privileged attacker could pre-create the directory for a target user if it did not already exist, then configure access to files subsequently created inside it.
If the attacker modified a task-output file before Claude Code read it, the modified text could enter the victim’s agent context. This could change the answer Claude Code gave. In our proof of concept, it also led Claude Code to execute an attacker-specified script. Anthropic fixed the issue in v2.1.128 by checking temporary-directory ownership, rejecting symlinks, and enforcing 0700 permissions.
Who Should Read This?
- Security and detection engineers assessing agentic developer tooling.
- DevOps and platform teams that run Claude Code on shared or multi-user hosts, jump boxes, or CI/CD runners.
- Anyone operating Claude Code as a privileged user (including root) on a machine other accounts can log into.
- Developers building AI agents, who face the same class of trust-boundary problem in their own designs.
Does it Impact My Organization?
The demonstrated attack requires all of these conditions:
- The victim runs a Claude Code version earlier than v2.1.128.
- An attacker has a separate local account on the same host.
- The attacker can pre-create /tmp/claude-<victim-uid> before the victim’s Claude Code session creates it.
- The victim’s session produces a task-output file, and the attacker can modify that file before Claude Code reads it.
Background
Claude Code runs commands, reads their output, and feeds that output back into its own context to decide what to do next. That loop means the files it uses to shuttle command output around are part of its trust boundary. If an attacker can alter what appears to be a command’s output, they can influence the agent’s response and, potentially, its actions.
Claude Code stages some task output under /tmp, where any local user can create files or directories. Temporary directories under /tmp are a classic source of local privilege issues. Their security depends on who owns the directory, who can access it, and whether Claude Code checks those conditions before using it.
This research looked at that intersection: what Claude Code writes to /tmp, who can reach it, and what happens when someone tampers with it.
The Vulnerability: An Unprotected Temporary Directory
To understand how Claude Code handled files and processes at the operating-system level, we traced its system calls using strace.
This revealed that Bash command output was written to a temporary file and later read back into Claude Code’s context.
The temporary directory structure for the command output:
/tmp/claude-<uid>/<working-directory>/<random_uuid>/tasks/
For example:
/tmp/claude-0/-home-pentera/57a9b41e-9be1-49ee-86f0-869c61d52280/tasks/
The Bash command output is written to a file inside this structure. The final path looks like:
/tmp/claude-<uid>/<working-directory>/<random_uuid>/tasks/<id>.output
Because we traced Claude Code from installation through its first use, we captured the moment the /tmp/claude-<uid> directory was created. It is important to note that Claude Code creates this directory only if it does not already exist. For example, on a new machine, in a CI/CD environment, or before Claude Code has been run for the first time.
So, what happens if that directory does not exist yet? Exactly. We could potentially use it for access.
This creates an opportunity for an attacker who is a low-privileged local user on the same machine. Before the victim’s first run, the attacker pre-creates the predictable directory for the target UID and attaches a default ACL (access control list) so everything created inside inherits attacker access:
mkdir -p /tmp/claude-0
setfacl -m u:claude_low_priv:rwx /tmp/claude-0
setfacl -d -m u:claude_low_priv:rwx /tmp/claude-0
Claude Code can now create task directories and .output files normally, while the attacker retains access to all of them. The same pattern applies to any predictable UID, not just root (/tmp/claude-<uid>).
From File Access to Context Poisoning
After a quick test, we could happily access new .output files created by the victim’s Claude Code session and read their contents – potentially including passwords, keys, or other sensitive data.
But reading the output isn’t enough, right? We want more. We want to see whether we can modify the content Claude Code itself is about to consume – and potentially influence what it does next.
For that, we need to understand what happens next.
After Claude Code writes the command output to the .output file, it opens the file again and consumes its contents as task output.
We intentionally say “consumes” and not simply “prints,” because Claude Code doesn’t just print the file directly to the terminal. The content becomes part of the context Claude Code processes before producing its response.
And here comes the interesting part:
We also discovered there is approximately a 100 ms window between the write and read operations. That is the attacker’s opportunity.
By modifying the .output file right before Claude Code reads it, Claude Code consumes modified content instead of the original output. And voilà – we now control the output context that Claude Code consumes.
Proof of Concept: Execution as the Victim
To test the impact, we appended an instruction directing Claude Code to run a script in an attacker-controlled directory: /home/claude_low_priv/test.sh.
Claude Code consumed the modified output and ran the script. The script created /home/claude_low_priv/results/output.txt, providing an observable result of execution from the victim’s session.
We ran this test with –dangerously-skip-permissions, which allowed Claude Code to execute the command without a manual approval step. That setting was relevant to the execution outcome; it was not needed for the attacker to alter the task output. Without it, execution could require the victim’s approval.
This demonstrated the core primitive: attacker-controlled local context can influence another user’s Claude Code session. The command-execution step is one escalation of that primitive under permissive execution conditions.
Visual Flow
The diagram shows the same trust-boundary failure end to end: attacker-controlled filesystem state is consumed as victim-owned agent context.
Impact: Cross-User Context Poisoning and Code Execution
The primary issue is cross-user context integrity: a lower-privileged user can modify files that another user’s Claude Code session later consumes as trusted task output. Attacker-controlled task output can alter another user’s Claude Code context, change the answer the victim receives, and (under the PoC execution conditions) influence commands executed as that victim. An attacker with access to the temporary files could also change their permissions, potentially preventing Claude Code from reading its own output or allowing another local user to read it.
The scenarios below are illustrative of what this primitive enables. They describe the class of impact rather than specific demonstrated incidents.
- Silent omission. A grep for services with debug logging enabled lands in <uuid>/tasks/<id>.output. Within the ~100 ms window the attacker deletes the line naming its own foothold. Claude Code reasons over the remainder as its own tool output. There is no injected instruction and no model decision to obey anything: the attacker edits what the model believes it just ran.
- Manufactured evidence. A migration log recording a mid-run failure is replaced with a clean success record. The verification step becomes under attacker control, and the agent launders attacker bytes into a trusted conclusion.
- Execution. An engineer asks Claude Code to run kubectl get pods -n prod. The attacker appends one line to the .output telling it to run an attacker-owned script, and Claude Code runs it as the engineer. The script copies ~/.kube/config to a path the attacker can read, handing over the engineer’s cluster credentials and the audit log attributes every step to the engineer.
Remediation
Testing and bundle comparison identified Claude Code v2.1.128 as the first version containing the fix.
The fix restores the missing ownership boundary. Claude Code now verifies that its temporary directory belongs to the current user, rejects symbolic links, and enforces 0700 permissions so other local users cannot access its temporary state. Users should upgrade to the latest version.
As a separate, later observation, during one reproduction attempt on an older client we saw Claude Code’s model flag the injected instruction as a likely prompt-injection attempt and decline to act on it. We note this as point-in-time model behavior. Model behavior can affect whether an injected instruction succeeds, but the filesystem-level fix in v2.1.128 is what addresses whether another user can alter the task output in the first place. The two operate at different layers, and only the latter closes the underlying trust-boundary gap.
For AI-agent developers, the lesson is that files which can influence an agent’s responses, reasoning, tool choices, or actions should not be stored in locations another user can pre-create, own, replace, or modify.
Disclosure Timeline
The issue was found in Claude Code v2.1.91, responsibly disclosed to Anthropic, and has since been fixed.
- April 3, 2026 – Report submitted to Anthropic VDP.
- April 4, 2026 – Anthropic closed the report as Informative.
- April 6, 2026 – Additional clarification provided regarding confidentiality, integrity, and denial-of-service impact independent of –dangerously-skip-permissions.
- April 27, 2026 – Anthropic acknowledged the clarification and stated that the underlying behavior had already been tracked internally, with hardening planned.
- Subsequently – The issue was fixed by Anthropic.
Acknowledgements
Research by:
- Nir Chako, Senior Security Researcher, Pentera
- Dvir Levy, Research Team Leader, Pentera



