Open source, MIT licensed

Private HTTPS URLs for every git worktree

Each worktree's dev servers get their own addresses, such as https://api.feat-x.dev.example.com, behind a sign-in that only the people you allow can pass. Traffic goes through a tunnel server you run yourself.

  • Developers
    npm install --global @tafrahq/wt-tunnel-client
  • Whoever deploys the server
    npm install --global @tafrahq/wt-tunnel

Needs Node.js 26 or later. The CLIs run on Linux and macOS; any browser that trusts your root CA can open the URLs.

Two worktrees, four apps
feat-x
https://feat-x.dev.example.com
https://api.feat-x.dev.example.com
fix-login
https://fix-login.dev.example.com
https://api.fix-login.dev.example.com

Every app listens on 127.0.0.1. No ports in the URLs.

Several branches at once, one localhost

Git worktrees let you run several branches at once, but every dev server still lands on one machine.

  • Ports and cookies collide

    Every branch lands on localhost at some port. Ports clash, and cookies and OAuth redirects leak between branches.

  • Sharing means a public link

    Showing a branch to a teammate, a phone or a reviewer usually means a public tunnel that anyone with the link can open.

  • Certificates publish branch names

    Public certificate authorities log every certificate in Certificate Transparency logs, so a certificate per branch publishes every branch name.

How it works

The server is one container with Caddy, frps and a sign-in service. Each worktree runs one frpc that dials out to it, so the dev machine opens no port.

Tunnel serverFly.io or any hostDev machineworktree feat-xBrowserapp.feat-x.dev.example.comCaddyTLS from yourown root CAasks thesign-in servicefrpsroutes byhost namefrpcone perworktreeYour app127.0.0.1:4123HTTPStunneldialed outby frpcBrowserapp.feat-x.dev.example.comHTTPSTunnel serverFly.io or any hostCaddyTLS from your own root CAasks the sign-in servicefrpsroutes by host nametunnel, dialed outby frpcDev machineworktree feat-xfrpcone per worktreeYour app127.0.0.1:4123
A browser requests https://app.feat-x.dev.example.com. On the tunnel server, Caddy ends TLS with a certificate from your own root CA and asks the sign-in service whether the visitor is signed in. frps then routes the request by host name to the frpc that registered it. That frpc runs in the worktree on the dev machine, dialed out to the server, and passes the request to the app on 127.0.0.1:4123.
  1. *.dev.example.com points at the server. Caddy answers with a certificate it signs on demand from your root, for hosts under your dev domains only.
  2. Caddy asks the sign-in service about every request. Without a valid session cookie, the browser goes to the sign-in provider and back. The app never sees that cookie.
  3. frps hands the request to the frpc that registered that host name, and frpc passes it to the app on 127.0.0.1.

Host names

<app>.<worktree>.<domain>
Every app, for example api.feat-x.dev.example.com
<worktree>.<domain>
The app named root, for example feat-x.dev.example.com

What you get

Each worktree gets its own host names, behind your sign-in, on a server you run.

  • <app>.<worktree>

    One URL per worktree and app

    Run many branches side by side without port juggling. Each app gets its own host name, so cookies, OAuth redirects and CORS work as they do in production.

  • sign-in

    Sign-in in front of every URL

    Google, GitHub, Microsoft or Cloudflare Access, whichever you set up. Only the emails and email domains you allow get through, and one sign-in covers every worktree under a dev domain.

  • root CA

    No public certificates

    Dev hosts get certificates from your own root CA, name-constrained to your dev domains, so a device that trusts it trusts nothing else. Only the sign-in host appears in public logs.

  • frpc

    No device agent, no VPN

    Viewers need a browser and the root CA, trusted once. The dev machine needs no root access and opens no port: one frpc per worktree dials out to the server.

  • WebSocket

    WebSockets pass through

    WebSocket connections go through the tunnel, so Vite hot module reload works.

  • fly.io

    One config file to deploy

    wt-tunnel deploy creates the server on one Fly.io Machine from wt-tunnel.deploy.json. It creates the DNS records in Cloudflare, or lists them for you to create.

  • self-hosted

    Self-hosted and small

    The server is one container with Caddy, frps and the sign-in service. Deploy it with the CLI, or run the public image on any host.

  • MIT

    Open source

    MIT licensed. Read the code, run it and change it. Bug reports, fixes and ideas are welcome on GitHub.

Quick start

There are three roles. One person runs the server for a team, a repository adds a config file, and each developer installs the client.

  1. Install the CLIs you need

    The three CLIs are published to npm under @tafrahq. They need Node.js 26 or later, on Linux or macOS.

    • Developers
      npm install --global @tafrahq/wt-tunnel-client
    • Whoever deploys the server
      npm install --global @tafrahq/wt-tunnel
  2. Run a server

    You need a domain whose DNS you control, a Fly.io account, an OAuth client with at least one sign-in provider (Google, GitHub, Microsoft or Cloudflare Access), Node.js 26 or later, and openssl.

    mkdir my-wt-tunnel && cd my-wt-tunnel
    wt-tunnel init                      # writes a commented wt-tunnel.deploy.json
    $EDITOR wt-tunnel.deploy.json       # Fly app, hosts, dev domains, who may sign in, DNS zones
    export FLY_API_TOKEN=... GITHUB_CLIENT_ID=... GITHUB_CLIENT_SECRET=...   # or GOOGLE_*, MICROSOFT_*, CLOUDFLARE_ACCESS_*
    wt-tunnel deploy

    The first deploy creates .server/, which holds the server config, a new root CA and generated secrets. Back it up and never commit it. Then open https://auth-wt-tunnel.example.com/ca on each device to trust the root.

  3. Add wt-tunnel to a project

    Commit a wt-tunnel.json at the repository root:

    {
      "domain": "dev.example.com",
      "server": { "host": "wt-tunnel.example.com" },
      "apps": {
        "root": { "portEnv": "PORT" },
        "api": { "portEnv": "API_PORT" }
      }
    }

    The app labelled root gets https://<worktree>.dev.example.com, and every other app gets https://<app>.<worktree>.dev.example.com. Dev servers must listen on 127.0.0.1 at the port in their variable. Vite also needs server.allowedHosts: ['.dev.example.com'].

  4. Set up as a developer

    export WT_TUNNEL_SERVER_TOKEN=...   # tunnelToken from the server's .server/wt-tunnel-server.json
    git worktree add -b feat-x ../myapp-feat-x && cd ../myapp-feat-x
    wt-tunnel-client worktree add myapp feat-x
    eval "$(wt-tunnel-client env)"      # exports PORT, API_PORT and WT_TUNNEL_HOST
    npx vite --host 127.0.0.1 --port "$PORT" --strictPort   # for example

    Trust the root CA once per device, from the server's /ca page. wt-tunnel-client worktree remove stops the tunnel and releases the ports.

Read the full documentation on GitHub

See it run

Real output, with the server on the same machine and example.com names. A real setup deploys the server with wt-tunnel deploy.

Terminal recording: wt-tunnel prepare creates a server folder, wt-tunnel-server starts locally, wt-tunnel-client gives the worktree feat-x its URLs, and a browser request to it is redirected to sign-in.