Worktree removal fails — file locks prevent cleanup on Windows

Resolved 💬 2 comments Opened Apr 1, 2026 by vlastimilvajnorak Closed May 6, 2026

When a worktree is created (either via EnterWorktree or manually), Claude Code cannot remove it at the end of a session because Node.js processes (likely node_modules or dev servers inside the worktree) hold file locks.

Steps to reproduce

  1. Create a worktree in a Next.js project on Windows
  2. Install dependencies (npm install) inside the worktree
  3. Run TypeScript compilation or dev server
  4. Try to remove the worktree via git worktree remove or ExitWorktree

Error

rm: cannot remove '.claude/worktrees/relaxed-mirzakhani/apps/site': Device or resource busy

git worktree remove also fails with Permission denied.

Expected behavior

Claude Code should release all file handles and kill child processes scoped to the worktree before attempting removal.

Environment

  • OS: Windows
  • Shell: Git Bash
  • Project: Next.js with npm workspaces
  • Claude Code: latest

View original on GitHub ↗

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