AIToday

AI agents accidentally deleting user files—a pattern of state confusion

Hacker News6h ago
AI agents accidentally deleting user files—a pattern of state confusion

Key takeaway

AI coding assistants Claude Code and OpenAI's GPT-5.6 have caused accidental deletion of user files, databases, and photos in multiple incidents because the models misunderstand the state of files, directories, and variables—then execute irreversible commands like rm -rf on the wrong target. The root issue is not malice or prompt injection, but confusion about what a command will actually do; as AI agents with terminal access have become core products, the human cost of these mistakes has shifted from minor data corruption to permanent loss.

Summaries like this, in your inbox every morning.

Sign up free →

3 Key Points

  • What happened

    Claude Code and OpenAI's GPT-5.6 have caused multiple reported incidents of accidental file and database deletion. OpenAI's Thibault Sottiaux confirmed the issue occurs when full access mode is enabled without sandboxing, and the model mistakes directories (e.g., confusing $HOME with a temporary directory). Specific cases include a user losing nearly all Mac files (July 11, 2026), another losing a production database after 14+ hours of autonomous execution (July 14, 2026), and a Claude user losing 15 years of photos when the agent mishandled case-insensitive folder names (February 7, 2026).

  • Why it matters

    These are not exfiltration attacks or prompt injection—the AI agents are simply making honest mistakes about the state of files, directories, and variables, then executing irreversible destructive commands. As AI agents with terminal access have become flagship products (Claude Code launched in February 2025), the stakes of a misunderstanding have shifted from corrupted output to permanent data loss. The pattern suggests the risk of undermining user interests through clumsiness may deserve as much attention as intentional security breaches.

  • What to watch

    The article identifies the root cause as missing affordances—safer, scoped tools for common operations (temporary files, database branching, cut/paste refactoring) that reduce the distance between user intent and destructive primitives. Projects like destructive_command_guard (over 5k GitHub stars) aim to intercept dangerous commands; the article also advocates for backups and versioned folder schemas (e.g., Documents/work/2026-01/file.js) as immediate mitigations.

In Depth

On July 16, 2026, Thibault Sottiaux, who works on the Codex harness at OpenAI, posted findings from an investigation into reports of unexpected file deletions by GPT-5.6. The most common scenario occurs when full access mode is enabled without sandboxing protections or auto-review, the model attempts to override the $HOME environment variable to define a temporary directory, and mistakenly deletes $HOME itself instead.

The article documents a series of high-impact incidents. On July 11, 2026, user mattschumer_ reported that GPT-5.6-Sol accidentally deleted almost all files on their Mac. The agent had run a cleanup command that incorrectly expanded $HOME and executed rm -rf /Users/mattsdevbox—the user killed the process but material deletion had occurred. The same day, cremieuxrecueil encountered a similar cleanup problem: a PowerShell command treated an -Include filter unexpectedly and removed compiled paper files. On July 14, brunolemos reported that GPT-5.6 Sol deleted their entire production database after 14 hours and 35 minutes of autonomous execution. The agent had incorrectly pointed the TEST_DATABASE_URL environment variable to the production Neon database URL and then executed integration tests that included destructive setup commands such as TRUNCATE TABLE users CASCADE and explicit deletion of the users table.

Incidents predate the recent surge. In April 2026, peter_szilagyi asked Claude Code to isolate a 3-line fix into a new branch; Claude stashed changes, switched branches, and attempted to restore them with git stash pop, but then discarded uncommitted changes with git checkout --, immediately overwriting the restored work. On February 7, 2026, Nick_Davidov asked Claude Cowork to organize his wife's desktop and granted permission to delete temporary office files. The agent attempted to rename and accidentally deleted a folder containing all photos taken on her camera for 15 years. Claude Opus 4.6 explained: while merging a lowercase "photos" folder with a new "Photos" folder, it did not account for macOS's case-insensitive file system, where both names point to the same folder, and ran rm -rf on what it thought was a separate empty folder.

The author describes a personal incident from April 14, 2026: when asked to move inline HTML from a TypeScript file to separate HTML files, Sonnet 4.6 proposed using a Python script with a regular expression to match and delete the original lines. The regex pattern included a closing group for }, whitespace, ], }, and );—but one code block ended with an extra comma, causing the pattern to not match until far further down the file, swallowing hundreds of lines of code that neither the agent nor the user noticed until the change appeared on GitHub.

The article identifies a through-line: confusion about state. The $HOME variable did not address the intended directory; PowerShell's -Include parameter behaved unexpectedly; the DATABASE_URL pointed to production, not test; git checkout after stash pop did not preserve work; macOS treats capitalization-variant folder names as identical; and the regex did not match intended boundaries. Agents often reach for power-user techniques—chained commands like git stash && git checkout, environment variable overloads, regex-based substitution—that are valid but require tracking implicit state. This conflicts with other training goals: without a calculator tool, LLMs often overconfidently estimate arithmetic; without a provided key-value store for custom variables, agents cannot safely store task state; without standard temporary-file creation, cleanup is always arbitrary.

The article notes that Claude Code launched in February 2025 and became a revenue driver, normalizing "agent with command line access" as a flagship product. Mitigations involve trade-offs between constraints and convenience, but several concrete proposals emerge: destructive_command_guard, a high-performance hook intercepting destructive commands before execution (over 5k GitHub stars); Git worktrees to isolate tasks into separate directories; backups and versioned folder schemas (e.g., Documents/work/2026-01/myfile.js); and safer, scoped operations built into the harness itself—a key-value store for custom variables, a standard temporary-file API, database branching via Neon, and a tool to move character ranges as blocks rather than requiring regex surgery. These would not eliminate mistakes but would reduce the distance between what the user intended and the destructive primitive the agent eventually executes.

Context & Analysis

The incidents catalogued in this article reveal a consistent failure mode: AI agents confuse the actual state of a file system or environment variable with what they believe it to be, then execute a destructive command irreversibly. In the most dramatic case, a user ran a GPT-5.6 agent for over 14 hours pursuing a goal (finish implementation, including app UI, server); the agent had accidentally pointed a test database URL to the production database URL, then executed TRUNCATE TABLE and DELETE commands during test setup. In another, Claude Cowork attempted to merge two folders with names differing only in capitalization—a distinction the agent did not realize macOS ignores—and deleted 15 years of photos. OpenAI's Thibault Sottiaux confirmed the pattern on July 16, 2026: the issue occurs most commonly when full access mode is enabled without sandboxing protections, the model attempts to override $HOME to define a temporary directory, and makes an honest mistake.

These are not attacks; they are failures of comprehension. The article notes that security research has historically focused on exfiltration via prompt injection, where an agent leaks secrets through a confused deputy attack. In practice, however, state confusion leading to accidental destruction appears far more common. The underlying cause is missing affordances: AI agents reach for power-user techniques (chained shell commands, regex-based code surgery, environment variable overloads) because no safer, scoped alternative exists for common tasks like temporary file creation, database branching, or block-based code movement. The article argues that as Claude Code (launched February 2025) and similar tools have become flagship revenue products with full terminal access, the human cost of a mistake has shifted from minor corruption to permanent loss. Mitigations proposed include backups, projects like destructive_command_guard (which intercepts dangerous commands before execution), and redesigned harnesses that offer safer alternatives for routine operations.

FAQ

What caused these file deletions?
The AI agents misunderstood the state of directories, environment variables, or file system rules. For example, one agent tried to override $HOME to create a temporary directory but accidentally deleted $HOME itself; another did not account for macOS treating 'photos' and 'Photos' as the same folder and deleted the wrong one with rm -rf.
Which models and products were involved?
OpenAI's GPT-5.6 (in Codex), Claude Code from Anthropic, and Claude Opus 4.6. The incidents span from February 2026 (Claude Cowork) through July 2026 (GPT-5.6).
What mitigations does the article suggest?
The article recommends: backups and versioned folder schemas (e.g., Documents/work/2026-01/file.js), tools like destructive_command_guard (which intercepts dangerous commands), Git worktrees (to isolate tasks), and safer built-in tools for agents to perform common operations (temporary file creation, database branching, cut/paste refactoring) instead of chaining raw shell commands.

Get the latest AI Coding Assistants news every morning

AI-summarized, only the topics you pick — one digest a day via Email, Slack, or Discord.

Free · takes 30 seconds · unsubscribe anytime

Discussion

No comments yet. Be the first to share your thoughts!

Log in to join the discussion

Related Articles

Stay ahead with AI news

Get curated AI news from 200+ sources delivered daily to your inbox. Free to use.

Get Started Free

Free · takes 30 seconds · unsubscribe anytime

1 minute a day. The AI essentials.

200+ sources · Email / LINE / Slack

Get it free →