What to build
Build on the static completion shipped in #17 by adding dynamic completion of worktree names at three specific positions:
wt use <TAB> — completes from the live worktree list.
wt rm <TAB> — same source as use.
wt session rm <TAB> — completes from worktrees attached to the active tmux session (panes mode) or tracked windows-mode sessions (~/.wt/sessions.json), respecting --mode if passed.
Mechanism: a hidden helper subcommand prints candidates one per line; each shell's completion script invokes the helper at the relevant positional positions.
End-to-end behaviour after this lands:
$ wt use <TAB><TAB>
feature/auth feature/payments bugfix/header
$ wt rm fea<TAB>
feature/auth feature/payments
$ wt session rm <TAB>
feature/auth feature/payments
Subcommand and flag completion from #17 continues to work unchanged; this issue only adds value-level completion for the three positionals named above.
Implementation notes
1. Hidden helper subcommand. Add a hidden wt __complete <kind> subcommand (#[command(hide = true)]) that prints completion candidates to stdout, one per line, with no decoration:
wt __complete worktrees — wraps the existing WorktreeManager::list_worktrees(), filters non-empty task_id (mirroring the existing filter used by the interactive picker), and prints task_id per line.
wt __complete session-worktrees [--mode panes|windows] — reads the active session state. For panes mode, lists worktrees with a window in the wt tmux session; for windows mode, reads from ~/.wt/sessions.json. When --mode is omitted, fall back to the resolved default from Config::load_for_repo.
The helper must be silent on errors (exit 0 with empty output) so that a transient failure (no git repo, no tmux, missing session file) never breaks the user's prompt.
2. Per-shell wrappers. For each shell, augment the static completion script from #17 so that the three positional positions delegate to the helper:
- bash: in the
_wt completion function, branch on the detected subcommand (use, rm, session rm) and call compgen -W "$(wt __complete worktrees 2>/dev/null)" -- "$cur" for that positional.
- zsh: in the generated
_wt function, replace the value spec for the affected positionals with ':worktree:_wt_worktrees', where _wt_worktrees is a small helper that runs wt __complete worktrees and feeds _describe.
- fish: append
complete -c wt -n "__fish_seen_subcommand_from use" -f -a "(wt __complete worktrees)" (and analogous lines for rm and session rm) to the generated fish file.
- elvish: register a custom completer via
edit:completion:arg-completer that delegates to the static map for known cases and calls the helper for the three target positions.
The implementer may choose to (a) post-process clap_complete output in Rust before emitting, or (b) emit a separate "dynamic addendum" file per shell that's sourced after the static one. Either is acceptable as long as #17's static behaviour is preserved and the acceptance criteria pass.
3. install.sh integration. No new install paths — the dynamic addendum lands in the same shell completion location as #17. If the addendum is a separate file/snippet, ensure idempotency on repeat runs (mirror the existing grep -q guards).
Acceptance criteria
Blocked by
Out of scope
- Dynamic completion for
wt new <name> (free-form; could complete from local branch names but warrants a separate discussion).
- Completing base branches for
-b <branch> from git branch output (separate follow-up).
- PowerShell.
What to build
Build on the static completion shipped in #17 by adding dynamic completion of worktree names at three specific positions:
wt use <TAB>— completes from the live worktree list.wt rm <TAB>— same source asuse.wt session rm <TAB>— completes from worktrees attached to the active tmux session (panes mode) or tracked windows-mode sessions (~/.wt/sessions.json), respecting--modeif passed.Mechanism: a hidden helper subcommand prints candidates one per line; each shell's completion script invokes the helper at the relevant positional positions.
End-to-end behaviour after this lands:
Subcommand and flag completion from #17 continues to work unchanged; this issue only adds value-level completion for the three positionals named above.
Implementation notes
1. Hidden helper subcommand. Add a hidden
wt __complete <kind>subcommand (#[command(hide = true)]) that prints completion candidates to stdout, one per line, with no decoration:wt __complete worktrees— wraps the existingWorktreeManager::list_worktrees(), filters non-emptytask_id(mirroring the existing filter used by the interactive picker), and printstask_idper line.wt __complete session-worktrees [--mode panes|windows]— reads the active session state. For panes mode, lists worktrees with a window in thewttmux session; for windows mode, reads from~/.wt/sessions.json. When--modeis omitted, fall back to the resolved default fromConfig::load_for_repo.The helper must be silent on errors (exit 0 with empty output) so that a transient failure (no git repo, no tmux, missing session file) never breaks the user's prompt.
2. Per-shell wrappers. For each shell, augment the static completion script from #17 so that the three positional positions delegate to the helper:
_wtcompletion function, branch on the detected subcommand (use,rm,session rm) and callcompgen -W "$(wt __complete worktrees 2>/dev/null)" -- "$cur"for that positional._wtfunction, replace the value spec for the affected positionals with':worktree:_wt_worktrees', where_wt_worktreesis a small helper that runswt __complete worktreesand feeds_describe.complete -c wt -n "__fish_seen_subcommand_from use" -f -a "(wt __complete worktrees)"(and analogous lines forrmandsession rm) to the generated fish file.edit:completion:arg-completerthat delegates to the static map for known cases and calls the helper for the three target positions.The implementer may choose to (a) post-process
clap_completeoutput in Rust before emitting, or (b) emit a separate "dynamic addendum" file per shell that's sourced after the static one. Either is acceptable as long as #17's static behaviour is preserved and the acceptance criteria pass.3.
install.shintegration. No new install paths — the dynamic addendum lands in the same shell completion location as #17. If the addendum is a separate file/snippet, ensure idempotency on repeat runs (mirror the existinggrep -qguards).Acceptance criteria
wt __complete worktrees(hidden) prints one worktree name per line; output is empty (exit 0) when no worktrees exist or when run outside a git repo.wt __complete session-worktrees [--mode panes|windows](hidden) prints one worktree name per line for the resolved session mode; honours--modeoverride; exits 0 with empty output when no session exists.wt --helpand fromwt completions <shell>output.wt use <TAB>andwt rm <TAB>complete to the live worktree list.wt session rm <TAB>completes to the active session's worktrees.wt session --mode <TAB>still listspanesandwindows).session-worktreespanes mode) do not produce visible error output during tab completion.Blocked by
Out of scope
wt new <name>(free-form; could complete from local branch names but warrants a separate discussion).-b <branch>fromgit branchoutput (separate follow-up).