|
| 1 | +--- |
| 2 | +name: worktrunk |
| 3 | +description: Manage git worktrees for parallel development workflows. Use when working with git worktrees, feature branch workflows, parallel AI agent tasks, or when the user mentions wt, worktrees, branch switching, or merging feature branches. |
| 4 | +allowed-tools: Bash(wt:*) |
| 5 | +--- |
| 6 | + |
| 7 | +# Worktrunk (wt) |
| 8 | + |
| 9 | +## Quick start |
| 10 | + |
| 11 | +```bash |
| 12 | +wt switch --create feature # Create worktree and branch |
| 13 | +wt switch feature # Switch to worktree |
| 14 | +wt list # Show all worktrees |
| 15 | +wt merge # Squash, rebase, merge to main, remove worktree |
| 16 | +wt remove # Remove worktree; delete branch if merged |
| 17 | +wt config shell install # Install shell integration (required for cd) |
| 18 | +``` |
| 19 | + |
| 20 | +## Core concepts |
| 21 | + |
| 22 | +**Worktrees** are separate working directories per branch (unlike `git switch` which changes branches in place). |
| 23 | +**Branches** are addressed by name; paths are computed from templates. |
| 24 | +**Default branch** is the merge target (main, master, etc.). |
| 25 | + |
| 26 | +## Switch |
| 27 | + |
| 28 | +```bash |
| 29 | +wt switch <branch> # Create worktree if needed, cd to it |
| 30 | +wt switch --create feature # Create new branch from default |
| 31 | +wt switch --create fix --base production # Create from specific base |
| 32 | +wt switch - # Previous worktree (like cd -) |
| 33 | +wt switch ^ # Default branch worktree |
| 34 | +wt switch pr:123 # GitHub PR #123 (requires gh) |
| 35 | +wt switch mr:456 # GitLab MR !456 (requires glab) |
| 36 | +``` |
| 37 | + |
| 38 | +**Flags:** |
| 39 | +```bash |
| 40 | +--base <branch> # Base branch for creation |
| 41 | +--execute <cmd> # Run command after switch (replaces wt process) |
| 42 | +--yes # Skip approval prompts |
| 43 | +--clobber # Remove stale paths at target |
| 44 | +--no-verify # Skip hooks |
| 45 | +``` |
| 46 | + |
| 47 | +**Execute flag** launches editors/agents (supports template variables): |
| 48 | +```bash |
| 49 | +wt switch --create feature --execute claude |
| 50 | +wt switch --create fix --execute "code {{ worktree_path }}" |
| 51 | +wt switch --create feature --execute "tmux new -s {{ branch | sanitize }}" |
| 52 | +``` |
| 53 | + |
| 54 | +## List |
| 55 | + |
| 56 | +```bash |
| 57 | +wt list # Show all worktrees |
| 58 | +wt list --full # Include CI status and line diffs |
| 59 | +wt list --branches # Include branches without worktrees |
| 60 | +wt list --format=json # JSON output for scripts |
| 61 | +``` |
| 62 | + |
| 63 | +**Columns:** Branch, Status (symbols), HEAD± (uncommitted), main↕ (ahead/behind default), Remote⇅, Path, CI, Commit, Age, Message |
| 64 | + |
| 65 | +**Status symbols:** |
| 66 | +``` |
| 67 | ++ staged ! modified ? untracked ✘ conflicts ⤴ rebase ⤵ merge |
| 68 | +_ same commit (safe) ⊂ integrated (safe) ↕ diverged ↑ ahead ↓ behind |
| 69 | +``` |
| 70 | + |
| 71 | +**JSON queries:** |
| 72 | +```bash |
| 73 | +wt list --format=json | jq '.[] | select(.main.ahead > 0) | .branch' |
| 74 | +wt list --format=json | jq '.[] | select(.working_tree.modified)' |
| 75 | +wt list --format=json | jq '.[] | select(.kind == "branch") | .branch' |
| 76 | +``` |
| 77 | + |
| 78 | +**Fields:** `branch`, `path`, `kind`, `commit`, `working_tree`, `main_state`, `main`, `remote`, `ci`, `statusline`, `is_current`, `is_previous`, etc. |
| 79 | + |
| 80 | +## Merge |
| 81 | + |
| 82 | +`wt merge [target]` merges current branch into target (default: default branch). |
| 83 | + |
| 84 | +**Pipeline:** squash → rebase (if behind) → pre-merge hooks → fast-forward merge → pre-remove hooks → remove worktree/branch → post-merge hooks |
| 85 | + |
| 86 | +```bash |
| 87 | +wt merge # Merge to default branch |
| 88 | +wt merge develop # Merge to specific branch |
| 89 | +wt merge --no-squash # Preserve commit history |
| 90 | +wt merge --no-commit # Skip committing (rebase still runs) |
| 91 | +wt merge --no-rebase # Skip rebase |
| 92 | +wt merge --no-remove # Keep worktree after merge |
| 93 | +wt merge --no-verify # Skip hooks |
| 94 | +wt merge --stage tracked # Only stage tracked files (default: all) |
| 95 | +``` |
| 96 | + |
| 97 | +## Remove |
| 98 | + |
| 99 | +```bash |
| 100 | +wt remove # Remove current worktree |
| 101 | +wt remove feature old-fix # Remove specific worktrees |
| 102 | +wt remove --force feature # Remove worktree with untracked files |
| 103 | +wt remove -D feature # Delete unmerged branch |
| 104 | +wt remove --no-delete-branch # Keep branch |
| 105 | +wt remove --foreground # Run removal in foreground (default: background) |
| 106 | +``` |
| 107 | + |
| 108 | +**Branch cleanup** (auto-deletes when merging adds nothing): same commit → ancestor → no added changes → trees match → merge adds nothing |
| 109 | + |
| 110 | +## Step |
| 111 | + |
| 112 | +```bash |
| 113 | +wt step commit # Stage and commit with LLM-generated message |
| 114 | +wt step squash # Squash all commits into one with LLM message |
| 115 | +wt step rebase # Rebase onto target branch |
| 116 | +wt step push # Fast-forward target to current branch |
| 117 | +wt step copy-ignored # Copy gitignored files between worktrees |
| 118 | +``` |
| 119 | + |
| 120 | +## Hooks |
| 121 | + |
| 122 | +Hooks run at lifecycle points. Define in `.config/wt.toml` (project) or `~/.config/worktrunk/config.toml` (user). |
| 123 | + |
| 124 | +**Types:** |
| 125 | +``` |
| 126 | +post-start # After worktree created (background, parallel) |
| 127 | +post-create # After worktree created (blocking) |
| 128 | +post-switch # After every switch (background) |
| 129 | +pre-commit # Before commit during merge |
| 130 | +pre-merge # Before merging to target |
| 131 | +post-merge # After successful merge |
| 132 | +pre-remove # Before worktree removed |
| 133 | +post-remove # After worktree removed (background) |
| 134 | +``` |
| 135 | + |
| 136 | +```toml |
| 137 | +[post-create] |
| 138 | +install = "npm ci" |
| 139 | +env = "echo 'PORT={{ branch | hash_port }}' > .env.local" |
| 140 | + |
| 141 | +[pre-merge] |
| 142 | +test = "npm test" |
| 143 | +lint = "npm run lint" |
| 144 | + |
| 145 | +[post-start] |
| 146 | +server = "npm run dev -- --port {{ branch | hash_port }}" |
| 147 | + |
| 148 | +[post-remove] |
| 149 | +kill-server = "lsof -ti :{{ branch | hash_port }} | xargs kill 2>/dev/null || true" |
| 150 | +``` |
| 151 | + |
| 152 | +**Template variables:** `{{ repo }}`, `{{ branch }}`, `{{ worktree_path }}`, `{{ commit }}`, `{{ remote }}`, `{{ target }}`, etc. |
| 153 | + |
| 154 | +**Filters:** `sanitize` (filesystem-safe), `hash_port` (port 10000-19999), `sanitize_db` (database-safe). |
| 155 | + |
| 156 | +**Run manually:** |
| 157 | +```bash |
| 158 | +wt hook pre-merge # Run all pre-merge hooks |
| 159 | +wt hook pre-merge test # Run hooks named "test" |
| 160 | +wt hook pre-merge user: # Run user hooks only |
| 161 | +wt hook pre-merge project:test # Run project's "test" hook |
| 162 | +wt hook pre-merge --yes # Skip approval prompts |
| 163 | +``` |
| 164 | + |
| 165 | +## Config |
| 166 | + |
| 167 | +```bash |
| 168 | +wt config shell install # Install shell integration (required for cd) |
| 169 | +wt config create # Create user config |
| 170 | +wt config create --project # Create project config (.config/wt.toml) |
| 171 | +wt config show # Show current config and file locations |
| 172 | +wt config state # Manage saved state |
| 173 | +wt config hook approvals # Manage hook approvals |
| 174 | +``` |
| 175 | + |
| 176 | +## Select |
| 177 | + |
| 178 | +`wt select` — interactive worktree picker with live preview (Unix only). |
| 179 | + |
| 180 | +**Keybindings:** `↑`/`↓` navigate, `Enter` switch, `1`/`2`/`3`/`4` preview tabs, `Esc` cancel |
| 181 | + |
| 182 | +## Shell integration |
| 183 | + |
| 184 | +Required for `wt switch` to change directories. Install with `wt config shell install`. |
| 185 | + |
| 186 | +**Manual install:** |
| 187 | +```bash |
| 188 | +# bash/zsh: add to ~/.bashrc or ~/.zshrc |
| 189 | +eval "$(wt config shell init bash)" |
| 190 | + |
| 191 | +# fish: add to ~/.config/fish/config.fish |
| 192 | +wt config shell init fish | source |
| 193 | +``` |
| 194 | + |
| 195 | +## Worktree paths |
| 196 | + |
| 197 | +Configure in user config (`~/.config/worktrunk/config.toml`): |
| 198 | + |
| 199 | +```toml |
| 200 | +# Default: siblings in parent (creates ~/code/myproject.feature-auth) |
| 201 | +worktree-path = "../{{ repo }}.{{ branch | sanitize }}" |
| 202 | + |
| 203 | +# Inside repository (creates ~/code/myproject/.worktrees/feature-auth) |
| 204 | +worktree-path = ".worktrees/{{ branch | sanitize }}" |
| 205 | + |
| 206 | +# Namespaced (creates ~/code/worktrees/myproject/feature-auth) |
| 207 | +worktree-path = "../worktrees/{{ repo }}/{{ branch | sanitize }}" |
| 208 | +``` |
| 209 | + |
| 210 | +## Examples |
| 211 | + |
| 212 | +**Feature branch workflow:** |
| 213 | +```bash |
| 214 | +wt switch --create feature |
| 215 | +# ... work ... |
| 216 | +wt merge |
| 217 | +``` |
| 218 | + |
| 219 | +**Parallel agent tasks:** |
| 220 | +```bash |
| 221 | +wt switch --create task1 --execute claude |
| 222 | +wt switch --create task2 --execute claude |
| 223 | +wt list |
| 224 | +``` |
| 225 | + |
| 226 | +**Dev servers per worktree:** |
| 227 | +```toml |
| 228 | +[post-start] |
| 229 | +server = "npm run dev -- --port {{ branch | hash_port }}" |
| 230 | + |
| 231 | +[post-remove] |
| 232 | +kill = "lsof -ti :{{ branch | hash_port }} | xargs kill 2>/dev/null || true" |
| 233 | +``` |
| 234 | + |
| 235 | +**Local CI (fast validation before merge):** |
| 236 | +```toml |
| 237 | +[pre-commit] |
| 238 | +format = "cargo fmt -- --check" |
| 239 | +lint = "cargo clippy" |
| 240 | + |
| 241 | +[pre-merge] |
| 242 | +test = "cargo test" |
| 243 | +build = "cargo build --release" |
| 244 | +``` |
| 245 | + |
| 246 | +## Files |
| 247 | + |
| 248 | +- **User config:** `~/.config/worktrunk/config.toml` |
| 249 | +- **Project config:** `.config/wt.toml` |
| 250 | +- **Logs:** `.git/wt-logs/` |
0 commit comments