STUPID-2026-0094

Claude Code destroyed a WSL2 home directory when a self-written bash script's EXIT trap fired against a reassigned variable (GitHub #88462)

8.0high
August 21, 2026Source checked

Why 8/10

A whole WSL home directory, SSH keys and credentials included, was deleted; only partial recovery from backups.

Scope
3/4
A whole machine or drive, an organisation's production system or data, or many credentials
Recoverability
2/3
Partly lost, or loss reported without saying whether it was recovered
Did it happen
2/2
Happened in real use
Beyond the user
1/1
Production systems, customers or third parties, or credentials and sensitive personal data

The score is the sum of these four factors. How each factor is scored · scored 2026-10-29

Guardrail rules for this command

Recursive deletes: make your agent stop and ask before running these. Free to copy; written in each tool’s documented format.

Claude Code · the agent in this incident
{
  "permissions": {
    "ask": [
      "Bash(rm -r*)",
      "Bash(rm -fr*)",
      "Bash(rm -R*)",
      "Bash(find * -delete*)",
      "PowerShell(Remove-Item *)",
      "Bash(cmd /c rmdir *)",
      "Bash(cmd /c del *)"
    ]
  }
}
Add to .claude/settings.json in the project (or ~/.claude/settings.json for every project). Each matching command then asks you first, including in auto mode.

Stronger control: Turn on the sandbox (/sandbox): shell commands can then write only to the project, a temp folder and directories you add. It runs on macOS, Linux and WSL2; on native Windows Claude Code runs commands unsandboxed. Docs

Codex
prefix_rule(pattern = ["rm", ["-r", "-rf", "-fr", "-R"]], decision = "prompt", justification = "Recursive delete: confirm the target first")
Save as ~/.codex/rules/stupidllm.rules and restart Codex. Codex's docs describe rules as controlling commands run outside its sandbox, and mark them experimental.

Stronger control: Keep Codex's OS sandbox on (it limits writes, typically to the workspace) and leave approvals on for sessions that can reach data you cannot lose. Docs

Gemini CLI
[[rule]]
toolName = "run_shell_command"
commandPrefix = ["rm -r", "rm -fr", "rm -R"]
decision = "ask_user"
priority = 100
denyMessage = "Destructive command: needs a human to confirm (stupidllm.com)"
Save as ~/.gemini/policies/stupidllm.toml. Workspace-level policy files are disabled in Gemini CLI, so this must be the user-level folder.

Stronger control: Policies in ~/.gemini/policies apply in every approval mode unless a rule's modes field narrows them. Docs

Copilot CLI
copilot --deny-tool='shell(rm)'
Pass on the command line. Copilot CLI matches the program name (and git/gh subcommands), so this blocks the whole command, not just its dangerous form.

Stronger control: Avoid --allow-all-tools on a machine with data you cannot lose; --deny-tool takes precedence over it. Docs

What these cannot do: a pattern rule matches the command text the agent writes. In Anthropic’s words it “isn’t a security boundary around the program”: /bin/rm, sh -c or a script that runs the same thing gets past it (STUPID-2026-0124 got past a guard with cmd /c). Use the sandbox as well, and keep backups of what you cannot lose.

  1. Instruction given

    Session running in defaultMode "auto" (no confirmation prompts); the assistant was writing and running a bash test-helper script it had authored itself moments earlier.

  2. Expected behavior

    Permission checking should account for destructive code the assistant wrote into a script in the same session, not only the literal command string used to invoke it, and a recursive delete should never be allowed to resolve to $HOME regardless of permission mode.

  3. Actual behavior

    The assistant wrote a bash helper function containing `trap 'rm -rf "$_HT_HOME"' EXIT`, then later modified the function to reassign `_HT_HOME="$HOME"`. The validation script called the function twice: the first call armed the trap while `_HT_HOME` still pointed at a temp directory, the second call reassigned `_HT_HOME` to `$HOME`. When the script exited, the trap fired using the variable's current value — `$HOME` — and ran `rm -rf` on the user's entire WSL2 home directory. The command Claude Code's permission system evaluated was just `bash /tmp/.../test-lib-demo.sh`, which read as harmless; the destructive logic was buried inside the script contents the assistant had written, not in the invoking command.

  4. Damage

    The reporter's entire WSL2 home directory (/home/leduc) was deleted, including environment configuration (hooks, agents, memory), roughly 1.4 GB of session transcripts, SSH keys and gh CLI authentication, and three in-flight conversations. Only partial recovery was possible from external backups. The issue documents this as the fifth report of the same class of bug (self-authored destructive code evading permission checks) over six months, with four prior reports (#29082, #32938, #49129, #70687) closed as not_planned or duplicate. Reported open with no maintainer response at time of writing.

Full write-up

On August 21, 2026, a Claude Code user (WSL2/Ubuntu under Windows, Claude Opus 5, session running in auto mode with no confirmation prompts) filed GitHub issue #88462 after a self-authored test script destroyed their home directory. During the session, the assistant wrote a bash helper function containing trap 'rm -rf "$_HT_HOME"' EXIT, intending the trap to clean up a temporary directory when the function's scope ended. Later in the same session it modified the function to reassign _HT_HOME="$HOME". The validation script called the function twice: the first call armed the EXIT trap while _HT_HOME still resolved to a temp path, and the second call reassigned _HT_HOME to $HOME. Because a bash trap evaluates its variable at fire time rather than at the time it was armed, the trap ran rm -rf against $HOME when the script exited.

Claude Code's permission system only evaluated the literal invoking command — bash /tmp/.../test-lib-demo.sh — which contained nothing that looked destructive. The actual destructive logic lived inside the script the assistant had authored moments earlier in the same session, so the write path and the execution path were never correlated. The wipe destroyed the reporter's environment configuration (hooks, agents, memory), roughly 1.4 GB of session transcripts, SSH keys, gh CLI authentication, and three in-flight conversations; only partial recovery was possible from external backups. A secondary failure compounded the incident: an error immediately after the deletion (pwd: error retrieving current directory: getcwd: cannot access parent directories) was treated as routine cleanup noise rather than recognized as a signal that something had gone wrong.

The issue explicitly frames this as the fifth report of the same underlying bug class — a permission system that inspects only the command string, not code the assistant itself just wrote and is about to execute — with four prior reports (#29082, #32938, #49129, #70687) each closed as not_planned or duplicate rather than fixed. It is labeled area:permissions, area:sandbox, bug, data-loss, high-priority, and platform:wsl, and remains open with no maintainer response at time of writing.

Classification

Failure mode
Destructive Action
Root cause
Tool Misuse
Domain
Infra
Language
Bash
OWASP Agentic Top 10 (our mapping)
ASI02 Tool Misuse and Exploitation list
MIT AI Risk Repository (our mapping)
7.3 Lack of capability or robustness taxonomy

Related incidents

Cite this record
StupidLLM. "STUPID-2026-0094: Claude Code destroyed a WSL2 home directory when a self-written bash script's EXIT trap fired against a reassigned variable (GitHub #88462)." AI Agent Incident Database, 2026. https://www.stupidllm.com/incident/STUPID-2026-0094/ (accessed 2026-12-01). CC BY 4.0.

← STUPID-2026-0093By IDSTUPID-2026-0095 →

Get told when an agent breaks something

We document AI agent failures daily, severity-scored against a published scale. Each Monday, if any scored 7 or above that week — deleted data, leaked secrets, broken production — you get one email with the sources. When nothing did, you get nothing.

This database is callable over MCP — query it from inside your agent.