GitHub Enterprise: `wt switch <PR URL>` ignores the URL's host, and the 404 hint points at `gh repo set-default` instead of `forge.hostname`
Problem
On a GitHub Enterprise host, wt switch pr:N and wt switch <PR URL> fail with a 404 unless forge.hostname is configured. The error hint points at gh repo set-default, which is already correct, so the cause is hard to find.
Setup
- worktrunk 0.81.0 (Homebrew), gh 2.103.3, macOS
- Remote:
https://github.example.com/acme/app ghis logged in to bothgithub.comandgithub.example.comgh repo set-default --view→acme/app- No
[forge]block in the repo, no[projects."github.example.com/*"]entry in user config
What happens
$ wt switch https://github.example.com/acme/app/pull/62
◎ Fetching PR #62...
✗ PR #62 not found on acme/app (gh default). Check that `gh repo set-default` points to the correct repository.
gh: Not Found (HTTP 404)
A gh wrapper on PATH shows the calls:
gh repo set-default --view
gh api repos/acme/app/pulls/62
There is no --hostname, so gh api sends the request to github.com. gh pr view 62 in the same checkout works, because gh pr resolves the host from the remote.
This matches the current code: fetch_pr_info in src/git/remote_ref/github.rs passes --hostname only when forge.hostname is configured. #1826 made that change on purpose to fix SSH aliases (#1790), and it removed the host detection that #1408 added.
Workaround
# ~/.config/worktrunk/config.toml
[projects."github.example.com/*"]
forge.platform = "github"
forge.hostname = "github.example.com"
With this, wt runs gh api repos/acme/app/pulls/62 --hostname github.example.com, and the same call with that host returns the PR.
Suggestions
- Use the PR URL's host. When the argument is a PR URL (#2896), the user has already named the host. If
forge.hostnameis unset, pass the URL's host as--hostname. A web URL carries the real host, not an SSH alias, so this does not bring back #1790. - Point the 404 hint at
forge.hostname. Whenforge.hostnameis unset and the remote's host is notgithub.com, the hint could nameforge.hostname(and the[projects."<host>/*"]user-config form) as a likely cause, next to thegh repo set-defaulthint. Here the hint sent me togh repo set-default, which was already correct.
Opened by claude-opus-5-5 on behalf of @pgilad-rna
I opened #4710 to fix the main failure. With no forge.hostname, the PR lookup now passes the GitHub remote's host as --hostname when gh auth token --hostname <host> shows gh is logged in to it. In your setup, wt switch pr:62 and the PR URL should then call gh api repos/acme/app/pulls/62 --hostname github.example.com with no config change. An SSH alias like github-personal has no gh login, so it still goes to gh's default host, and the #1790 fix stays intact. A regression test covers both cases. CI and maintainer review are still pending.
The PR leaves two parts of your report open:
- The 404 hint. It could name
forge.hostname, which would still help whenghisn't logged in to the Enterprise host. That hint is new user-facing output, so I've left it for a maintainer to decide. - The PR URL's host. The lookup doesn't use it yet. Your remote's host and the URL's host are the same, so #4710 already covers your case.
Until #4710 merges, your [projects."github.example.com/*"] workaround is the right setting.
#4710 has merged as 79f19f640. With no forge.hostname set, wt switch pr:N and the PR URL form now pass the GitHub Enterprise remote's host to gh api whenever gh is logged in to that host. That covers your setup, and it ships in the next release after v0.81.0. Until that release, keep the [projects."github.example.com/*"] workaround.
The 404 hint naming forge.hostname, and using the PR URL's own host, are still open here.
Opened https://github.com/max-sixty/worktrunk/pull/4722 for the URL-host part: a GitHub /pull/N URL now supplies gh api --hostname when gh is logged in there. The 404 hint is unchanged.
Both suggestions in this issue have now merged:
- PR URL host — #4722 (in v0.82.0):
wt switch <GitHub PR URL>passes the URL's host togh api --hostnamewhenghis logged in there. - 404 hint — #4734 (merged after v0.83.0, so it ships in the next release): a 404 on an Enterprise PR URL with no API host selected names the host for
gh auth loginand points atforge.hostnamewhen the API host differs, instead of onlygh repo set-default.
Together with #4710 (remote host passed when gh is logged in to it), that covers the setup described here. I'm leaving the issue open for a maintainer to close.
Closing: all three parts of this report are on main — #4710 (remote host passed to gh api --hostname), #4722 (PR URL host, released in v0.82.0) and #4734 (404 hint pointing at forge.hostname, ships in the release after v0.83.0). If something in your setup still fails after upgrading, let us know and we'll reopen.