Skip to content

feat(switch): make --no-cd print-only in picker mode - #1445

Merged
max-sixty merged 1 commit into
mainfrom
switch-no-cd-prints
Mar 12, 2026
Merged

max-sixty merged 1 commit into
mainfrom
switch-no-cd-prints

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Summary

Draft implementation per @max-sixty's suggestion: reuse --no-cd to make the picker print-only instead of adding a separate --print flag.

  • When wt switch --no-cd opens the interactive picker (no branch argument), selecting a branch prints its name to stdout and exits — no switching, no cd directive, no hooks
  • When wt switch --no-cd <branch> is used with an explicit branch, behavior is unchanged (switches without cd)
  • alt-r (remove) is blocked in print mode since it's a read-only operation

This avoids adding a new CLI flag while giving the same scripting capability that #1404 proposed.

Test plan

  • Unit tests for resolve_print_identifier (switch, create, remove cases)
  • PTY integration test: --no-cd picker prints branch name, emits no cd directive
  • Existing --no-cd tests still pass (directive suppression, hooks, execute)
  • Help snapshots and doc sync updated

🤖 Generated with Claude Code

When `wt switch --no-cd` opens the interactive picker, it now prints
the selected branch name and exits without switching — useful for
scripting without needing a separate --print flag.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@max-sixty
max-sixty merged commit 54f34bb into main Mar 12, 2026
22 checks passed
@max-sixty
max-sixty deleted the switch-no-cd-prints branch March 12, 2026 05:12
@ruudk

ruudk commented Mar 12, 2026

Copy link
Copy Markdown

Thanks @max-sixty. Would you be able to tag it too?

max-sixty added a commit that referenced this pull request May 21, 2026
With `[switch] cd = false` or `wt switch --no-cd`, opening the
interactive picker (`wt switch` with no branch argument) and selecting a
worktree printed the branch name and exited — no switch, no hooks, and
`Alt-c` created nothing. #1445 introduced this as an explicit print-only
mode, but it surprises anyone who sets `cd = false` as a standing
navigation preference (driving worktree switches through tmux or cmux):
the picker silently stops doing anything.

The picker now runs the same `plan_switch` → `execute_switch` pipeline
as `wt switch <branch>`, suppressing only the cd directive. Pre- and
post-switch hooks fire, `Alt-c` creates the worktree, and
`--format=json` works in the picker too (`requires = "branch"` and the
`--branches`/`--remotes` conflict are dropped from the flag). JSON
emission is extracted into a shared `emit_switch_json` so the argument
path and the picker produce identical output.

This is a behavior change: the print-only picker mode is gone. Scripts
that captured its bare-branch-name output should switch to `wt switch
--format=json`, which both performs the switch and prints a structured
`action`/`branch`/`path` result — now shown as a `pick` alias example in
tips-patterns. The cmux recipe drops its `pick` alias workaround, since
the picker fires `pre-switch` hooks directly.

Closes #2837. Thanks to @endigma for the discussion that pinned down the
intended behavior: the picker should be identical to passing the branch
as an argument.

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[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.

3 participants