Skip to content

Deployment

PiFi has three parts, and you can place them on one machine or several:

  • the coordinator, which stores state and serves the web app and the sockets;
  • hosts, the machines that run Pi, hold your repositories and keep your provider credentials, and connect outbound to the coordinator;
  • devices, the browsers, phones and terminals you use.

Pick the pattern that fits where you run it. None of them requires a particular network, proxy or identity provider. Who may sign in is covered in auth.md; backups and upgrades in operations.md.

Requirements: Node >=24 and pnpm 12 (to build from source), git, and Pi >=1.4.0 <1.8.0 on every host that runs sessions (see compatibility.md). Policy-protected sessions require Pi 1.5.0; older supported Pi versions remain available for basic unprotected operation. The container image needs only Docker for the coordinator.

The optional GitHub catalog worker ships with the coordinator and uses the same persistent data directory (catalog-secrets/). It does not listen on a port. Outbound HTTPS to GitHub is required; no inbound webhooks or callback URLs are needed (Web OAuth redirects back through the user’s browser to <public URL>/settings/projects/connect/callback). Set PIFI_GITHUB_APP_CLIENT_ID, PIFI_GITHUB_APP_CLIENT_SECRET (enables 1-click Web OAuth; without it, GitHub App sign-in falls back to zero-config Device Flow), and optionally PIFI_GITHUB_APP_SLUG to override the default PiFi GitHub App. Personal Access Token connections work out of the box with zero app configuration. Hosts do not need gh installed; hosts receiving private clone grants must connect over HTTPS (loopback HTTP is supported for local standalone use).

Choosing a pattern

You want Use
Try it, or use it on one machine Local
An always-on server you reach from several devices A server behind a reverse proxy or a VPN, plus hosts. docker-compose.md has a ready-to-run setup for each proxy

Three rules hold in every pattern:

  1. Set PIFI_PUBLIC_URL to the exact URL people type in the browser. It drives sign-in links, the OIDC redirect URI, the Secure cookie flag and the passkey domain.
  2. Use HTTPS with a real name if you want passkeys, push notifications or an installed app. Plain HTTP works for a browser tab, a host or a terminal.
  3. Do not put a proxy-level login (basic auth, forward auth) in front of PiFi. Host agents, webhooks and installed apps cannot pass it, and PiFi has its own sign-in.

Local: pifi up

npm install -g @spencerboucher/pifi
pifi up

up runs the coordinator and a local host agent in one process. On first start, without single sign-on and with no device signed in yet, it prints a single-use sign-in link with a QR code and opens it in your browser when run in a terminal.

Setting Default Override
Port 7400 --port
Bind address 0.0.0.0 --bind (use 127.0.0.1 to keep it on this machine)
Public URL http://localhost:<port> --public-url, PIFI_PUBLIC_URL
Trusted origins the public URL’s origin (plus http://127.0.0.1:<port> with the default URL) --trusted-origins, PIFI_TRUSTED_ORIGINS
Web app packages/web/dist next to the CLI, when built --web-dist, PIFI_WEB_DIST
Data dir $XDG_DATA_HOME/pifi, else ~/.local/share/pifi (Linux); ~/Library/Application Support/pifi/coordinator (macOS) --data-dir, PIFI_DATA_DIR
  • The default public URL uses localhost so passkeys work on this machine. To reach it from another device, pass --public-url with the address that device uses (passkeys then need HTTPS and a domain name, see auth.md).
  • The local host is enrolled automatically on first start (--name sets its name). Its host.json and state live in <data-dir>/host/. Pi must be on PATH (or PIFI_PI_BIN).
  • --dev also trusts the Vite dev server origins (http://localhost:5173, http://127.0.0.1:5173) and turns on debug logs.
  • up records the local URL in <data-dir>/cli-endpoint.json, so pifi pair on the same machine finds it.
  • up reads the same server variables as pifi coordinator start (the container’s command): the ones in the table above plus the OIDC, trusted-proxy and shared-secret variables in the environment reference. With an OIDC owner declared it comes up already set up and prints no link.
  • Schedules (cron, once, webhooks, dependency triggers) only run while the process is awake. A sleeping laptop fires nothing; missed cron occurrences follow each automation’s missed-run policy when it wakes.

A server

The container image runs the coordinator only. Pi never runs in it.

For a complete setup with HTTPS, start from a recipe in docker-compose.md: Caddy, Traefik, nginx, Tailscale or a Cloudflare Tunnel, each a directory you copy, fill in and start. The rest of this section describes the minimal deploy/compose.yaml and the settings every recipe uses.

cd deploy
export PIFI_PUBLIC_URL=https://pifi.example.com
mkdir -p data && sudo chown 1000:1000 data
docker compose up -d
docker compose exec pifi pifi pair # localhost only; otherwise configure single sign-on first

deploy/compose.yaml uses ghcr.io/justmytwospence/pifi:0.32.0 (multi-arch, node:26-bookworm-slim, runs as the node user), mounts ./data at /data and has a HEALTHCHECK on /healthz. If the package is not public, docker login ghcr.io with a token that can read packages first. The compose file publishes the port on 127.0.0.1 only, for a proxy on the same machine; change it to 7400:7400 to serve plain HTTP on every interface, or remove it if the proxy shares a Docker network.

Single sign-on is required unless the public URL is localhost: declare an OIDC owner in the environment (auth.md). On localhost, pifi pair prints a single-use sign-in link. To run without Docker, use pifi coordinator start with the same variables.

The coordinator container needs neither a home directory nor the Docker socket, and the compose file mounts neither.

Environment reference

Variable Applies to Default Meaning
PIFI_PUBLIC_URL coordinator, up http://localhost:<port> The URL clients and hosts use. Drives sign-in and enrollment links, the OIDC redirect URI, the Secure cookie flag (https) and the passkey domain.
PIFI_TRUSTED_ORIGINS coordinator, up the public URL’s origin Comma-separated browser origins allowed to call the API and open sockets. Set it only when browsers also use other origins (for example a LAN name next to a public name). Passkeys are verified against these origins. An entry may use * as its whole first label (https://*.example.com) to trust every single-label subdomain.
PIFI_SHARED_DOMAIN coordinator, up unset A domain that is the public URL’s host or a parent of it. Web apps on it and its subdomains share sign-in: the device cookie is set for that domain and passkeys use it as their RP ID. Changing it later invalidates passkeys registered under another RP ID.
PIFI_TRUSTED_PROXIES coordinator, up none Comma-separated IPs or CIDRs of reverse proxies whose X-Forwarded-For is trusted for the client IP (rate limits). Set it when a proxy is in front. See auth.md.
PIFI_DATA_DIR coordinator, CLI platform default; /data in the image Data directory: coordinator.db, admin.token, coordinator.lock.
PIFI_LISTEN coordinator start 0.0.0.0:7400 host:port to listen on.
PIFI_WEB_DIST coordinator, up packages/web/dist when found; /app/packages/web/dist in the image Directory of the built web app. Without it the server is API only.
PIFI_LOG_LEVEL all info pino level: trace, debug, info, warn, error, fatal, silent.
PIFI_HOST_ENROLL_SECRET coordinator, up and host unset Shared secret (at least 32 characters). On the coordinator it enables secret enrollment; on a host it is what the host enrolls with.
PIFI_OIDC_ISSUER, PIFI_OIDC_CLIENT_ID coordinator, up unset Together they enable single sign-on.
PIFI_PAIRING_ONLY coordinator, up unset true: no single sign-on at any public URL; sign in with pifi pair links only (throwaway servers, auth.md).
PIFI_OIDC_CLIENT_SECRET coordinator, up unset Client secret (recommended).
PIFI_OIDC_LABEL coordinator, up Sign in with single sign-on Sign-in button text.
PIFI_OIDC_SCOPES coordinator, up openid profile email groups Scopes requested.
PIFI_OIDC_OWNER_SUBJECT, PIFI_OIDC_OWNER_EMAIL, PIFI_OIDC_OWNER_GROUP coordinator, up unset Who the owner is. At least one is required with OIDC; all that are set must match.
PIFI_COORDINATOR_URL host unset With the secret, lets a host without host.json enroll itself.
PIFI_HOST_NAME host the machine’s host name Name given to a self-enrolling host.
PIFI_HOST_CONFIG host, CLI ~/.config/pifi/host.json Host credential file.
PIFI_STATE_DIR host, CLI ~/.local/state/pifi (Linux), ~/Library/Application Support/pifi (macOS) Host state: host.db, runtime/, logs/.
PIFI_PI_BIN host, CLI pi The Pi binary.
PIFI_GITHUB_APP_CLIENT_ID, PIFI_GITHUB_APP_CLIENT_SECRET, PIFI_GITHUB_APP_SLUG coordinator, up built-in PiFi defaults (secret unset) GitHub App OAuth/Device Flow credentials. Setting PIFI_GITHUB_APP_CLIENT_SECRET enables 1-click Web OAuth; without it, GitHub App connections use Device Flow.
PIFI_ADMIN_TOKEN CLI the data dir’s admin.token Admin token for pair and local work commands.
PIFI_URL, PIFI_TOKEN CLI client.json Coordinator URL and device credential for work commands.

The OIDC variables are explained in auth.md.

Behind a reverse proxy (HTTPS)

Terminate TLS in a proxy on the same machine or network and forward everything to the coordinator on port 7400. The proxy must:

  • pass WebSocket upgrades for /ws/client (browsers and terminals) and /ws/host (host agents);
  • not buffer streamed responses, nor compress or retry them;
  • allow long-lived connections (idle timeouts of many minutes; clients and hosts reconnect by themselves if one is dropped);
  • allow request bodies of at least 32 MB (attachments).

Then set PIFI_PUBLIC_URL to the proxy’s URL and PIFI_TRUSTED_PROXIES to the proxy’s address, so rate limits see real clients.

Caddy. Caddy gets certificates itself and forwards WebSockets without configuration. See deploy/Caddyfile.example:

pifi.example.com {
reverse_proxy pifi:7400 {
flush_interval -1
}
}

Traefik. deploy/compose.yaml carries commented Docker labels (router rule, websecure entrypoint, TLS, service port 7400, an external network shared with Traefik); deploy/traefik.example.yaml is the file-provider equivalent. Traefik forwards WebSocket upgrades automatically. Add no buffering, compression or retry middleware.

nginx.

map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 443 ssl;
http2 on;
server_name pifi.example.com;
ssl_certificate /etc/ssl/pifi.example.com/fullchain.pem;
ssl_certificate_key /etc/ssl/pifi.example.com/privkey.pem;
client_max_body_size 32m;
location / {
proxy_pass http://127.0.0.1:7400;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# WebSocket upgrade for /ws/client and /ws/host
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_buffering off;
proxy_read_timeout 1h;
proxy_send_timeout 1h;
}
}

Serving the web app separately

docker build --target web . builds an image of the web app alone (Caddy on port 8080). Put it behind a proxy that sends /api/, /ws/, /adapter-frames/, /healthz and /readyz to the coordinator and everything else to the web container, preserving Host and Origin. Several web apps can then share one coordinator, for example a stable one and one for the next version: each web app’s origin must be trusted (PIFI_TRUSTED_ORIGINS, where https://*.example.com covers every single-label subdomain), and PIFI_SHARED_DOMAIN lets all of them share one sign-in. The coordinator’s own web app (PIFI_WEB_DIST) keeps working for deployments that do not split them. The coordinator reports an API level the web app checks; a web app outside the coordinator’s range shows a banner.

VPN or tailnet

Reaching the server only over a private network needs no proxy. Run the coordinator, then use the VPN address or name as the URL:

  • WireGuard, a LAN or any other VPN: use the address or name that devices reach, for example PIFI_PUBLIC_URL=http://pifi.internal:7400. Plain HTTP is fine for hosts, terminals and a browser tab; passkeys, push and installed apps need HTTPS and a domain name, so add a proxy or certificate if you want them. If browsers use more than one name, list them in PIFI_TRUSTED_ORIGINS.

  • Tailscale: tailscale serve gives the server an HTTPS name on your tailnet with a real certificate, which is enough for passkeys, push and the installed app. With the coordinator on the same machine:

    tailscale serve --bg 7400

    then run the coordinator with PIFI_PUBLIC_URL=https://<machine>.<tailnet>.ts.net and PIFI_TRUSTED_PROXIES=127.0.0.1 (the serve proxy connects from loopback). Publish the container port on loopback as in the compose file. Check the current tailscale serve syntax for your version.

In every case the server is reachable only by those who can reach the URL, and signing in still requires the owner.

Hosts

A host runs the Pi processes and owns the repositories and provider credentials. It connects outbound to <coordinator>/ws/host; the coordinator never dials a host, so hosts can sit behind NAT. Enrollment (single-use token or shared secret) is described in auth.md.

On the machine that has the repositories and Pi credentials, as the user that should run Pi:

npm install -g @spencerboucher/pifi
pifi host enroll --coordinator https://pifi.example.com --token <token> [--name laptop]
pifi host install-service

To upgrade a host later: npm update -g @spencerboucher/pifi, then restart its service (launchctl kickstart -k gui/$(id -u)/com.pifi.host on macOS, systemctl --user restart pifi-host on Linux).

Get the token from Settings › Hosts › Add host. host enroll writes ~/.config/pifi/host.json (mode 0600). With a shared secret you can skip it: set PIFI_COORDINATOR_URL, PIFI_HOST_ENROLL_SECRET and optionally PIFI_HOST_NAME in the service’s environment and the host enrolls itself the first time it runs.

host install-service renders a template from deploy/launchd or deploy/systemd with the absolute paths of this Node binary, the CLI and host.json (plus your current PATH, so pi and git resolve), writes it, loads it and prints the file and every command it runs:

OS File Loaded with
macOS ~/Library/LaunchAgents/com.pifi.host.plist launchctl bootout gui/<uid>/com.pifi.host (if loaded), then launchctl bootstrap gui/<uid> <plist>
Linux ~/.config/systemd/user/pifi-host.service systemctl --user daemon-reload, enable --now, restart

--print shows the rendered file without writing it; --no-load writes it without loading. The service runs pifi host run --config <host.json> and logs to <host state dir>/logs/host.log (launchd) or the user journal (systemd). Nothing is installed or started unless you run the command. On Linux, loginctl enable-linger <user> keeps user services running while you are logged out. To run in the foreground instead, use pifi host run. Check the link with pifi host status.

Host state (host.db, runtime/, logs/) defaults to ~/Library/Application Support/pifi on macOS and ~/.local/state/pifi on Linux (PIFI_STATE_DIR).

Host in a container

The same image can run a host agent: pifi host run. Use it only when the machine that owns your repositories is itself managed through containers. It needs:

  • Pi on PATH. The image does not include Pi. Build a small image on top of it, or mount a Pi install and set PIFI_PI_BIN:

    FROM ghcr.io/justmytwospence/pifi:0.12.0
    USER root
    RUN npm install -g @earendil-works/pi-coding-agent@1.5.0
    USER node
  • git. Included in the image (with an ssh client for git remotes).

  • The user’s home directory, mounted at the same path it has on the machine, with the container running as that user’s uid. The repositories, Pi’s credentials and sessions, ~/.config/pifi/host.json and the host state all live there, and paths the coordinator records must resolve identically inside the container.

  • The coordinator’s URL, reachable from the container, and either a pre-made host.json in that home or the shared secret and URL in the environment so the host enrolls itself.

deploy/compose.yaml has a commented pifi-host service with these settings.

Pi terminal

Terminals sign in by approval in a browser you are already signed in to:

pifi login --coordinator https://pifi.example.com
pifi tui <session id>

login shows a link and a code; approve it in the browser. --token <link from pifi pair> signs in without a browser. login writes ~/.config/pifi/client.json (mode 0600) and registers the terminal as a device of kind terminal.

Work commands (hosts, sessions, tasks, automations, tui, herdr, doctor) resolve credentials in this order: --coordinator/--credential flags, PIFI_URL and PIFI_TOKEN, ~/.config/pifi/client.json, then the local admin.token in the data dir against the coordinator recorded in cli-endpoint.json, else http://127.0.0.1:7400. The admin token is sent only to a loopback URL or the one in cli-endpoint.json; PIFI_URL selects the coordinator like --coordinator.

iOS Home Screen push

Web Push on iPhone and iPad (iOS/iPadOS 16.4 or later) works only for a site added to the Home Screen and opened from that icon, over HTTPS with a certificate the device trusts (a self-signed certificate will not work).

  1. Reach the server over HTTPS with a certificate the device trusts (a reverse proxy, or tailscale serve).
  2. In Safari, open PiFi and sign in (a passkey or single sign-on is convenient for the next steps), then Share > Add to Home Screen.
  3. Open PiFi from the new icon and sign in again with a passkey or single sign-on: the installed app does not share cookies with Safari. See auth.md.
  4. Go to Settings › Notifications and enable notifications. The permission prompt must be triggered by a tap inside the installed app.
  5. Use the test notification in the same panel to confirm delivery.

Limits:

  • Delivery is not guaranteed; it depends on Apple’s push service and device conditions.
  • Clearing a notification across devices is best effort. The coordinator uses notification tags and sends clear messages when attention is resolved, but iOS may not remove an already delivered notification.
  • Quiet hours and previews follow the iPhone’s Focus and notification preview settings. How long you must be away from your computers before the phone is notified is a coordinator setting (Settings › Notifications). See notifications.md.

Privilege model

  • Pi runs with the privileges of the host agent’s OS user. Anything that user can read, write or execute, Pi and its extensions can too. Run the host agent as a user you are willing to give that to.
  • A container host has the same reach as what you mount into it. Mounting a home directory gives it that whole home; mount the least you need, and never the Docker socket.
  • Provider credentials stay on the hosts. The coordinator never receives them.
  • The coordinator container does not sandbox execution, because execution never happens there. It needs neither a home directory nor the Docker socket.
  • Custom adapters (server modules under the owner, plugin or project tiers) are trusted code that runs in the host agent. Web renderers receive restricted capabilities. See adapters.md.
  • admin.token in the data dir grants full access to the coordinator, including enrolling devices. Protect the data dir (file mode 0600 for the token, restricted directory access, careful backups). Whoever can run commands in the coordinator container or read that file is the owner.
  • PIFI_HOST_ENROLL_SECRET lets its holder add hosts that receive work. Keep it as private as a password.
  • Revoke a lost device or a retired host in Settings; see auth.md and operations.md.