Skip to content

feat: add alt-r shortcut to remove worktrees from switch picker - #1253

Merged
max-sixty merged 7 commits into
mainfrom
feat/picker-delete-shortcut
Mar 6, 2026
Merged

max-sixty merged 7 commits into
mainfrom
feat/picker-delete-shortcut

Conversation

@worktrunk-bot

@worktrunk-bot worktrunk-bot commented Mar 4, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds an alt-r keybinding to the wt switch interactive picker that removes the highlighted worktree directly, without needing to type the branch name or switch first.

  • Safe defaults: no -D (force-delete unmerged branches), no -f (force-remove dirty worktrees) — matches the safety behavior requested in Feature: Interactive picker for wt remove (like wt switch) #1251
  • Removes the worktree and its merged branch in foreground (immediate feedback)
  • Shows standard wt remove success/failure output after picker exits
  • Controls line in the preview pane updated to show alt-r: remove

Closes #1251

Test plan

  • All 554 unit tests pass (cargo test --lib --bins)
  • Clippy clean
  • Doc sync test passes
  • Manual testing: open wt switch, highlight a worktree, press alt-r — verify it removes the worktree and shows the success message
  • Manual testing: try alt-r on main worktree — verify it shows "Cannot remove the main working tree" error
  • Manual testing: try alt-r on a worktree with uncommitted changes — verify it shows the dirty worktree error

🤖 Generated with Claude Code

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two observations:

  1. Keybindings table not updated — The new alt-d binding is shown in the preview controls line but missing from the keybindings table in src/cli/mod.rs L321 (the primary source for docs/content/switch.md). Add a row after Alt-c:

    | `Alt-d` | Delete selected worktree |
    

    Then run cargo test --test integration test_command_pages_and_skill_files_are_in_sync to sync the docs page.

  2. Hooks are skipped — The delete path passes verify: false to handle_remove_output, so pre-remove / post-remove hooks don't run. The normal wt remove flow respects these. This may be intentional (prompting for hooks mid-picker would be disruptive), but worth a conscious decision — users relying on pre-remove hooks won't get that protection from the picker.

@max-sixty

Copy link
Copy Markdown
Owner

why alt+d? evaluate a number of options; consider relevance, prior art, conflicts, etc

@worktrunk-bot

Copy link
Copy Markdown
Collaborator Author

Good question — here's an evaluation of the candidates.

Current picker conventions for context: alt-c (create), alt-p (preview toggle), ctrl-u/ctrl-d (scroll preview).

Binding Mnemonic Prior art Conflicts Notes
alt-d "d" for delete readline alt-d = kill-word ctrl-d (preview scroll) uses same letter with different modifier — accidental alt-vs-ctrl mixup would scroll vs. delete a worktree Follows the alt-{first letter} pattern
alt-x "x" for close/remove fzf examples commonly use ctrl-x/alt-x for destructive secondary actions; "x" is universal for close (tmux, browser tabs, UI buttons) None Doesn't follow strict first-letter pattern, but "x = remove" is widely understood
alt-r "r" for remove Matches the actual CLI command (wt remove) readline alt-r = revert-line (minor) Follows alt-{first letter} pattern, consistent with the tool's own terminology
ctrl-x "cut" (= remove) Common in GUI apps Emacs prefix key; breaks the alt-* modifier family used by the other custom bindings Mixed modifier convention
del Delete key Intuitive Not all keyboards have it (laptops); inconsistent terminal support Low discoverability

The ctrl-d / alt-d proximity is the main concern with the current choice — it's the one combination where a modifier-slip causes a destructive action. alt-x avoids that entirely and has the strongest "delete/close" connotation in prior art. alt-r stays closer to the project's alt-{first letter} convention and matches wt remove.

My lean is alt-x (safest, most universal) or alt-r (most consistent with this codebase). Happy to switch to whichever you prefer.

@max-sixty

Copy link
Copy Markdown
Owner

let's do alt-r

@worktrunk-bot

Copy link
Copy Markdown
Collaborator Author

Switched to alt-r — updated the keybinding, all comments, docs, help text, and snapshot tests. Also changed the user-facing label from "delete" to "remove" to match the wt remove mnemonic.

Comment thread src/commands/select/mod.rs Outdated
// Create new worktree with query as branch name (alt-c for "create")
"alt-c:accept(create)".to_string(),
// Delete selected worktree (alt-r for "remove")
"alt-r:accept(delete)".to_string(),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we name this remove, rather than delete?

---
1: HEAD± | 2: log | 3: main…± | 4: remote⇅ | 5: summary [N/M]
Enter: switch | alt-c: create | Esc: cancel | ctrl-u/d: scr
Enter: switch | alt-c: create | alt-r: remove | Esc: cancel

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do these get cut off? because we're using an very thin width in tests?

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re: rename to remove — Done in c90db80. Renamed the enum variant to PickerAction::Remove and the accept label to "remove".

Re: truncated controls in snapshots — Yes, this is the test terminal width. The preview panel gets ~59 chars (120-col terminal with right:60 split), so the controls line has always been truncated — it was ...ctrl-u/d: scr before this PR. The actual terminal at typical widths (160+ cols) shows the full line. The snapshots just capture what fits in the test viewport.

@max-sixty
max-sixty enabled auto-merge (squash) March 6, 2026 04:04
@max-sixty

Copy link
Copy Markdown
Owner

resolve conflicts please

separately: is there any GitHub event we could trigger a resolve-conflicts CI job to ask claude to resolve conflicts? or that's not available?

github-actions Bot and others added 6 commits March 6, 2026 05:35
Adds an `alt-d` keybinding in `wt switch` interactive picker that removes
the highlighted worktree. Uses safe defaults (no -D, no -f) — unmerged
branches are retained and dirty worktrees are not force-removed.

Closes #1251

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Run cargo fmt and update 7 switch picker preview snapshots
to reflect the new alt-d: delete controls text.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Update the keybindings table in `wt switch --help` to document the
new alt-d delete shortcut, and sync the generated docs and help
snapshot.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
alt-r matches the `wt remove` command name and avoids the ctrl-d/alt-d
modifier-slip risk that could accidentally trigger a destructive action
instead of scrolling the preview.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Rename the enum variant and accept label from "delete" to "remove"
to match `wt remove` terminology consistently.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@worktrunk-bot
worktrunk-bot force-pushed the feat/picker-delete-shortcut branch from c90db80 to be0c04f Compare March 6, 2026 05:37
@worktrunk-bot worktrunk-bot changed the title feat: add alt-d shortcut to delete worktrees from switch picker feat: add alt-r shortcut to remove worktrees from switch picker Mar 6, 2026
@max-sixty
max-sixty merged commit afc3754 into main Mar 6, 2026
20 of 21 checks passed
@max-sixty
max-sixty deleted the feat/picker-delete-shortcut branch March 6, 2026 05:52
@worktrunk-bot

Copy link
Copy Markdown
Collaborator Author

Conflicts resolved and rebased onto main. All CI checks green (Linux, macOS, Windows, lint, code-coverage). The codecov/patch failure is unchanged from before — the picker remove path runs inside skim's interactive TUI and can't be covered by automated tests.

On the automated conflict resolution question: GitHub doesn't expose a native event for "PR became conflicted." The closest options would be a scheduled workflow that polls gh pr list --json mergeable and triggers on CONFLICTING state, or a push event on main that checks open PRs for new conflicts. Neither is built-in, but either could dispatch to a Claude job to attempt the rebase.

@max-sixty

Copy link
Copy Markdown
Owner

On the automated conflict resolution question: GitHub doesn't expose a native event for "PR became conflicted." The closest options would be a scheduled workflow that polls gh pr list --json mergeable and triggers on CONFLICTING state, or a push event on main that checks open PRs for new conflicts. Neither is built-in, but either could dispatch to a Claude job to attempt the rebase.

could we do a scan of PRs authored by @worktrunk-bot as part of one of our nightly jobs, and merge the default branch into any PRs that have conflicts?

@worktrunk-bot

Copy link
Copy Markdown
Collaborator Author

Yes — this fits naturally into the nightly cleaner job. It already has contents: write + pull-requests: write permissions and uses BOT_TOKEN, so no new tokens or permissions needed.

The addition would be a step like:

# Find open bot PRs with conflicts
CONFLICTED=$(gh pr list --author worktrunk-bot --json number,mergeable \
  --jq '[.[] | select(.mergeable == "CONFLICTING")] | .[].number')

for pr in $CONFLICTED; do
  gh pr checkout "$pr"
  if git merge origin/main --no-edit; then
    git push
    gh pr comment "$pr" -b "Merged main to resolve conflicts."
  else
    git merge --abort
    gh pr comment "$pr" -b "Automated merge from main failed — conflicts need manual resolution."
  fi
  git checkout main
done

A few considerations:

  • Merge vs rebase: git merge origin/main is safer for automation — it doesn't rewrite history and won't force-push. Rebase would be cleaner but requires --force-with-lease and can fail in more subtle ways.
  • Scope: Limiting to --author worktrunk-bot is good — we shouldn't touch human-authored PRs without being asked.
  • Placement: Could be a standalone step at the start of the nightly cleaner, before the Claude sweep. It's a simple shell script, no need for Claude to drive it.

Want me to add this to claude-nightly-cleaner.yaml?

@max-sixty

Copy link
Copy Markdown
Owner

It's a simple shell script, no need for Claude to drive it.

Claude needs to resolve conflicts

but yes, add to the start or end of a job, ask Claude to use subagents

worktrunk-bot added a commit that referenced this pull request Mar 6, 2026
Adds a Step 0 to the nightly cleaner prompt that checks for open
worktrunk-bot PRs with merge conflicts and resolves them using
Claude subagents before proceeding to the code review sweep.

Each conflicted PR gets a dedicated subagent that checks out the
branch, merges main, resolves conflicts, pushes, and monitors CI.
PRs are processed in parallel via the Task tool.

Requested in #1253.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@worktrunk-bot

Copy link
Copy Markdown
Collaborator Author

Done — #1307 adds a Step 0 to the nightly cleaner that finds conflicted worktrunk-bot PRs and resolves them using Claude subagents (Task tool) before the code review sweep. Each PR gets its own subagent so they run in parallel, and each one monitors CI after pushing.

max-sixty pushed a commit that referenced this pull request Mar 6, 2026
## Summary

- Adds a "Step 0" to the nightly cleaner that checks for open
`worktrunk-bot` PRs with merge conflicts
- Conflicted PRs are resolved using Claude subagents (Task tool), run in
parallel
- Each subagent checks out the PR branch, merges main, resolves
conflicts, pushes, and monitors CI
- Falls back to commenting on the PR if conflicts are too complex to
resolve confidently

Requested by @max-sixty in #1253.

## Test plan

- [ ] Trigger via `workflow_dispatch` when a bot PR has conflicts to
verify end-to-end
- [ ] Verify no-op behavior when no bot PRs are conflicted

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: worktrunk-bot <[email protected]>
Co-authored-by: Claude Opus 4.6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants