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
- Create a worktree in a Next.js project on Windows
- Install dependencies (
npm install) inside the worktree - Run TypeScript compilation or dev server
- Try to remove the worktree via
git worktree removeorExitWorktree
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
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗