portful
portfulv0.1.0MIT
Keep one fixed port pointed at whichever git worktree is active, and switch it without restarting the client
Install
npm install portfulWith git worktrees, several branches can run at once, but the client that talks to the server, such as a frontend dev server, still uses one port.
Without portful, every switch means stopping the running server and starting it again from another worktree.
portful keeps each worktree’s backend server running on its own port and puts a small reverse proxy on the fixed port, which forwards to whichever worktree is active.
portful use changes the active worktree, and the next request reaches it, with no restart of the client, no edit to .env, and no cd.
portful takes its command names and config layout from portless wherever the two tools do the same thing.
Features
Section titled “Features”- One fixed port per repo.
portful proxy start <repo>runs the proxy on the repo’sfixedPortin the foreground. It reads the active worktree again on every request and adds anX-Portful-Worktreeheader to each HTTP response. - A running server per worktree.
portful serve <repo>/<worktree>starts that worktree’s server on a port fromportRangethat stays the same across restarts. Every server getsPORT,HOST, andPORTFUL_URLin its environment. - One command to switch.
portful use <repo>/<worktree>sets the active worktree, andportful use <repo>opens peco, fzf, or a numbered prompt to pick one. - Where each port goes.
portful listprints one row per repo with the address clients use, the worktree it reaches, and whether the proxy runs.portful status --jsonprints the fuller view as JSON. - Commands inside a worktree.
portful exec <repo>/<worktree> <cmd...>runs a command in that worktree’s directory and passes its flags through untouched. - A read-only check.
portful doctorreports on config, ports, and state, and exits non-zero when something looks off.
How an agent uses it
Section titled “How an agent uses it”- Run
portful whoamito confirm which repo and worktree the current directory is in. It prints one line such asapi/feature-x port 3101 (running, active),--jsonprints the full detail, and it exits non-zero outside a registered repo. - Read
portful list --jsonorportful status --jsonto see where each fixed port goes and which servers run. - Run
portful doctorwhen a server does not answer.statusreports process liveness, not reachability, anddoctorcompares each port’s reallsofstate with what portful expects.
Getting started
Section titled “Getting started”portful needs Node.js 24 or newer, macOS or Linux, and git.
npm install -g portfulRegister the repo once per machine in ~/.config/portful/config.json, then give it ports in a portful.json in the checkout:
mkdir -p ~/.config/portfulcat > ~/.config/portful/config.json <<'JSON'{ "repos": { "api": { "path": "~/work/api" } } }JSON
cat > ~/work/api/portful.json <<'JSON'{ "fixedPort": 3000, "portRange": [3101, 3199], "serve": "bundle exec rails s -p {port}"}JSONStart one server per worktree and the proxy, each in its own terminal tab, then switch:
portful serve api/feature-xportful serve api/feature-yportful proxy start apiportful use api