Skip to content

[Bug] cmux rm fails on Windows when node_modules holds transient file locks #24

Description

@jeremylasne92-hue

Summary

On Windows (Git Bash / MSYS), cmux rm <branch> and cmux rm <branch> --force frequently fail with Directory not empty or a permission error when the worktree contains a populated node_modules/. Manually retrying the same cmux rm 1-2 seconds later succeeds. Filesystem-level cleanup with PowerShell Remove-Item -Recurse -Force also succeeds immediately.

Environment

  • OS: Windows 11
  • Shell: Git Bash (MSYS2 / MINGW64), bash 5.2.37
  • Git: 2.52.0.windows.1
  • cmux: 0.1.4

Reproduction

cd /c/some/git/repo
cmux new feature-x         # worktree created, .cmux/setup runs npm install
cmux rm feature-x -f       # ❌ "Failed to remove worktree: feature-x"
                           # error: failed to delete '.../.worktrees/feature-x': Directory not empty
sleep 2
cmux rm feature-x -f       # ✅ succeeds

The branch is removed during the first attempt (because git worktree remove partially completes before the directory deletion fails), so the second cmux rm reports "Worktree not found" — but the orphan directory still consumes disk space (often 1-2GB for a Node.js project).

Root cause

Windows holds short-lived file handles on files inside node_modules after node processes exit (build watchers, esbuild, vitest, etc.). git worktree remove does its directory-cleanup pass while the lock is still held → fails. The lock clears within a second or two but cmux doesn't retry.

Proposed fix

Retry git worktree remove up to 3 times with a 1-second backoff on MSYS/MinGW/Cygwin shells. Linux/macOS behavior is unchanged.

PR: #PR (link below once opened)

Related

This is a separate issue from #22 (path-format mismatch). Both are Windows-specific but independent root causes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions