worktrunk icon indicating copy to clipboard operation
worktrunk copied to clipboard

Feature: Interactive picker for wt remove (like wt switch)

Open alfredomtx opened this issue 9 months ago • 5 comments

The friction

wt switch without arguments opens an interactive picker to browse and select worktrees — great UX. But wt remove has no equivalent: you must type the full branch name or be in the worktree you want to remove.

Current workaround

Switch to the target worktree first, then wt remove:

wt switch           # pick worktree
wt remove           # remove current

Or type the full branch name: wt remove feature/cor/ASPD-27003-add-casl-validation

Ideal solution

Two possible approaches (not mutually exclusive):

  1. Interactive picker for wt remove — same picker as wt switch but removes the selected worktree on Enter.

  2. Remove keybinding in wt switch picker — add a shortcut (e.g. Alt-d or Del) to remove the highlighted worktree directly from the switch picker. Similar to how file managers let you delete while browsing. This might feel more natural since the picker is already the go-to for worktree navigation.

alfredomtx avatar Mar 03 '26 23:03 alfredomtx

Thanks for the suggestion! This is a feature request rather than a bug, so I'll leave it for a maintainer to evaluate and prioritize.

worktrunk-bot avatar Mar 03 '26 23:03 worktrunk-bot

yes, very reasonable idea!

let's add a shortcut to wt switch @worktrunk-bot ; evaluate which we should choose. it should not pass -D or -f. think about how we show success or failure

max-sixty avatar Mar 04 '26 05:03 max-sixty

Opened #1253 with an implementation.

How it works:

  • alt-d in the picker triggers accept(delete), which exits skim and routes to the delete handler
  • Calls handle_remove with safe defaults — no -D (force-delete unmerged branches), no -f (force-remove dirty worktrees)
  • On success: prints the standard wt remove output (worktree removed, branch deleted) and exits
  • On failure: shows the error (e.g., "has uncommitted changes", "cannot remove main working tree") and exits non-zero
  • Controls line in the preview pane updated to show alt-d: delete

Design choice on success/failure UX: After the picker exits, we show the same output as wt remove — this keeps it familiar and gives the user clear feedback. If the user wants to delete more worktrees, they can re-run wt switch. Keeping the picker open after a delete would require re-launching skim, which would cause screen flicker and add complexity.

codecov/patch: The delete handler code runs inside skim's accept flow, which requires interactive PTY input to trigger. The existing PTY test infrastructure could support an alt-d test, but the removal would require a non-current worktree to exist in the test repo — happy to add that if you'd like, but wanted to keep the initial PR focused.

worktrunk-bot avatar Mar 04 '26 06:03 worktrunk-bot

This either isn't working right or has drifted. On Mac wt v0.81.0, the command appears to be alt-x when in the wt switch picker. When you execute it, there is almost no feedback in the TUI - i think the / in the left column means it's been removed? I can't tell. Then pressing Enter on the same row re-creates the same worktree.

There is feedback if there are conflicts or a reason it can't do it, but the happy-path feedback feels incomplete to me. I would prefer at least an output "removed worktree xyz". Am I missing something?

Regardless, I am a huge fan of this utility, and tell all my peers about it, and they love it too!

mcascone avatar Oct 30 '26 15:10 mcascone

Yes: / marks a branch with no worktree. In the current picker, Alt-x can remove the worktree while keeping its unmerged branch, changing that row to / branch. Enter on the branch row creates a worktree again. The removal runs silently inside the picker, so the row change is the only success feedback; #4636 tracks making that result clear. Your separate request for a picker opened by wt remove is in #4635.

worktrunk-bot avatar Oct 30 '26 16:10 worktrunk-bot