worktrunk icon indicating copy to clipboard operation
worktrunk copied to clipboard

--no-cd flag ignored when using interactive picker

Open cperalt opened this issue 8 months ago • 1 comments

I use worktrunk with tmux — each worktree has a corresponding tmux session, and I have a post-switch hook that switches my tmux client to the matching session. Because of this, I use --no-cd so the shell in the current tmux session doesn't change directories (I only want the tmux switch, not a directory change in the source session).

Expected behavior: wt switch --no-cd should skip the directory change regardless of whether a branch is specified directly or selected via the interactive picker.

Actual behavior:

  • wt switch --no-cd main — works correctly, no directory change, hooks run as expected
  • wt switch --no-cd (opens picker, select a branch) — the directory change still happens after selection

Use case:

~/.config/worktrunk/config.toml

[post-switch] tmux = """ SESSION="mpos-{{ branch | sanitize }}" if tmux has-session -t "$SESSION" 2>/dev/null; then if [ -n "${TMUX:-}" ]; then tmux switch-client -t "$SESSION" else tmux attach-session -t "$SESSION" fi fi """

alias wts="wt switch --no-cd"

When I run wts from my main tmux session, pick a branch, and then switch back to the main session, the shell's working directory has changed to the selected worktree's path.

Version: 0.28.2

cperalt avatar Mar 07 '26 08:03 cperalt

Thanks for reporting this! I was able to identify the root cause: the interactive picker hardcoded change_dir: true when calling handle_switch_output(), so the --no-cd flag was never plumbed through from the CLI to the picker's switch path.

I've opened #1331 with a fix. A maintainer will review it shortly.

worktrunk-bot avatar Mar 07 '26 08:03 worktrunk-bot