feat(cd): add 'wt cd' to switch between existing worktrees - #117
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #117 +/- ##
==========================================
+ Coverage 36.70% 36.91% +0.20%
==========================================
Files 27 28 +1
Lines 3111 3199 +88
==========================================
+ Hits 1142 1181 +39
- Misses 1884 1931 +47
- Partials 85 87 +2
🚀 New features to boost your workflow:
|
'wt co' offers every local and remote branch and creates a worktree when one is missing, so switching between the worktrees you already have means scrolling past hundreds of irrelevant branches (issue #103). 'wt cd' (alias 'wt sw') selects only from worktrees that already exist, including the main checkout, and never creates anything. With a branch argument it navigates directly; without one it opens the same fuzzy picker used by the other interactive commands. The status line before the cd marker is deliberate: the shell wrapper greps for '^wt navigating to: ', and script(1) can prefix the first output line with a control character, which would silently break auto-cd. Closes #103
script(1) does not propagate the child's exit status on every platform (util-linux returns its own status without -e), so the shellenv wrapper reports 0 for a failed command on Linux. Every other non-zero-exit scenario in the suite already uses skip_shellenv + $WT_BIN for this reason.
This was referenced Aug 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #103.
Why
wt coalready has a fuzzy picker and auto-cd, but its list comes fromgetAvailableBranches()— every local and remote branch — and picking a branch without a worktree creates one. The request in #103 is narrower: jump between the worktrees that already exist, which is whatcd $(wt ls | fzf | cut -d' ' -f1)does today.What
wt cd [branch](aliaswt sw):(current); detached worktrees fall back to their directory name.no worktree found for branch: X / Use 'wt checkout X' to create one.--format jsonemits the usual envelope withpath/navigate_to, and requires an explicit branch argument (same rule ascheckoutandremove).Tab completion for
cd/swadded for bash, zsh, fish and PowerShell, completing existing worktree branches (unlikeremove, the main checkout is included). Docs updated in README,llms.txt,AGENTS.md, thewt examplescatalog, and the Claude Code skill.One implementation note
wt cdprints✓ Switched to worktree: <path>before the cd marker. That is not just cosmetic: the shell wrapper extracts the path withgrep '^wt navigating to: ', andscript(1)can prefix the first output line with a control character (^D), which makes the anchored grep miss it and silently skips auto-cd. Every other navigating command happens to print a status line first, so this was never hit before. The e2e suite reproduced it immediately.Testing
e2e/scenarios/cd.yaml: navigate to existing worktree,swalias, refusal to create, return to the main checkout, JSON behaviour.(current)marking, detached fallback, bare worktree skipped) and path containment.TestInteractiveCdWithoutArgsasserting the picker offers a branch with a worktree and not one without.go test ./...,go vet ./...,go run e2e/run.go(310 passed, 0 failed).TestBashTabCompletionForCheckoutBranchandTestBashTabCompletionForCommandsfail on my macOS box (bash 3.2), but they fail identically onmain— unrelated to this change.Unrelated harness bug spotted
e2e/run.gonever resets__exit_codebetween steps, and uses${__exit_code:-0}, so any zero-exit step following a non-zero-exit step inherits the old1and fails. I worked around it by splitting a scenario rather than touching shared infra here — happy to send a separate one-line fix.