Claude Code's -w -p mode leaves the worktree lock held after it exits
11/30/2026
Passing -w (--worktree) to Claude Code creates a git worktree inside the repository to isolate the work, while -p is used for unattended one-shot runs. The author found that when the two are combined, the worktree lock is still held after the task finishes, which blocks later cleanup or removal. As a result, each run leaves behind a worktree that cannot be cleaned up. The author suggests using a script to release only the locks held by PIDs that have already exited, then cleaning up with git worktree remove or prune.