Every Git worktree gets its own URL.
Local hostnames, webhooks and OAuth callbacks, routed to the right checkout.
Install · Quick start · Usage · Configuration · Webhooks & OAuth · FAQ
Working on three branches at once in three worktrees, or with three AI agents? Each one still wants localhost:3000, the same cookie domain, the same Stripe webhook URL and the same OAuth redirect URI.
wtg gives each worktree a stable identity and routes traffic to it:
~/src/shop (main) → https://main.shop.localhost:8743 (also https://shop.localhost:8743)
~/src/shop.auth (feature/auth) → https://feature-auth.shop.localhost:8743
└─ api service → https://api.feature-auth.shop.localhost:8743
Stripe → https://<tunnel>/w/feature-auth/webhooks/stripe → feature/auth worktree
GitHub login → https://<tunnel>/_wg/oauth/callback → whichever worktree started it
- 🌐 A URL per worktree.
{branch}.{project}.localhostover HTTP and HTTPS. No/etc/hostsedits, no root. - 🔢 No port juggling. Every service gets a stable, collision-free
$PORT, and URLs stay the same across restarts. - 🧩 Many services per worktree.
web,api,docs… each with its own hostname andWG_*_URLenv var. - 🔄 Follows git. New, removed, renamed and moved worktrees are picked up automatically.
- 🪝 Webhooks into any worktree. One tunnel for all of them, with only the paths you allowlist exposed.
- 🔐 One OAuth redirect URI for every worktree. Signed state sends each login back to the right checkout.
- 🔁 Webhook replay. Inspect captured requests (credentials redacted) and re-send them to any worktree.
- 🧱 Built on proven tools. Caddy does the routing, and cloudflared or ngrok do the tunnelling. Pairs with Worktrunk.
macOS / Linux (recommended)
curl -fsSL https://raw.githubusercontent.com/chryzxc/worktree-gateway/main/install.sh | shThis downloads the latest release, verifies its checksum and installs wtg to ~/.local/bin. Set WTG_INSTALL_DIR to install somewhere else, or WTG_VERSION=v0.1.0 to pin a version. The script is short; read it before piping it to sh if you prefer.
Other methods
Download a release manually. Grab wtg_<version>_<os>_<arch>.tar.gz from Releases, extract it, and put wtg on your PATH.
With Go 1.26+:
go install github.com/chryzxc/worktree-gateway/cmd/wtg@latestFrom source:
git clone https://github.com/chryzxc/worktree-gateway && cd worktree-gateway && make installShell completion (bash, zsh, fish, PowerShell):
echo 'source <(wtg completion zsh)' >> ~/.zshrc # zsh
echo 'source <(wtg completion bash)' >> ~/.bashrc # bash
wtg completion fish > ~/.config/fish/completions/wtg.fishCheck your setup:
wtg doctorUpgrading: run the installer again, then wtg daemon restart so the background daemon picks up the new version. wtg warns you when the daemon and the CLI versions differ.
Uninstalling: wtg daemon stop && wtg untrust, then delete ~/.local/bin/wtg, ~/.config/worktree-gateway and ~/.local/state/worktree-gateway.
cd ~/src/shop
wtg init # writes wtg.yaml (guesses your dev command)
wtg run # starts it on a stable $PORT and routes it
wtg open # → https://main.shop.localhost:8743
wtg trust # once: trust the local HTTPS certificateNow add a second worktree. Any tool works:
git worktree add ../shop.auth -b feature/auth
cd ../shop.auth && wtg run
# wtg: feature-auth/web on port 24817 → https://feature-auth.shop.localhost:8743Both run side by side, each on its own URL:
$ wtg status
WORKTREE BRANCH SERVICE STATUS UPSTREAM URL
main (main) main web up 127.0.0.1:21853 https://main.shop.localhost:8743
feature-auth feature/auth web up 127.0.0.1:24817 https://feature-auth.shop.localhost:8743Remove the worktree with git worktree remove and its routes disappear.
Tip
Your dev server must listen on $PORT. Most frameworks (Next.js, Express, Rails, Django, Phoenix…) read it automatically. Vite needs vite --port $PORT.
wtg run # the default service, command from wtg.yaml
wtg run api -- go run ./cmd/api # any command; gets PORT and WG_* env
wtg register db-admin --port 8081 # route something you started yourselfwtg run starts the daemon and registers the worktree automatically; no separate wtg up, wtg port or wtg env step is needed. Run it again to replace that service without stopping its siblings.
It injects identity env vars. Apps use them to build absolute URLs and to find their sibling services:
WG_URL=https://feature-auth.shop.localhost:8743
WG_API_URL=https://api.feature-auth.shop.localhost:8743
WG_WORKTREE=feature-auth WG_BRANCH=feature/auth PORT=24817Use eval "$(wtg env)" to load the same variables into your shell. The full list is in the configuration docs.
# wtg.yaml
project: shop
services:
web:
command: npm run dev
api:
command: go run ./cmd/api
health: /healthzweb is served at feature-auth.shop.localhost and api at api.feature-auth.shop.localhost. All options are in the configuration reference.
services:
web:
public:
paths: [/webhooks] # the only paths reachable from the internetwtg tunnel start # needs cloudflared (default) or ngrok
wtg status # public: https://abc.trycloudflare.com/w/feature-authPoint Stripe at https://abc.trycloudflare.com/w/feature-auth/webhooks/stripe. Then inspect and replay what arrived:
wtg requests
wtg replay req_1a2b3c4d --yes
wtg replay req_1a2b3c4d --to main --yes # send it to another worktreeRegister one redirect URI with your provider. The gateway sends each callback back to the worktree that started the login, using signed state. See docs/webhooks-and-oauth.md for the Node and Go snippets.
wtg hooks worktrunk --write # new worktrees register themselves; removal cleans up| Command | Description |
|---|---|
wtg init |
Create a starter wtg.yaml |
wtg run [svc] [-- cmd…] |
Run a dev server with $PORT and identity env, routed while it runs; replaces a previous run of the same service |
wtg stop [svc] |
Stop the worktree's wtg run servers (all, or one) and drop their routes |
wtg open [svc] |
Open the worktree's URL in the browser |
wtg status [-a] [--json] |
Worktrees, services, health and URLs |
wtg up / wtg down [--forget] |
Register a worktree or take its routes down (usually automatic) |
wtg register <svc> --port N / wtg deregister <svc> |
Route a process you started yourself |
wtg env [svc] / wtg port [svc] |
Print identity exports or the stable port |
wtg tunnel start|stop|status |
Opt-in public exposure |
wtg requests [id] / wtg replay <id> |
Inspect and replay webhook traffic |
wtg oauth state --callback /path |
Mint a signed OAuth state |
wtg trust / wtg untrust |
Install or remove the local HTTPS CA |
wtg doctor · wtg hosts · wtg hooks worktrunk |
Diagnostics and integrations |
wtg daemon start|stop|restart|status |
Background daemon (auto-started) |
wtg completion <shell> |
Shell completion script |
Run wtg <command> --help for flags and examples.
wtg CLI ──unix socket──► wtg daemon ─┬─ registry projects → worktrees → services
├─ discovery git worktree list (add/remove/rename/move)
├─ health checks process + port / HTTP probe
├─ Caddy ─────────► :8780 http · :8743 https (local CA)
└─ ingress :8790 ◄─ cloudflared / ngrok (only when you start a tunnel)
A worktree's identity comes from git itself, so moving the worktree or renaming its branch doesn't break it. Every change rebuilds Caddy's config and reloads it with no downtime. The ingress only forwards allowlisted paths to registered loopback services. The design and the trade-offs are in docs/PLAN.md.
wtg is a local development tool and is safe by default:
- Nothing is reachable from outside until you run
wtg tunnel start. After that, only the paths inpublic.pathsare reachable. - It only forwards to registered services on loopback, so it cannot act as an open proxy or be used for SSRF.
- OAuth state is HMAC-signed, expires, can only be used once, and must match a path you allowlisted.
- The request log is size- and time-bounded, redacts credentials, is readable only by you, and can skip bodies.
- The control API is a user-only unix socket. There is no root access,
/etc/hostsis never edited, and the CA is trusted only when you runwtg trust.
The details and how to report a vulnerability are in SECURITY.md.
Why wtg and not wg?
wg is WireGuard's CLI. The environment variables keep the WG_ prefix.
Why port 8743 instead of 443?
Binding ports below 1024 needs root, and wtg never asks for it. To use https://feature-auth.shop.localhost without a port, run your own Caddy on 443 and set proxy.provider: caddy-admin. wtg then pushes its routes to that Caddy instead.
A tool can't resolve *.localhost.
Browsers and most systems resolve it to loopback (RFC 6761). For tools that don't, wtg hosts prints /etc/hosts lines you can add, or use curl --resolve host:8743:127.0.0.1.
How does this compare to Portless, Portree or Worktrunk?
Portless gives apps *.localhost names with its own proxy. Portree supervises processes per worktree. Worktrunk creates and manages worktrees, and works well with wtg.
wtg treats a worktree, with all of its services, as one identity tracked from git. It adds external webhook and OAuth routing plus replay, and it builds on Caddy rather than its own proxy. The full comparison is in docs/PLAN.md.
Does it restart my crashed dev server?
No. wtg is not a process supervisor. When a service dies, its route shows "service not running", and public webhook requests are held briefly (then answered 503) so providers retry.
Something isn't working.
Run wtg doctor, then check ~/.local/state/worktree-gateway/daemon.log. Common fixes:
| Symptom | Fix |
|---|---|
| Browser certificate warning | wtg trust (restart Firefox) |
the running daemon is vX but this binary is vY |
wtg daemon restart after upgrading |
address already in use |
change http_port / https_port / ingress.port in ~/.config/worktree-gateway/config.yaml |
Service stuck on starting |
your server isn't listening on $PORT |
| Webhook 404 through the tunnel | the path isn't in public.paths, or the worktree name is wrong (wtg status) |
| Replayed webhook fails its signature check | expected: signature headers are redacted, so detect X-Wg-Replay: 1 in test mode |
- Local identity and routing, health, discovery, Worktrunk hooks
- Multi-service, env injection, HTTPS, tunnels, opt-in exposure
- Webhook routing, request log, replay, signed OAuth callbacks
- Homebrew tap
- Windows support (it builds, but is untested)
-
wtg ui: a local dashboard for requests and routes
Contributions are welcome. See CONTRIBUTING.md for the dev setup (make build test lint) and the project's non-goals. Changes are tracked in CHANGELOG.md.
MIT © 2026 Christian Rey Villablanca