# Port conflicts between many dev servers: named local URLs (portless) Use when several agents/worktrees run dev servers on one Mac and ports collide, or when setting a convention so agents stop inventing ports. ## Decide the mechanism - Prefer a tool that assigns the port, registers the route and removes it on exit by itself (portless: `portless ` -> `http://.localhost:`). A reverse proxy with a hand-edited host->port file (Caddy, Traefik) turns that file into a manual port registry that drifts; use it only for services portless cannot wrap. - Embed it in the project's own dev script (`"dev": "portless fibi next dev"`) so agents follow the rule without remembering a tool. - Keep fixed system ports (gateway, dashboards, live apps behind `tailscale serve`) outside it. ## No-sudo, no-trust-store setup (test or permanent) portless needs Node 24+. Do not upgrade the system Node; run portless with its own Node: ```bash D=; cd $D F=$(curl -s https://nodejs.org/dist/latest-v24.x/SHASUMS256.txt | grep -oE "node-v24[0-9.]+-darwin-arm64.tar.gz" | head -1) curl -sO https://nodejs.org/dist/latest-v24.x/$F curl -s https://nodejs.org/dist/latest-v24.x/SHASUMS256.txt | grep " $F" | shasum -a 256 -c tar xzf $F && mv ${F%.tar.gz} node24 export PATH=$D/node24/bin:$PATH && npm init -y >/dev/null && npm i portless export PORTLESS_PORT=1355 PORTLESS_HTTPS=0 PORTLESS_SYNC_HOSTS=0 # + PORTLESS_STATE_DIR=$D/state for an isolated test ``` - Defaults to avoid unless the user approves: proxy on 443 (auto-elevates with sudo), a local CA added to the system trust store, `/etc/hosts` sync. The env vars above turn all three off; `.localhost` resolves without hosts entries on macOS. - `--tailscale` mounts apps on tailnet ports 443, then 8443, 8444...; check `tailscale serve status` first, those ports may already belong to live apps. - Use a separate `PORTLESS_STATE_DIR` and proxy port when another agent may be testing portless at the same time (the default state dir is `~/.portless`). ## Example permanent install - A small wrapper script on PATH (e.g. `/portless`) that runs portless's `dist/cli.js` with its own Node 24, pins `PORTLESS_PORT=`, `PORTLESS_HTTPS=0`, `PORTLESS_SYNC_HOSTS=0`, `PORTLESS_STATE_DIR=`, and refuses `--tailscale/--funnel/--ngrok/--cloudflare/--lan` (they would grab tailnet ports that live apps may already use). Install into a temp name and `mv` into place. - Pin `PORTLESS_STATE_DIR` in the wrapper: leftover `PORTLESS_*` vars from an isolated test persist in the agent's terminal session and make `list`/`proxy stop` read a different state dir, so a running proxy looks absent. If that happens, `unset` them, then re-check. - Remove a stale test route with `portless alias --remove `; move an old-format `routes.json` to a backup folder instead of deleting it. - Phone/tailnet access to a portless app: the proxy routes by Host header and the tailnet Host is `.ts.net`, so point `tailscale serve --bg --https= http://127.0.0.1:` at the app's fixed loopback start script, not at the proxy port; pick a port absent from `tailscale serve status`, and turn it off after the test. ## Acceptance test (all must pass before recommending) 1. Two apps at once: `APP=a portless a node server.js &`, `APP=b portless b node server.js &`; `portless list` shows both; `curl http://a.localhost:1355/` and `b` answer from their own ports (server echoes `process.env.PORT`). 2. Worktree: in a git repo with a linked worktree on branch `fix-ui`, `portless run ` in each gives `.localhost` and `fix-ui..localhost` simultaneously. 3. Same name twice: the first route survives, the second start is refused. 4. Cleanup: kill one app; its route disappears and the URL returns 404. 5. HMR through the proxy (Vite): start `portless vt npm run dev` in the background, read the token from `/@vite/client` (`wsToken = "..."`), open `new WebSocket("ws://vt.localhost:1355/?token=", ["vite-hmr"])` in Node 24, edit `index.html`; expect `{"type":"connected"}` then `full-reload`, and the page content changes. Long-running servers must be launched with `background=true`; a foreground command that starts one is rejected. 6. Teardown: kill app PIDs from `portless list`, `portless proxy stop`, confirm the proxy port is free and no test process remains. ## Reviewing someone else's comparison Check that each candidate was tested in its core mode (portless's automatic ` ` flow and worktree naming, not only the manual `alias` command) before accepting a ranking, and verify "left no trace" claims yourself (`brew list --versions `, the tool's state dir, listening ports).