---
source: tests/integration_tests/help.rs
info:
program: wt
args:
- switch
- "--help"
env:
CLICOLOR_FORCE: "1"
COLUMNS: "500"
GIT_EDITOR: ""
LANG: C
LC_ALL: C
NO_COLOR: ""
PSModulePath: ""
RUST_LOG: warn
SHELL: ""
TERM: alacritty
WORKTRUNK_APPROVALS_PATH: /nonexistent/test/approvals.toml
WORKTRUNK_CONFIG_PATH: /nonexistent/test/config.toml
WORKTRUNK_SYSTEM_CONFIG_PATH: /etc/xdg/worktrunk/config.toml
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
---
success: true
exit_code: 0
----- stdout -----
wt switch - Switch to a worktree; create if needed
Usage: [1m[36mwt switch[0m [36m[OPTIONS][0m [36m[BRANCH][0m [1m[36m[--[0m [36m<EXECUTE_ARGS>...[0m[1m[36m][0m
[1m[32mArguments:[0m
[36m[BRANCH][0m
Branch name or shortcut[0m
Opens interactive picker if omitted. Shortcuts: '^' (default branch), '-' (previous), '@' (current), 'pr:{N}' (GitHub PR), 'mr:{N}' (GitLab MR)[0m
[36m[EXECUTE_ARGS]...[0m
Additional arguments for --execute command (after --)[0m
Arguments after [1m--[0m are appended to the execute command. Each argument is expanded for templates, then POSIX shell-escaped.[0m
[1m[32mOptions:[0m
[1m[36m-c[0m, [1m[36m--create[0m
Create a new branch
[1m[36m-b[0m, [1m[36m--base[0m[36m [0m[36m<BASE>[0m
Base branch[0m
Defaults to default branch. Supports the same shortcuts as the branch argument: [1m^[0m, [1m@[0m, [1m-[0m, [1mpr:{N}[0m, [1mmr:{N}[0m.[0m
[1m[36m-x[0m, [1m[36m--execute[0m[36m [0m[36m<EXECUTE>[0m
Command to run after switch[0m
Replaces the wt process with the command after switching, giving it full terminal control. Useful for launching editors, AI agents, or other interactive tools.[0m
Supports ]8;;@/hook.md#template-variables\[4mhook template variables]8;;\[0m ([1m{{ branch }}[0m, [1m{{ worktree_path }}[0m, etc.) and filters. [1m{{ base }}[0m and [1m{{ base_worktree_path }}[0m require [1m--create[0m.[0m
Especially useful with shell aliases:[0m
[1m[1malias wsc='wt switch --create -x claude'[0m
[1mwsc feature-branch -- 'Fix GH #322'[0m
[0m
Then [1mwsc feature-branch[0m creates the worktree and launches Claude Code. Arguments after [1m--[0m are passed to the command, so [1mwsc feature -- 'Fix GH #322'[0m runs [1mclaude 'Fix GH #322'[0m, starting Claude with a prompt.[0m
Template example: [1m-x 'code {{ worktree_path }}'[0m opens VS Code at the worktree, [1m-x 'tmux new -s {{ branch | sanitize }}'[0m starts a tmux session named after the branch.[0m
[1m[36m--clobber[0m
Remove stale paths at target
[1m[36m--no-cd[0m
Skip directory change after switching[0m
Hooks still run normally. Useful when hooks handle navigation (e.g., tmux workflows) or for CI/automation. Use --cd to override.[0m
In picker mode (no branch argument), prints the selected branch name and exits without switching. Useful for scripting.[0m
[1m[36m-h[0m, [1m[36m--help[0m
Print help (see a summary with '-h')
[1m[32mPicker Options:[0m
[1m[36m--branches[0m
Include branches without worktrees
[1m[36m--remotes[0m
Include remote branches
[1m[32mAutomation:[0m
[1m[36m--no-hooks[0m
Skip hooks
[1m[36m--format[0m[36m [0m[36m<FORMAT>[0m
Output format[0m
JSON prints structured result to stdout. Designed for tool integration (e.g., Claude Code WorktreeCreate hooks).[0m
Possible values:
- [1m[36mtext[0m: Human-readable text output
- [1m[36mjson[0m: JSON output
[default: text]
[1m[32mGlobal Options:[0m
[1m[36m-C[0m[36m [0m[36m<path>[0m
Working directory for this command
[1m[36m--config[0m[36m [0m[36m<path>[0m
User config file path
[1m[36m-v[0m, [1m[36m--verbose[0m[36m...[0m
Verbose output (-v: info logs + hook/template output; -vv: debug logs + diagnostic report + trace.log/output.log under .git/wt/logs/)
[1m[36m-y[0m, [1m[36m--yes[0m
Skip approval prompts
Worktrees are addressed by branch name; paths are computed from a configurable template. Unlike [2mgit switch[0m, this navigates between worktrees rather than changing branches in place.
[1m[32mExamples[0m
[107m [0m [2m[0m[2m[34mwt[0m[2m switch feature-auth # Switch to worktree[0m[2m[0m
[107m [0m [2m[0m[2m[34mwt[0m[2m switch [0m[2m[36m-[0m[2m # Previous worktree (like cd -)[0m[2m[0m
[107m [0m [2m[0m[2m[34mwt[0m[2m switch [0m[2m[36m--create[0m[2m new-feature # Create new branch and worktree[0m[2m[0m
[107m [0m [2m[0m[2m[34mwt[0m[2m switch [0m[2m[36m--create[0m[2m hotfix [0m[2m[36m--base[0m[2m production[0m
[107m [0m [2m[0m[2m[34mwt[0m[2m switch pr:123 # Switch to PR #123's branch[0m[2m[0m
[1m[32mCreating a branch[0m
The [2m--create[0m flag creates a new branch from [2m--base[0m — the default branch unless specified. Without [2m--create[0m, the branch must already exist. Switching to a remote branch (e.g., [2mwt switch feature[0m when only [2morigin/feature[0m exists) creates a local tracking branch.
[1m[32mCreating worktrees[0m
If the branch already has a worktree, [2mwt switch[0m changes directories to it. Otherwise, it creates one:
1. Runs pre-switch hooks, blocking until complete
2. Creates worktree at configured path
3. Switches to new directory
4. Runs pre-start hooks, blocking until complete
5. Spawns post-start and post-switch hooks in the background
[107m [0m [2m[0m[2m[34mwt[0m[2m switch feature # Existing branch → creates worktree[0m[2m[0m
[107m [0m [2m[0m[2m[34mwt[0m[2m switch [0m[2m[36m--create[0m[2m feature # New branch and worktree[0m[2m[0m
[107m [0m [2m[0m[2m[34mwt[0m[2m switch [0m[2m[36m--create[0m[2m fix [0m[2m[36m--base[0m[2m release # New branch from release[0m[2m[0m
[107m [0m [2m[0m[2m[34mwt[0m[2m switch [0m[2m[36m--create[0m[2m temp [0m[2m[36m--no-hooks[0m[2m # Skip hooks[0m[2m[0m
[1m[32mShortcuts[0m
Shortcut Meaning
──────── ─────────────────────────────
[2m^[0m Default branch ([2mmain[0m/[2mmaster[0m)
[2m@[0m Current branch/worktree
[2m-[0m Previous worktree (like [2mcd -[0m)
[2mpr:{N}[0m GitHub PR #N's branch
[2mmr:{N}[0m GitLab MR !N's branch
[107m [0m [2m[0m[2m[34mwt[0m[2m switch [0m[2m[36m-[0m[2m # Back to previous[0m[2m[0m
[107m [0m [2m[0m[2m[34mwt[0m[2m switch ^ # Default branch worktree[0m[2m[0m
[107m [0m [2m[0m[2m[34mwt[0m[2m switch [0m[2m[36m--create[0m[2m fix [0m[2m[36m--base=@[0m[2m # Branch from current HEAD[0m[2m[0m
[107m [0m [2m[0m[2m[34mwt[0m[2m switch [0m[2m[36m--create[0m[2m fix [0m[2m[36m--base=pr:123[0m[2m # Branch from PR #123's head[0m[2m[0m
[107m [0m [2m[0m[2m[34mwt[0m[2m switch pr:123 # PR #123's branch[0m[2m[0m
[107m [0m [2m[0m[2m[34mwt[0m[2m switch mr:101 # MR !101's branch[0m[2m[0m
Shortcuts also apply to [2m--base[0m. For a fork PR/MR, the head commit is fetched and used as the base SHA without creating a tracking branch.
[1m[32mInteractive picker[0m
When called without arguments, [2mwt switch[0m opens an interactive picker to browse and select worktrees with live preview.
[1mKeybindings:[0m
Key Action
───────────── ─────────────────────────────────────────
[2m↑[0m/[2m↓[0m Navigate worktree list
(type) Filter worktrees
[2mEnter[0m Switch to selected worktree
[2mAlt-c[0m Create new worktree named as entered text
[2mEsc[0m Cancel
[2m1[0m–[2m5[0m Switch preview tab
[2mAlt-p[0m Toggle preview panel
[2mCtrl-u[0m/[2mCtrl-d[0m Scroll preview up/down
[1mPreview tabs[0m — toggle with number keys:
1. [1mHEAD±[0m — Diff of uncommitted changes
2. [1mlog[0m — Recent commits; commits already on the default branch have dimmed hashes
3. [1mmain…±[0m — Diff of changes since the merge-base with the default branch
4. [1mremote⇅[0m — Ahead/behind diff vs upstream tracking branch
5. [1msummary[0m — LLM-generated branch summary; requires [2m[list] summary = true[0m and [2m[commit.generation][0m
[1mPager configuration:[0m The preview panel pipes diff output through git's pager. Override in user config:
[107m [0m [2m[36m[switch.picker][0m
[107m [0m [2mpager = [0m[2m[32m"delta --paging=never --width=$COLUMNS"[0m
Available on Unix only (macOS, Linux). On Windows, use [2mwt list[0m or [2mwt switch <branch>[0m directly.
[1m[32mPull requests and merge requests[0m
The [2mpr:<number>[0m and [2mmr:<number>[0m shortcuts resolve a GitHub PR or GitLab MR to its branch. For same-repo PRs/MRs, worktrunk switches to the branch directly. For fork PRs/MRs, it fetches the ref ([2mrefs/pull/N/head[0m or [2mrefs/merge-requests/N/head[0m) and configures [2mpushRemote[0m to the fork URL.
[107m [0m [2m[0m[2m[34mwt[0m[2m switch pr:101 # GitHub PR #101[0m[2m[0m
[107m [0m [2m[0m[2m[34mwt[0m[2m switch mr:101 # GitLab MR !101[0m[2m[0m
Requires [2mgh[0m (GitHub) or [2mglab[0m (GitLab) CLI to be installed and authenticated. The [2m--create[0m flag cannot be used with [2mpr:[0m/[2mmr:[0m syntax since the branch already exists.
[1mForks:[0m The local branch uses the PR/MR's branch name directly (e.g., [2mfeature-fix[0m), so [2mgit push[0m works normally. If a local branch with that name already exists tracking something else, rename it first.
[1m[32mWhen wt switch fails[0m
- [1mBranch doesn't exist[0m — Use [2m--create[0m, or check [2mwt list --branches[0m
- [1mPath occupied[0m — Another worktree is at the target path; switch to it or remove it
- [1mStale directory[0m — Use [2m--clobber[0m to remove a non-worktree directory at the target path
To change which branch a worktree is on, use [2mgit switch[0m inside that worktree.
[1m[32mSee also[0m
- [2mwt list[0m — View all worktrees
- [2mwt remove[0m — Delete worktrees when done
- [2mwt merge[0m — Integrate changes back to the default branch
----- stderr -----