-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Description
Preflight Checklist
- I have searched existing issues for similar behavior reports
- This report does NOT contain sensitive information (API keys, passwords, etc.)
Type of Behavior Issue
Claude modified files I didn't ask it to modify
What You Asked Claude to Do
asked Claude Code CLI to remove git worktrees (variant-a and variant-b) from a pnpm monorepo project on Windows. The worktrees had node_modules installed via pnpm, which uses NTFS junctions and hard links to share packages between workspaces.
What Claude Actually Did
Claude Code should have:
- Detected pnpm node_modules before running any recursive deletion command and warned the user about the NTFS junction risk on Windows.
-
- Used the safe alternative instead of
Remove-Item -Recurse -Force:cmd.exe /c "rmdir /S /Q <path>"— which correctly handles NTFS junctions without following them.
- Used the safe alternative instead of
-
- Or better: Run
git worktree remove <name>which handles cleanup safely, or delete node_modules FIRST using the safe method before removing the worktree.
- Or better: Run
-
- Asked for confirmation before any recursive destructive operation, especially on Windows with pnpm.
-
- Never executed
Remove-Item -Recurse -Forceorrm -rfon directories containing pnpm node_modules on Windows without explicit warning about this known destructive bug.
- Never executed
Expected Behavior
aClaude Code should have recognized the Windows + pnpm + NTFS junction risk and used cmd.exe /c "rmdir /S /Q <path>" instead of Remove-Item -Recurse -Force. Alternatively, it should have run git worktree remove <name> directly, or warned the user and asked for confirmation before any recursive deletion on Windows with pnpm node_modules present.
Files Affected
aPERMANENTLY DELETED (not in Recycle Bin):
- C:\Users\wilbe\Documents\ (entire folder)
- C:\Users\wilbe\Downloads\ (entire folder)
- C:\Users\wilbe\Music\ (entire folder)
- C:\Users\wilbe\Pictures\ (entire folder)
- C:\Users\wilbe\Videos\ (entire folder)
- C:\Users\wilbe\Favorites\ (entire folder)
- WAOK-MONOREPO source code (re-cloned from GitHub, but 2 unpushed commits lost)
- WAOK-LEGACY project (partially deleted)
- 2 unpushed git commits: 14ee8e0 (Variant C) and 2243e22 (commit-msg hook fix)
- All uncommitted working changes (including "blue line" UI work)Permission Mode
Accept Edits was ON (auto-accepting changes)
Can You Reproduce This?
Yes, every time with the same prompt
Steps to Reproduce
- Create a pnpm monorepo on Windows (NTFS)
- Add git worktrees:
git worktree add ./variant-aandgit worktree add ./variant-b -
- Run
pnpm installinside the worktrees (creates NTFS junctions in node_modules)
- Run
-
- Ask Claude Code CLI to remove the worktrees
-
- Claude Code runs
Remove-Item -Recurse -Force ./variant-a(PowerShell) orrm -rf ./variant-a(Git Bash/MSYS)
- Claude Code runs
-
- PowerShell/MSYS follows NTFS junctions → deletes real target directories outside the worktree
-
- Catastrophic data loss occurs silently, bypassing Recycle Bin
See also: Remove-Item -Recurse -Force follows NTFS junctions in node_modules (pnpm), deleting real files outside the target directory — catastrophic data loss PowerShell/PowerShell#26913 (filed as companion issue)
- Catastrophic data loss occurs silently, bypassing Recycle Bin
Claude Model
Sonnet
Relevant Conversation
aClaude Code CLI was asked to clean up / remove git worktrees (variant-a, variant-b) from a pnpm monorepo on Windows. Claude Code executed recursive deletion commands (`Remove-Item -Recurse -Force` in PowerShell and/or `rm -rf` in Git ash/MSYS) without warning about the NTFS junction traversal risk. The AI gave no warning, no confirmation prompt, and no indication that this operation could affect directories outside the target worktree. The deletion silently escaped the target directory via pnpm's NTFS junctions in node_modules and permanently deleted the user's entire Windows profile folders and portions of other projects.Impact
Critical - Data loss or corrupted project
Claude Code Version
Unknown — version not recorded at time of incident (Feb 26, 2026). Latest available at that date.
Platform
Anthropic API
Additional Context
Root cause (known PowerShell bug):
This is a documented bug in PowerShell where Remove-Item -Recurse -Force follows NTFS junctions instead of just removing the junction point. pnpm specifically creates NTFS junctions (not symlinks) in node_modules on Windows, making this combination uniquely dangerous.
Known related issues:
- Fix Remove-Item <symbolic link to directory> PowerShell/PowerShell#621 — patched in PS Core 6+, NOT in Windows PS 5.1
-
- Remove-Item removes the symbolic links and junctions when used with -WhatIf parameter PowerShell/PowerShell#16664 — OPEN, junctions deleted even with -WhatIf
-
-
-
- git clean removes content of symlinks git-for-windows/git#607 — rm -rf in MSYS follows junctions on NTFS
-
-
-
-
-
-
- Companion issue filed: Remove-Item -Recurse -Force follows NTFS junctions in node_modules (pnpm), deleting real files outside the target directory — catastrophic data loss PowerShell/PowerShell#26913
Safe alternative Claude Code should use on Windows:
- Companion issue filed: Remove-Item -Recurse -Force follows NTFS junctions in node_modules (pnpm), deleting real files outside the target directory — catastrophic data loss PowerShell/PowerShell#26913
-
-
-
cmd.exe /c "rmdir /S /Q <path>"
This correctly removes junction points without following them into their targets.
Why this is a Claude Code responsibility:
Claude Code operates as an autonomous coding agent. When it chooses to execute destructive system commands, it must be aware of platform-specific pitfalls. On Windows with pnpm, recursive deletion via PowerShell or Git Bash is a known data-loss vector. Claude Code should either refuse to use these commands in this context, use the safe alternative automatically, or at minimum warn the user and request explicit confirmation before proceeding.