Windows: orphaned worktree agent processes hold directory lock after session ends, blocking folder deletion
Resolved 💬 2 comments Opened Jun 16, 2026 by EricTonin Closed Jun 16, 2026
Summary
When a workflow runs agents with isolation: \"worktree\" on Windows, the child claude.exe processes can survive after the parent session ends. These orphaned processes hold an open handle to the worktree directory, making it impossible to delete the folder through normal means (Explorer, Remove-Item, rd /s /q, robocopy purge all fail with \"file in use\").
Steps to reproduce
- Run a Claude Code workflow that uses
isolation: \"worktree\"agents on Windows - Close or crash the parent session before the workflow fully completes cleanup
- Try to delete the leftover folder under
.claude/worktrees/<name> - Deletion fails with \"the file is being used by another process\"
Environment
- OS: Windows 11 Pro 10.0.26200
- Worktree path was inside OneDrive (may be a contributing factor to cleanup failure)
- Platform: win32
What was observed
- Three
claude.exeprocesses (PIDs 37684, 38628, 37420) started at ~02:23 and were still running at ~12:20 — nearly 10 hours after the session that spawned them - Combined CPU time: ~1097 seconds — they were actively doing work when abandoned, not just idle
/agentsshowed nothing — orphaned processes are invisible to Claude Code's own session-scoped tooling- The only way to discover them was via
Get-Process claude | Sort-Object StartTimein PowerShell - Killing the three processes immediately released the lock and allowed normal deletion
Expected behavior
- Worktree agent processes should terminate and release all handles when the parent session ends or the workflow completes
- If cleanup fails, the folder should be removed automatically (or re-attempted on next startup)
/agents(or a new command) should surface orphanedclaudeprocesses from all sessions, not just the current one
Workaround
# Find orphaned processes (old StartTime compared to current session)
Get-Process claude | Select-Object Id, Name, StartTime, CPU | Sort-Object StartTime
# Kill the old ones, then delete the folder
Stop-Process -Id <orphaned_pids> -Force
Remove-Item -Recurse -Force ".claude\worktrees\<name>"
# Clean up stale git worktree refs
git worktree pruneThis issue has 2 comments on GitHub. Read the full discussion on GitHub ↗