Speed up Windows worktree deletion
Summary
- Reuse the already-authoritative worktree record in the local delete IPC path instead of relisting all repo worktrees during removal.
- Remove the unconditional
git worktree prune+ post-prune relist from local and SSH worktree deletion. - Keep branch safety by letting
git branch -d/-Dreject live checkouts, and only prune/retry when Git reports the branch is checked out via worktree metadata.
Measurement
Windows 11 / git version 2.54.0.windows.1 synthetic repo, 80 sibling worktrees, 10 tracked files; each run created and deleted fresh target worktrees.
- Old sequence average: 810.5 ms (runs: 801.1, 841.4, 801.5, 836.3, 772.0)
- Patched sequence average: 447.8 ms (runs: 433.5, 456.5, 430.6, 434.3, 484.0)
- Improvement: 44.7% faster
Verification
pnpm vitest run --config config/vitest.config.ts src/main/git/worktree.test.ts src/relay/git-handler-worktree-ops.test.ts src/relay/git-handler-worktree-paths.test.ts src/relay/git-handler-branch-cleanup.test.tspnpm run typecheck:nodepnpm exec oxlint src/main/git/worktree.ts src/main/ipc/worktrees.ts src/relay/git-handler-worktree-ops.ts src/main/git/worktree.test.ts src/relay/git-handler-worktree-ops.test.ts src/relay/git-handler-worktree-paths.test.ts src/relay/git-handler-branch-cleanup.test.ts
Ready to review this PR? Stage has broken it down into 5 individual chapters for you:
Chapters generated by Stage for commit 1df1a85103f70a12021308e32e3591ffbcf4a5b5 on Jun 16, 2026 7:37am UTC.
📝 Walkthrough
Walkthrough
The PR replaces an unconditional "prune then relist" guard before branch deletion in both the main-process removeWorktree function and the relay removeWorktreeOp handler. Both paths now attempt branch deletion first, detect the specific "branch checked out in worktree" error via a new isBranchCheckedOutInWorktreeError predicate, run git worktree prune only on that failure, and retry deletion once. A new exported RemoveWorktreeOptions type adds an optional knownRemovedWorktree field so callers can supply already-known worktree metadata and skip an extra listWorktrees call; the IPC layer is updated to pass this hint. Test files across both layers are updated to reflect the new call sequences and add coverage for the prune-and-retry and known-worktree-reuse paths.
🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (2 warnings)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Description check | ⚠️ Warning | The description is largely incomplete, missing most required template sections including Screenshots, Testing checklist, AI Review Report with cross-platform verification, and Security Audit. | Add Screenshots section, complete Testing checklist with verification results, add comprehensive AI Review Report covering cross-platform compatibility for macOS/Linux/Windows, and include Security Audit summary covering input/command/path handling and IPC security. |
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 5.56% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
✅ Passed checks (3 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The title 'Speed up Windows worktree deletion' directly aligns with the PR's main objective of optimizing worktree deletion performance on Windows, clearly summarizing the primary change. |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.