Skip to content

[BUG] Critical Bug: Claude Code executed 'rm -rf' and deleted project files unexpectedly #29082

Closed as not planned

Description

@cfireboy

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

Image

While using Claude Code for Flutter development, the AI agent executed an unauthorized rm -rf command which deleted my project directory smart_drive_log.
Evidence: Claude has admitted this was an operational error (Quote: "It was caused by Claude's operational error, not by you.").
Impact: Loss of development time and potential code loss within my daily/weekly usage limits.
Request: I would like to report this critical safety issue and inquire about potential compensation for the wasted usage limits/credits.

What Should Happen?

Permission Check: Claude should never execute destructive commands like rm -rf without explicit user confirmation.

Context Awareness: The agent should distinguish between temporary build artifacts (like build/ in Flutter) and essential source code directories (like smart_drive_log).

Error Recovery: If a file deletion is necessary for a task, Claude should suggest moving it to a backup directory or the system trash instead of permanent deletion.

Quota Protection: Since this operational error wasted my limited daily/weekly usage and 5-hour development window, there should be a mechanism to report such failures and restore usage limits.

Error Messages/Logs

Verified smart_drive_log directory exists but is empty
Verified smart_drive_log directory exists but is empty
Bash
rm -rf /c/Users/BlairChiu/.gradle/daemon/8.14/ && TEMP="C:/Users/BlairChiu/tmp" TMP="C:/Users/BlairChiu/tmp" flutter build apk --release --no-android-gradle-daemon-jvm-args 2>&1 | head -5 # Try without extra flag TEMP="C:/Users/BlairChiu/tmp" TMP="C:/Users/BlairChiu/tmp" cd /c/Users/BlairChiu/StudioProjects/smart_drive_log && TEMP="C:/Users/BlairChiu/tmp" TMP="C:/Users/BlairChiu/tmp" flutter build apk --release 2>&1 | tee /c/Users/BlairChiu/build_temp_fix.txt; echo "Exit: $?"
Could not find an option named "--no-android-gradle-daemon-jvm-args".
Run 'flutter -h' (or 'flutter <command> -h') for available flutter commands and options.
Bash
rm -rf /c/Users/BlairChiu/.gradle/daemon/8.14/ cd /c/Users/BlairChiu/StudioProjects/smart_drive_log && TEMP="C:/Users/BlairChiu/tmp" TMP="C:/Users/BlairChiu/tmp" flutter build apk --release 2>&1 | tee /c/Users/BlairChiu/build_temp_fix.txt echo "Exit: $?"
Exit code 1
rm: cannot remove '/c/Users/BlairChiu/StudioProjects/smart_drive_log': Device or resource busy
Show more
Bash
rm -rf /c/Users/BlairChiu/.gradle/daemon/8.14/ && cd /c/Users/BlairChiu/StudioProjects/smart_drive_log && TEMP="C:/Users/BlairChiu/tmp" TMP="C:/Users/BlairChiu/tmp" flutter build apk --release 2>&1 | tee /c/Users/BlairChiu/build_temp_fix.txt; echo "Exit: $?"
Error: No pubspec.yaml file found.
This command should be run from the root of your Flutter project.
Exit:
Bash
rm -rf /c/Users/BlairChiu/.gradle/daemon/ 2>/dev/null; echo "cleared"
cleared
Bash
TEMP="C:/Users/BlairChiu/tmp" TMP="C:/Users/BlairChiu/tmp" flutter build apk --release 2>&1 | tee /c/Users/BlairChiu/build_temp_fix.txt; echo "Exit: $?"
Error: No pubspec.yaml file found.
This command should be run from the root of your Flutter project.
Exit:
Bash
pwd
/c/Users/BlairChiu/StudioProjects/smart_drive_log
Bash
ls
Bash
ls /c/Users/BlairChiu/StudioProjects/smart_drive_log/ | head -10
Bash
ls /c/Users/BlairChiu/StudioProjects/
08_smart_drive_log_bak.lnk
flutter_analyze_output.txt
nul
Show more
Glob
pubspec.yaml
No files found
Bash
find /c/Users/BlairChiu/StudioProjects/smart_drive_log -name "pubspec.yaml" 2>/dev/null | head -5
Bash
find /c/Users/BlairChiu/StudioProjects -name "pubspec.yaml" 2>/dev/null | head -5
/c/Users/BlairChiu/StudioProjects/智能雲端行車里程紀錄助手 (Smart Drive Log)/01_30/02_第2天任務_OK/pubspec.yaml
/c/Users/BlairChiu/StudioProjects/智能雲端行車里程紀錄助手 (Smart Drive Log)/31_40/32_All_v1/pubspec.yaml
Bash
ls -la "/c/Users/BlairChiu/StudioProjects/smart_drive_log" 2>&1 | head -20
total 8
drwxr-xr-x 1 BlairChiu 197121 0 Feb 27 01:53 .
drwxr-xr-x 1 BlairChiu 197121 0 Feb 25 00:31 ..

Steps to Reproduce

Steps to Reproduce
*
Please provide clear, numbered steps that anyone can follow to reproduce the issue. Important: Include any necessary code, file contents, or context needed to reproduce the bug. If the issue involves specific files or code, please create a minimal example.

Claude Model

Sonnet (default)

Is this a regression?

Yes, this worked in a previous version

Last Working Version

No response

Claude Code Version

Claude 1.1.4328 (d8e391) 2026-02-25T17:04:36.000Z

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

Windows Terminal

Additional Information

Image

Verified smart_drive_log directory exists but is empty
Verified smart_drive_log directory exists but is empty
Bash
rm -rf /c/Users/BlairChiu/.gradle/daemon/8.14/ && TEMP="C:/Users/BlairChiu/tmp" TMP="C:/Users/BlairChiu/tmp" flutter build apk --release --no-android-gradle-daemon-jvm-args 2>&1 | head -5 # Try without extra flag TEMP="C:/Users/BlairChiu/tmp" TMP="C:/Users/BlairChiu/tmp" cd /c/Users/BlairChiu/StudioProjects/smart_drive_log && TEMP="C:/Users/BlairChiu/tmp" TMP="C:/Users/BlairChiu/tmp" flutter build apk --release 2>&1 | tee /c/Users/BlairChiu/build_temp_fix.txt; echo "Exit: $?"
Could not find an option named "--no-android-gradle-daemon-jvm-args".
Run 'flutter -h' (or 'flutter -h') for available flutter commands and options.
Bash
rm -rf /c/Users/BlairChiu/.gradle/daemon/8.14/ cd /c/Users/BlairChiu/StudioProjects/smart_drive_log && TEMP="C:/Users/BlairChiu/tmp" TMP="C:/Users/BlairChiu/tmp" flutter build apk --release 2>&1 | tee /c/Users/BlairChiu/build_temp_fix.txt echo "Exit: $?"
Exit code 1
rm: cannot remove '/c/Users/BlairChiu/StudioProjects/smart_drive_log': Device or resource busy
Show more
Bash
rm -rf /c/Users/BlairChiu/.gradle/daemon/8.14/ && cd /c/Users/BlairChiu/StudioProjects/smart_drive_log && TEMP="C:/Users/BlairChiu/tmp" TMP="C:/Users/BlairChiu/tmp" flutter build apk --release 2>&1 | tee /c/Users/BlairChiu/build_temp_fix.txt; echo "Exit: $?"
Error: No pubspec.yaml file found.
This command should be run from the root of your Flutter project.
Exit:
Bash
rm -rf /c/Users/BlairChiu/.gradle/daemon/ 2>/dev/null; echo "cleared"
cleared
Bash
TEMP="C:/Users/BlairChiu/tmp" TMP="C:/Users/BlairChiu/tmp" flutter build apk --release 2>&1 | tee /c/Users/BlairChiu/build_temp_fix.txt; echo "Exit: $?"
Error: No pubspec.yaml file found.
This command should be run from the root of your Flutter project.
Exit:
Bash
pwd
/c/Users/BlairChiu/StudioProjects/smart_drive_log
Bash
ls
Bash
ls /c/Users/BlairChiu/StudioProjects/smart_drive_log/ | head -10
Bash
ls /c/Users/BlairChiu/StudioProjects/
08_smart_drive_log_bak.lnk
flutter_analyze_output.txt
nul
Show more
Glob
pubspec.yaml
No files found
Bash
find /c/Users/BlairChiu/StudioProjects/smart_drive_log -name "pubspec.yaml" 2>/dev/null | head -5
Bash
find /c/Users/BlairChiu/StudioProjects -name "pubspec.yaml" 2>/dev/null | head -5
/c/Users/BlairChiu/StudioProjects/智能雲端行車里程紀錄助手 (Smart Drive Log)/01_30/02_第2天任務_OK/pubspec.yaml
/c/Users/BlairChiu/StudioProjects/智能雲端行車里程紀錄助手 (Smart Drive Log)/31_40/32_All_v1/pubspec.yaml
Bash
ls -la "/c/Users/BlairChiu/StudioProjects/smart_drive_log" 2>&1 | head -20
total 8
drwxr-xr-x 1 BlairChiu 197121 0 Feb 27 01:53 .
drwxr-xr-x 1 BlairChiu 197121 0 Feb 25 00:31 ..
Show less

緊急情況! smart_drive_log 目錄是空的!讓我立即檢查發生了什麼:

Activity

  1. github-actions commented on Feb 26, 2026

    @github-actions

    Found 3 possible duplicate issues:

    1. Bash tool: newline characters in command string treated as spaces, causing rm -rf to delete unintended directories #24319
    2. [BUG] rm -rf on single subdirectory deleted entire parent directory contents #21217
    3. [BUG] Claude Code v2.1.58 deleted entire Windows user profile (C:\Users\msafa) - CRITICAL DATA LOSS #29023

    This issue will be automatically closed as a duplicate in 3 days.

    • If your issue is a duplicate, please close it and 👍 the existing issue instead
    • To prevent auto-closure, add a comment or 👎 this comment

    🤖 Generated with Claude Code

  2. cfireboy commented on Feb 27, 2026

    @cfireboy
    Author

    Wait, this is NOT a simple duplicate.

    While it shares similarities with #24319 and #29023, my case specifically involves a Flutter project structure where the agent failed to distinguish between temporary build logs and the core source directory smart_drive_log.

    This incident resulted in actual production code loss and exhausted my daily/weekly Pro usage limits while I attempted to recover the environment. I am keeping this issue open to track the recovery of my usage credits and to ensure the development team addresses the specific guardrail failure in Flutter/Dart project contexts.

    👎 (Adding this to prevent auto-closure)

  3. panchito05 commented on Feb 27, 2026

    @panchito05

    Related incident — same root cause pattern

    Linking this to a cluster of related issues all involving Claude Code executing destructive deletion commands on Windows:

    Same-day incident (Feb 26, 2026): Claude Code CLI deleted my entire C:\Users\wilbe\ standard folders (Documents, Downloads, Music, Pictures, Videos, Favorites) while removing git worktrees from a pnpm monorepo. The mechanism: pnpm creates NTFS junctions in node_modules, and Remove-Item -Recurse -Force / rm -rf follows those junctions into their real targets outside the worktree directory.

    Cluster of related issues:

    # DANGEROUS — follows NTFS junctions:
    Remove-Item -Recurse -Force <path>
    
    # SAFE — removes junction points correctly:
    cmd.exe /c "rmdir /S /Q <path>"

    Claude Code needs to detect Windows + pnpm node_modules and use the safe alternative, or at minimum warn and require confirmation before any recursive deletion.

  4. panchito05 commented on Feb 28, 2026

    @panchito05

    🚨 UPDATE — Feb 28, 2026: Anthropic banned my account the day after I filed my reports

    Updating this thread as an affected user (see my previous comment above).

    The day after I filed my reports (issue #29249, HackerOne VDP, and comments here), Anthropic suspended and revoked my Claude account — citing only a vague "violation of Usage Policy" with no specific explanation.

    Timeline:

    I have filed a formal appeal and am demanding a full explanation from Anthropic's Safeguards Team.

    Full incident documentation: https://gist.github.com/panchito05/95f3b8feb401ad230bded40981132628
    My report: #29249

  5. stevenelliottjr commented on Mar 3, 2026

    @stevenelliottjr

    Submitted a plugin to help with this: #30261 — a PreToolUse hook that blocks destructive commands (rm -rf, git reset --hard, DROP TABLE, etc.) before execution. Includes smart allowlisting for safe operations like build artifact cleanup.

  6. yurukusa commented on Mar 29, 2026

    @yurukusa

    You can prevent this with a PreToolUse hook that blocks rm -rf unconditionally:

    INPUT=$(cat)
    COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty' 2>/dev/null)
    [ -z "$COMMAND" ] && exit 0
    if echo "$COMMAND" | grep -qE 'rm\s+(-[a-z]*r[a-z]*f|--recursive\s+--force|-[a-z]*f[a-z]*r)'; then
        echo "BLOCKED: rm -rf is permanently disabled by safety hook." >&2
        echo "Use 'mv' to a temp directory or 'trash-cli' instead." >&2
        exit 2
    fi
    if echo "$COMMAND" | grep -qE 'find\s+.*-delete'; then
        echo "BLOCKED: find -delete is disabled by safety hook." >&2
        exit 2
    fi
    exit 0
    {
      "hooks": {
        "PreToolUse": [{
          "matcher": "Bash",
          "hooks": [{ "type": "command", "command": "bash ~/.claude/hooks/banned-command-guard.sh" }]
        }]
      }
    }

    exit 2 blocks the command before bash runs — Claude can't bypass it. This would have prevented the unauthorized rm -rf that deleted your project.

  7. alemarcosa commented on Apr 2, 2026

    @alemarcosa

    This is the fundamental gap in the current approval architecture — the safety boundary lives inside the agent runtime, which means it can be bypassed by prompt behavior or bugs. The correct interception point is between the model response and the agent execution, before the tool call is delivered to the runtime. I built Daedalab (daedalab.app) as a proxy layer that does exactly this: destructive calls like rm -rf get blocked at the protocol level and require out-of-band approval before the agent receives them. Works with Claude Code via API key + base URL config. Happy to share more on the architecture if useful for this issue.

  8. github-actions commented on May 10, 2026

    @github-actions

    Closing for now — inactive for too long. Please open a new issue if this is still relevant.

  9. github-actions commented on Jun 30, 2026

    @github-actions

    This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

  10. locked as resolved and limited conversation to collaborators on Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions