[BUG] rm -rf command deleted parent directory instead of subdirectory, breaking Bash tool

Resolved 💬 3 comments Opened Jan 1, 2026 by jimprince Closed Jan 4, 2026

Description

During a Claude Code session, an rm -rf command targeting a subdirectory appears to have deleted the parent directory instead, causing the Bash tool to enter a broken state where all subsequent commands fail with empty output.

Environment

  • Claude Code Version: 2.0.76
  • OS: macOS Darwin 25.2.0 (Sequoia)
  • Model: claude-opus-4-5-20251101

What Happened

The Command (05:29:43 UTC)

A multi-line command was executed:

rm -rf /path/to/project/apps/myapp/swift-frontend/build/DerivedData-brad
echo "Cleared DerivedData-brad"
make -C /path/to/project/apps/myapp build-brad 2>&1 | tail -10

The cwd at time of execution

/path/to/project/apps/myapp

Result

  1. Output was completely empty - even the echo command produced no output
  2. All subsequent Bash commands failed with "Exit code 1" and empty stdout/stderr
  3. Read tool returned: "File does not exist" for files in the directory
  4. Glob tool confirmed: "Directory does not exist: /path/to/project/apps/myapp"

The entire apps/myapp/ directory was deleted, not just the swift-frontend/build/DerivedData-brad subdirectory.

Timeline from session logs

| Time (UTC) | Event |
|------------|-------|
| 05:29:43 | rm -rf command executed |
| 05:29:49 | Command returns with empty output, is_error: false |
| 05:29:53 | Next make command returns Exit code 1 |
| 05:30:39 | Context compaction |
| 05:30:56 | Read Makefile returns "File does not exist" |
| 05:31:13 | Glob confirms directory does not exist |

Evidence of Bash Tool Broken State

After the rm command, all subsequent commands failed:

Bash(ls -la /path/to/project/apps/myapp/) → Exit code 1
Bash(pwd && ls) → Exit code 1  
Bash(echo "test") → Exit code 1
Glob(pattern="*", path=".../myapp") → "Directory does not exist"

This matches the behavior described in #9190 - when Claude deletes its cwd, the Bash tool breaks completely.

Hypothesis

Based on investigation and related issues (#7255, #9190, #4331, #12637), the path may have been incorrectly parsed during command construction, potentially splitting into two arguments:

rm -rf /path/to/project/apps/myapp /swift-frontend/build/DerivedData-brad

This would explain:

  • Why the parent directory (cwd) was deleted
  • Why the Bash tool immediately entered a broken state
  • Why output was completely empty

Impact

  • Data loss: Uncommitted work in the directory was lost
  • Recovery required: Had to use git checkout HEAD -- to restore (which also lost uncommitted changes)

Related Issues

  • #9190 - Bash tool breaks if claude rm's the current pwd
  • #7255 - Dangerous rm Command Execution with Unintended Path Parsing
  • #4331 - Claude Code deleted the directory on which it worked
  • #12637 - Unsafe rm command execution deletes entire home directory

Suggested Mitigations

  1. Validate rm -rf target paths before execution
  2. Detect and warn if rm target is parent of or equal to cwd
  3. Add safeguards against path parsing issues in multi-line commands
  4. Consider #12489 suggestion to intercept all rm commands

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗