Skip to content

feat(completions): ship dynamic registration for package installs - #3105

Merged
max-sixty merged 1 commit into
max-sixty:mainfrom
bendrucker:git-completions
Jun 18, 2026
Merged

max-sixty merged 1 commit into
max-sixty:mainfrom
bendrucker:git-completions

Conversation

@bendrucker

@bendrucker bendrucker commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

A plain package install of wt cannot complete branch or worktree names.

brew install worktrunk
# new shell
wt switch <TAB>     # subcommands and flags only, no branch names

I found that wt config shell completions <shell> emits a static clap_complete::generate() registration, and the homebrew-core formula bakes that into site-functions/_wt at install time via generate_completions_from_executable. The 0.58.0 binary shows:

$ wt config shell completions zsh | grep -c _arguments   # static _arguments calls
88
$ wt config shell completions zsh | grep -c COMPLETE     # dynamic runtime markers
0

That static _wt is what every Homebrew user has autoloaded by compinit. It completes subcommands and flags and has no mechanism to list branches.

Proposed Fix

wt config shell completions now emits a dynamic registration, the same script COMPLETE=<shell> wt already prints, which calls the binary at TAB time. The binary has always supported dynamic completion at runtime. The package path was simply wired to the wrong clap API: clap_complete::generate() is the legacy static path, and clap_complete::env is the maintained dynamic one. After this change a plain brew install completes branch and worktree names with zero config, matching what gh, rustup, kubectl, and docker ship via their packages.

Changes

  • Bash, Zsh, Fish, and PowerShell now emit dynamic registration via clap_complete::env. It reuses clap's maintained body rather than hand-rolling a completer. Nushell already emitted its full dynamic template, so it is unchanged.
  • make_zsh_autoload_safe rewrites clap's trailing compdef into a dual-mode guard. Homebrew installs the zsh script as site-functions/_wt and autoloads it from fpath, where the file body itself runs as the completion function. The guard completes directly when autoloaded and falls back to compdef when sourced. The display zstyles precede the guard so single-column listing applies on the first TAB.
  • The other shells need no transform. Homebrew sources bash files, autoloads fish completion files by command name, and PowerShell registrations are sourced into the profile.
  • Dropped a dead sed hack from templates/zsh.zsh. clap emits _describe -V natively, so the substitution matched nothing.
  • Reworded the Completions help text, which falsely claimed "static / only commands and flags."

Homebrew installs completions for bash, zsh, and fish. PowerShell is switched to dynamic for consistency, but no package manager installs its completions, so it applies only when a user sources it.

Why Not wt config shell install?

install does bind dynamic completion, but a package install never runs it and should not have to. install exists for cd-on-switch: its job is the wt() wrapper that lets wt switch change the shell's directory, and it does so by appending an eval "$(...)" line to ~/.zshrc or ~/.bashrc. Completion is incidental to it.

It only makes sense for Homebrew to run the completions command, since it's a pure function, no side effects. Changing the user's shell config during install would be unexpected.

Testing

Tested real shells with the completer present only via fpath autoload (no eval, no install):

  • zsh: wt switch <TAB> lists branch names on the first TAB, single-column.
  • bash (sourced, as Homebrew does): branches appear.
  • Dynamic value path (COMPLETE=zsh … wt switch '') still lists branches with recency markers.

Fish reuses the exact COMPLETE=fish wt mechanism that wt config shell install already ships, so it is proven in-tree. The strengthened test_completions_for_all_shells pins the dynamic registration structure for every shell.

Related

I hit this and worked around it locally by binding the dynamic completer by hand after compinit (bendrucker/dotfiles#493).

@bendrucker

Copy link
Copy Markdown
Contributor Author

Looking into the test fail

`wt config shell completions <shell>` emitted static clap_complete output
(subcommands and flags only). Package installs (Homebrew) use this path, so
`wt switch <TAB>` never completed branch or worktree names without first
running `wt config shell install`.

Emit a dynamic registration instead, reusing clap_complete::env for bash, zsh,
fish, and powershell -- the same script `COMPLETE=<shell> wt` prints, which
calls the binary at TAB time. Branch and worktree completion (already
implemented via the dynamic completers) now works from a plain package install.
Nushell already emitted its full dynamic template and is unchanged.

Zsh needs a thin transform (make_zsh_autoload_safe) so the script works when
autoloaded from fpath as site-functions/_wt: clap's trailing `compdef` is
replaced with a dual-mode guard that completes directly when autoloaded and
registers via compdef when sourced. The display zstyles precede the completer
so single-column listing applies on the first TAB. The other shells need no
transform: Homebrew sources bash files, autoloads fish completion files by
command name, and powershell registrations are sourced into the profile.

Also drop a dead `sed` hack from templates/zsh.zsh: clap emits `_describe -V`
natively, so the substitution matched nothing.

The homebrew-core `worktrunk` formula already calls
generate_completions_from_executable(bin/"wt", "config", "shell",
"completions"), which writes the bash, zsh, and fish output to the shells'
default completion directories. So this change flows through on the next
release/bottle build with no formula edit. Homebrew does not install powershell
completions; that shell is switched for consistency and applies when sourced.
@max-sixty

Copy link
Copy Markdown
Owner

thank you very much @bendrucker !

so I understand: does this only change behavior for those who install with brew and don't install the shell integration?

(or @worktrunk-bot feel free to opine)

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Yes — that's the right framing. The behavioral change lands on exactly one population: users who get wt from a package manager and never run wt config shell install.

Walking the three things this PR touches:

  1. wt config shell completions <shell> (the package-manager path — what Homebrew bakes into site-functions/_wt via generate_completions_from_executable). This flips from a static clap_complete::generate() registration to a dynamic clap_complete::env one. This is the actual behavior change. Before: subcommands and flags only. After: branch and worktree names complete at TAB time, with zero config. So a plain brew install worktrunk now behaves like gh/rustup/kubectl do from their packages.

  2. The integration path (wt config shell install / init). Unaffected behaviorally — these users already had dynamic, branch-aware completion via the eval "$(COMPLETE=zsh … wt)" line. The only edit here is dropping the sed "s/_describe 'values'/_describe -V 'values'/" hack from templates/zsh.zsh. I verified that substitution is dead: the binary now emits _describe -V 'values' natively —

    $ COMPLETE=zsh wt | grep _describe
        [[ -n $dirs ]] && _describe -V 'values' dirs -S '/' -r '/'
        [[ -n $other ]] && _describe -V 'values' other
    

    so the sed matched nothing and recency ordering is preserved without it. Inert cleanup, not a behavior change for these users.

  3. Help text for the hidden Completions subcommand — wording only.

One nuance worth stating: it's not strictly "brew users." It's anyone whose install pipeline runs wt config shell completions and autoloads/sources the result without also running install — Homebrew (bash/zsh/fish) today, plus any future packaging that does the same. PowerShell is switched too for consistency, but since no package manager installs PS completions, that only takes effect if someone sources it manually.

Net: strict improvement for the package-install-only crowd (they gain branch completion), no-op for everyone who ran install. CI is fully green now.

Comment thread src/commands/init.rs
r#"# Single-column display keeps descriptions visually associated with each branch.
zstyle ':completion:*:{cmd_name}:*' list-max 1
# Prevent grouping branches with identical descriptions (same timestamp) on one line.
zstyle ':completion:*:*:{cmd_name}:*' list-grouped false

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@worktrunk-bot confirm whether these are necessary

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary for completion to work — branches complete fine without them. They're a display-parity measure, copied verbatim from templates/zsh.zsh:86,89 so a package-install user sees the same listing as someone who ran wt config shell install.

What each does:

  • list-max 1 — forces single-column. Without it zsh's default packs candidates into multiple columns.
  • list-grouped false — stops zsh collapsing branches that share a description onto one line. Branch descriptions encode recency (-- + 12m), so several branches last touched ~12m ago would otherwise render grouped as release main -- + 12m instead of one branch per line. (That's the exact case the template comment at zsh.zsh:88 calls out.)

So: drop them and completion still functions, but the listing regresses to multi-column + grouped, diverging from the install path.

One maintenance note while we're here: these zstyles now live in two places — templates/zsh.zsh and this hardcoded string in make_zsh_autoload_safe. test_completions_for_all_shells pins their presence and that they precede the guard, but not that they stay identical to the template, so the two could drift. Minor, but worth a comment cross-referencing the template if we want to keep them locked together.

@max-sixty

Copy link
Copy Markdown
Owner

ok, great! it seems like a nice improvement + some simplification, even if most folks have the shell integration installed?

@max-sixty
max-sixty merged commit ad43df7 into max-sixty:main Jun 18, 2026
39 checks passed
@max-sixty max-sixty mentioned this pull request Jun 18, 2026
max-sixty added a commit that referenced this pull request Jun 18, 2026
Release v0.60.0 (minor bump from 0.59.0).

Minor because semver-checks flagged a breaking library-API change and
five new features landed since v0.59.0. The data-loss surface review (4
independent finders) cleared the one change that touches it (relocating
dirty linked worktrees, #3104).

### Improved
- Package installs now complete branch/worktree names via dynamic
registration (#3105, thanks @bendrucker)
- `wt step relocate` moves dirty linked worktrees (#3104, thanks
@lunaynx for reporting)
- `--dry-run` previews print to stdout (#3085)
- Picker gutter distinguishes local (`/`) and remote (`|`) branches
(#3115)
- `wt list --format=json` gains structured `repo`/`ci.repo` metadata
(#3021, thanks @jeremy0dell)
- `wt step eval --format=json` (#3106)
- `--format=claude-code` rejected on `wt list` / `wt config state get`
(#3116)

### Fixed
- `cargo install worktrunk` builds from crates.io again (#3124, fixes
#3123, thanks @kerrickstaley for reporting)
- Tab-completion works in repos with no commits (#3097, closes #3094)
- `wt config state get ci-status --format=json` honors
`[forge].platform` (#3120)

### Documentation
- `wt list --help` example tables fit the terminal (#3125)
- `/wt-switch-create` cross-repo handling reworked (#3118)
- Help-text and web-doc refinements (#3096, #3108, #3110, #3112, #3126)

Full notes in `CHANGELOG.md`.

> _This was written by Claude Code on behalf of max_
@bendrucker

Copy link
Copy Markdown
Contributor Author

Yep, I of course have the shell integration installed but found the dynamic completions were clobbered by the presence of the static ones from Homebrew.

@bendrucker
bendrucker deleted the git-completions branch June 18, 2026 22:07
@max-sixty

Copy link
Copy Markdown
Owner

Yep, I of course have the shell integration installed but found the dynamic completions were clobbered by the presence of the static ones from Homebrew.

ah!! that seems bad indeed...

are you on zsh? I wonder if it's some ordering thing there.

regardless: now fixed!

@bendrucker

Copy link
Copy Markdown
Contributor Author

Yes, zsh, and yes related to ordering.

social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
worktrunk 0.60.0

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## Release Notes

### Improved

- **Package installs complete branch and worktree names**: A plain `brew install worktrunk` (or other package install) now tab-completes branch and worktree names, not just subcommands and flags. `wt config shell completions <shell>` emits a dynamic registration that calls the binary at completion time (the maintained `clap_complete::env` path), matching what `gh`, `rustup`, and `kubectl` ship. ([#3105](max-sixty/worktrunk#3105), thanks @bendrucker)

- **`wt step relocate` moves dirty linked worktrees**: Relocating a linked worktree with uncommitted or untracked changes no longer skips it. `git worktree move` carries those files along, so the dirty-skip was a worktrunk policy rather than a git limitation. The main worktree still skips when dirty (without `--commit`), since its relocation falls back to `git checkout`, which refuses to switch over a dirty tree. ([#3104](max-sixty/worktrunk#3104), thanks @lunaynx for reporting)

- **`--dry-run` previews print to stdout**: `wt hook <type>`, `wt step relocate`, `wt step prune`, `wt step copy-ignored`, and `wt config shell install`/`uninstall` now send their `--dry-run` preview to stdout (the command's answer) while narration stays on stderr. This matches `wt list`, `git clean -n`, and `terraform plan`, and keeps previews pageable and pipeable. (Breaking: scripts reading these previews from stderr should now read stdout) ([#3085](max-sixty/worktrunk#3085))

- **Picker gutter distinguishes local and remote branches**: With `--branches` and `--remotes`, the `wt switch` picker marks each row's kind in the gutter: `/` for a local branch without a worktree and `|` for a remote branch, alongside the existing `@`/`^`/`+` worktree glyphs. ([#3115](max-sixty/worktrunk#3115))

- **`wt list --format=json` gains structured `repo` metadata**: JSON output adds `repo` (the local checkout's primary remote) and `ci.repo` (the repository `ci.url` targets, which differs for fork PRs) objects carrying `host`/`owner`/`name`/`provider`; the existing `repo_url` and `ci.repo_url` strings remain. The provider honors the configured `[forge].platform` on hosts that can't be auto-detected. ([#3021](max-sixty/worktrunk#3021), thanks @jeremy0dell)

- **`wt step eval --format=json`**: `wt step eval` gains a structured `{name, template, result}` JSON lane on stdout, the machine-readable analog of its `-v` view. Text mode is unchanged. ([#3106](max-sixty/worktrunk#3106))

- **`--format=claude-code` rejected where it never applied**: `wt list` and `wt config state get` accepted `--format=claude-code` silently and treated it as `table`; the value only ever meant anything on `wt list statusline`. Both now fail fast with `invalid value 'claude-code'`. (Breaking: `wt list --format=claude-code` and `wt config state get --format=claude-code` now error) ([#3116](max-sixty/worktrunk#3116))

### Fixed

- **`cargo install worktrunk` builds from crates.io**: Installing from crates.io failed to compile with `environment variable VERGEN_GIT_DESCRIBE not defined at compile time`, because the package archive has no `.git` for the build script to read. The version lookup now falls back to the cargo package version when git-describe is unavailable. ([#3124](max-sixty/worktrunk#3124), fixes [#3123](max-sixty/worktrunk#3123), thanks @kerrickstaley for reporting)

- **Tab-completion works in repos with no commits**: `wt switch <TAB>` and `wt remove <TAB>` returned nothing on a fresh `git init` repo, because the unborn default branch has no entry under `refs/heads/`. Completion now also draws on worktree branches, so the unborn `main` (and any `wt switch --create` branch on an empty repo) completes. ([#3097](max-sixty/worktrunk#3097), closes [#3094](max-sixty/worktrunk#3094))

- **`wt config state get ci-status --format=json` honors `[forge].platform`**: On a self-hosted host the parser can't recognize (Gitea, Azure DevOps, GitHub Enterprise on a generic domain), this path reported `provider: "unknown"` while `wt list --format=json` reported the configured provider. All structured-output paths now route the `[forge].platform` override through one accessor, so they stay consistent. ([#3120](max-sixty/worktrunk#3120))

### Documentation

- **`wt list --help` example tables fit the terminal**: The captured `wt list` example tables in `--help` chop to terminal width with a dimmed ellipsis (matching real `wt list`) instead of word-wrapping and shearing their columns; hand-authored command examples still wrap. ([#3125](max-sixty/worktrunk#3125))

- **`/wt-switch-create` cross-repo handling reworked**: The Claude Code plugin command's skill reworks how it creates and enters a worktree in another repo, built around what the harness actually does (`EnterWorktree` re-roots within the current repo; a `cd` reaches another repo when it's in `additionalDirectories`). The procedure dropped from five steps to three. ([#3118](max-sixty/worktrunk#3118))

- **Help-text and docs refinements**: `--format` help renders its values inline (`[possible values: table, json]`) instead of an expanded block; `wt switch` and `wt step push` help got smaller clarifications; and web-doc terminal blocks no longer wrap command-only lines. ([#3096](max-sixty/worktrunk#3096), [#3108](max-sixty/worktrunk#3108), [#3110](max-sixty/worktrunk#3110), [#3112](max-sixty/worktrunk#3112), [#3126](max-sixty/worktrunk#3126))

## Install worktrunk 0.60.0

### Install prebuilt binaries via shell script

```sh
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/max-sixty/worktrunk/releases/download/v0.60.0/worktrunk-installer.sh | sh && wt config shell install
```

### Install prebuilt binaries via powershell script

```sh
powershell -ExecutionPolicy Bypass -c "irm https://github.com/max-sixty/worktrunk/releases/download/v0.60.0/worktrunk-installer.ps1 | iex"; git-wt config shell install
```

### Install prebuilt binaries via Homebrew

```sh
brew install worktrunk && wt config shell install
```

## Download worktrunk 0.60.0

|  File  | Platform | Checksum |
|--------|----------|----------|
| [worktrunk-aarch64-apple-darwin.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.60.0/worktrunk-aarch64-apple-darwin.tar.xz) | Apple Silicon macOS | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.60.0/worktrunk-aarch64-apple-darwin.tar.xz.sha256) |
| [worktrunk-x86_64-apple-darwin.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.60.0/worktrunk-x86_64-apple-darwin.tar.xz) | Intel macOS | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.60.0/worktrunk-x86_64-apple-darwin.tar.xz.sha256) |
| [worktrunk-x86_64-pc-windows-msvc.zip](https://github.com/max-sixty/worktrunk/releases/download/v0.60.0/worktrunk-x86_64-pc-windows-msvc.zip) | x64 Windows | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.60.0/worktrunk-x86_64-pc-windows-msvc.zip.sha256) |
| [worktrunk-aarch64-unknown-linux-musl.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.60.0/worktrunk-aarch64-unknown-linux-musl.tar.xz) | ARM64 MUSL Linux | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.60.0/worktrunk-aarch64-unknown-linux-musl.tar.xz.sha256) |
| [worktrunk-x86_64-unknown-linux-musl.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.60.0/worktrunk-x86_64-unknown-linux-musl.tar.xz) | x64 MUSL Linux | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.60.0/worktrunk-x86_64-unknown-linux-musl.tar.xz.sha256) |



### Install via Cargo

```sh
cargo install worktrunk && wt config shell install
```

### Install via Winget (Windows)

```sh
winget install max-sixty.worktrunk && git-wt config shell install
```

### Install via AUR (Arch Linux)

```sh
paru worktrunk-bin && wt config shell install
```
</pre>
  <p>View the full release notes at <a href="https://github.com/max-sixty/worktrunk/releases/tag/v0.60.0">https://github.com/max-sixty/worktrunk/releases/tag/v0.60.0</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!11933
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants