Skip to content

[MODEL] Claude Code CLI executed Remove-Item -Recurse -Force on pnpm worktrees, triggering catastrophic NTFS junction traversal — permanent deletion of user profile folders and source code #29249

@panchito05

Description

@panchito05

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:

  1. Detected pnpm node_modules before running any recursive deletion command and warned the user about the NTFS junction risk on Windows.
    1. 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.
    1. Or better: Run git worktree remove <name> which handles cleanup safely, or delete node_modules FIRST using the safe method before removing the worktree.
    1. Asked for confirmation before any recursive destructive operation, especially on Windows with pnpm.
    1. Never executed Remove-Item -Recurse -Force or rm -rf on directories containing pnpm node_modules on Windows without explicit warning about this known destructive bug.

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

  1. Create a pnpm monorepo on Windows (NTFS)
  2. Add git worktrees: git worktree add ./variant-a and git worktree add ./variant-b
    1. Run pnpm install inside the worktrees (creates NTFS junctions in node_modules)
    1. Ask Claude Code CLI to remove the worktrees
    1. Claude Code runs Remove-Item -Recurse -Force ./variant-a (PowerShell) or rm -rf ./variant-a (Git Bash/MSYS)
    1. PowerShell/MSYS follows NTFS junctions → deletes real target directories outside the worktree
    1. 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)

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions