You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
wt switch interactive picker with cd = false skips switch hooks #2837
With [switch] cd = false (or --no-cd), the interactive picker prints the selected branch and exits without firing any switch hooks. The same wt switch <branch> --no-cd invocation with a branch arg fires hooks normally, so the picker path is inconsistent with the direct-arg path.
Surfaced in #2796 — @endigma's working cmux recipe needs a wt pick alias that runs the picker twice to force hooks to fire:
[switch]
cd = false
[pre-switch]
trace = "echo pre-switch fired for {{ branch }} >&2"
wt switch other-branch → prints pre-switch fired for other-branch ✓
wt switch (picker, select other-branch) → prints other-branch, no hook output ✗
post-switch, pre-start, post-start are also skipped on the picker path.
Cause
src/commands/picker/mod.rs:767-777 early-returns on !change_dir, before run_pre_switch_hooks / plan_switch / execute_switch / the background-hook spawn that the change_dir = true branch flows into.
Comment on the branch says "read-only, no side effects" — that was the intent when #1330 added --no-cd support to the picker, but the same shape later bit #1704 (alt-r removal in the picker skipping pre-remove / post-remove).
Constraint
Pre-switch hooks can't run while skim still owns the terminal — they'd corrupt the picker frame and have nowhere to prompt. So the fix isn't "run hooks before the early-return"; it's something like "tear down skim first, then run the normal switch pipeline with change_dir = false". That removes the early-return and lets the picker share the same execute_switch path as the direct-arg case.
Workaround
The wt pick alias above. The double-invocation is the cost of routing the picker's output through the CLI a second time so it hits the non-picker code path.
Verified the analysis: the early-return at src/commands/picker/mod.rs:767-777 does skip the entire hook + execute pipeline that the change_dir = true branch flows into (run_pre_switch_hooks → plan_switch → execute_switch → background hooks).
One missing piece of context: the no-hooks behavior on the picker --no-cd path was an explicit design decision in #1445 ("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"), and test_switch_picker_no_cd_prints_branch_without_switching in tests/integration_tests/switch_picker.rs locks that contract in. So the fix is a contract change, not just a missing call: any patch that makes hooks fire needs to revisit #1445's intent and rework that test, and reason about what alt-c (create) with cd = false should do — currently it just prints "create" and no-ops, but a unified pipeline would actually create the worktree.
Skipping a code change — the print-only-vs-fire-hooks-then-print question is a design call for a maintainer. The wt pick alias in the cmux recipe (#2836) is a reasonable workaround in the meantime.
I would expect the interactive picker to work identically to when providing the branch as an argument, which is what the dumb pick alias is hacking it to do so it works
oh, this is in a worse state than I realized, sorry; seems that picker + --no-cd doesn't do the things it should, because of #1445. Let me find a way of fixing while allowing something to get the branch name
Activity
worktrunk-bot commentedon May 20, 2026
Verified the analysis: the early-return at src/commands/picker/mod.rs:767-777 does skip the entire hook + execute pipeline that the
change_dir = truebranch flows into (run_pre_switch_hooks→plan_switch→execute_switch→ background hooks).One missing piece of context: the no-hooks behavior on the picker
--no-cdpath was an explicit design decision in #1445 ("Whenwt switch --no-cdopens the interactive picker (no branch argument), selecting a branch prints its name to stdout and exits — no switching, no cd directive, no hooks"), andtest_switch_picker_no_cd_prints_branch_without_switchingintests/integration_tests/switch_picker.rslocks that contract in. So the fix is a contract change, not just a missing call: any patch that makes hooks fire needs to revisit #1445's intent and rework that test, and reason about whatalt-c(create) withcd = falseshould do — currently it just prints "create" and no-ops, but a unified pipeline would actually create the worktree.Skipping a code change — the print-only-vs-fire-hooks-then-print question is a design call for a maintainer. The
wt pickalias in the cmux recipe (#2836) is a reasonable workaround in the meantime.max-sixty commentedon May 20, 2026
OK, I think we probably should run the switch hooks, even though we're not
cd-ing?@endigma do you agree? or is the existing state what you would expect?
endigma commentedon May 20, 2026
I would expect the interactive picker to work identically to when providing the branch as an argument, which is what the dumb pick alias is hacking it to do so it works
max-sixty commentedon May 20, 2026
oh, this is in a worse state than I realized, sorry; seems that picker +
--no-cddoesn't do the things it should, because of #1445. Let me find a way of fixing while allowing something to get the branch namefix(switch): interactive picker runs the full switch pipeline (#2845)