Skip to content

fix(plugin): /wt-switch-create guesses whether a bare name is the repo or the branch - #4159

Merged
max-sixty merged 2 commits into
mainfrom
wt-switch-create-path-entry
Sep 17, 2026
Merged

max-sixty merged 2 commits into
mainfrom
wt-switch-create-path-entry

Conversation

@max-sixty

@max-sixty max-sixty commented Sep 17, 2026 •

Copy link
Copy Markdown
Owner

A bare token like worktrunk passed to /wt-switch-create could name a repository or a branch, and nothing in the invocation says which. The grammar read every non-path token as the branch, so /wt-switch-create worktrunk -- … from a directory outside any repo, or prql -- … from a worktrunk worktree, took the repo name as a branch (or asked).

The skill now makes an informed guess:

  • A name the current repo already has a branch for is that branch, matching how wt switch resolves a branch before a path ("a directory never shadows a branch sharing its name", after_long_help in src/cli/mod.rs).
  • Otherwise it's the repo when a git repository by that name exists where the user keeps repos (beside the current repo, or in a workspace directory like ~/workspace), and the branch when none does. A subdirectory of the current repo stays a branch: docs is not the docs/ directory.
  • A name read as the repo carries its absolute path forward, since step 3 substitutes it into wt -C <repo> and cd <repo>, both of which take a directory rather than a name.

Two tokens that both read as branches still ask.

Testing

An A/B test gave the old and new passages the same scenarios, with the filesystem facts stated, 2 runs each:

Arguments Old New
worktrunk -- … from ~ (not a repo) branch worktrunk, asks repo ~/workspace/worktrunk
prql -- … from a worktrunk worktree branch prql repo ~/workspace/prql
fix-parser prql -- … asks branch fix-parser, repo prql
docs -- … (subdirectory only) branch branch
fix-auth -- … branch branch

The new wording read all 10 runs as intended. The revised passage was re-run on the repo, subdirectory and no-match cases, plus the collision the review raised — a local docs branch alongside a ~/workspace/docs repository, where the branch wins — for 8 further runs, all as intended.

Not exercised: a live session that has to find the repository on disk before guessing.

This was written by Claude Code on behalf of max-sixty

🤖 Generated with Claude Code

…o or the branch

A bare token like `worktrunk` could name a repository or a branch, and
the old grammar always read it as a branch, so an invocation from outside
the repo (or naming a sibling repo) created a branch in the wrong place
or asked. The skill now reads a bare name as the repo when a git
repository by that name exists where the user keeps repos, and as the
branch otherwise; a subdirectory of the current repo stays a branch.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

@worktrunk-bot worktrunk-bot left a comment

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.

Two things on the new bare-name rule.

A guessed repo name never reaches the commands that consume it. The
grammar bullet now reads "optional path or name", but step 3 substitutes
<repo> into wt -C <repo> and cd <repo>, and wt's -C is a
working-directory path (Cli::directory in src/cli/mod.rs —
value_name = "path", Option<PathBuf>) resolved against the cwd. So
/wt-switch-create prql -- … from ~/workspace/worktrunk classifies prql
as the repo and then runs wt -C prql, which fails, and step 3's handling for
that is "Any other failure (not a git repo, invalid name): report it and
stop." The guess already had to locate the repository on disk, so the fix is
to say that resolved path is what carries forward — suggestion inline. This is
exactly the path the PR notes as unexercised ("a live session that has to find
the repository on disk before guessing"), which is what makes it worth pinning
in the prose rather than leaving to the model.

A bare name that is also a local branch has no tiebreak. The repo reading
wins unconditionally, so in a ~/workspace holding docs, api, cli, an
invocation like /wt-switch-create docs -- update the install page targets
~/workspace/docs with a branch name picked from the task, instead of
creating a docs branch here — and nothing in the output says which reading
it took. Naming an existing branch is supported usage (step 3 handles
Branch <branch> already exists by rerunning without --create), and
git show-ref --verify --quiet refs/heads/<name> is a cheaper check than the
workspace scan. Deferring to the branch would also match worktrunk's own
tiebreak for this shape of ambiguity — after_long_help in src/cli/mod.rs
says a path is "resolved after the branch, so a directory never shadows a
branch sharing its name". Your call whether the skill should follow that or
ask; the A/B table doesn't cover the collision.

Comment thread skills/wt-switch-create/SKILL.md Resolved
…g branch win

Review findings on the bare-name rule: a guessed name was never resolved
to a path, though step 3 substitutes it into `wt -C <repo>` and
`cd <repo>`, which take a directory; and a name that is already a branch
here lost to a same-named repo. The guess now carries the repository's
absolute path forward, and an existing branch wins, matching how
`wt switch` resolves a branch before a path.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit a2f1497 into main Sep 17, 2026
41 checks passed
@max-sixty
max-sixty deleted the wt-switch-create-path-entry branch September 17, 2026 01:53
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.

2 participants