Sync your pi coding sessions to a live web app in real time.
pi session ──► WebSocket Relay ──► Web App
◄──────────────────────────────────────
This project has three components: a pi extension, a WebSocket relay, and a web app. You self-host the relay and web app, and configure the extension to point at them.
pi install npm:pi-web-syncConfigure the extension (pick one):
📄 Config file (recommended — set once, works for every session)
Create a JSON file at one of these locations:
| Location | Scope | Path |
|---|---|---|
| Global (all projects) | User-wide | ~/.pi-web-sync.json |
| Project (per-project) | Local override | .pi-web-sync.json |
Required fields:
{
"relayUrl": "ws://localhost:8787",
"webappUrl": "http://localhost:5173"
}| Field | Description |
|---|---|
relayUrl |
WebSocket relay URL (required) |
webappUrl |
Web app base URL for session links (required) |
🔧 Environment variables
export PI_WEB_SYNC_RELAY_URL=ws://localhost:8787
export PI_WEB_SYNC_WEBAPP_URL=http://localhost:5173⌨️ Interactive command
In pi, run:
/web-sync connect ws://localhost:8787 http://localhost:5173
No default servers are provided. You must deploy your own relay and web app, or run them locally. See below.
┌─────────────┐ WebSocket ┌──────────────────┐ WebSocket ┌───────────┐
│ pi session │ ◄──────────────► │ WebSocket Relay │ ◄──────────────► │ Web App │
│ (extension) │ JSON msgs │ (Worker/Durable │ JSON msgs │ (React) │
└─────────────┘ └──────────────────┘ └───────────┘
| Component | Package | Role |
|---|---|---|
| Extension | packages/extension |
Pi plugin — hooks into pi events and relays messages via WebSocket |
| Relay | packages/relay |
Cloudflare Worker — pairs one pi client with one web client per session ID, forwards JSON messages. No storage. |
| Web App | packages/webapp |
React + Vite SPA — displays conversation with markdown rendering. History persisted in localStorage. |
- Pi session starts → extension generates a session ID, connects to the relay
- Pi prints the session URL — open it in a browser
- Keystrokes in pi stream to the web app as
assistant_deltamessages - Complete messages arrive as
assistant_done— stored in localStorage - Messages typed in the web app reach pi as
user_messagemessages - On reconnect, the web app requests full history via
sync_request; pi replies withsync_response
Local development:
cd packages/relay
npm run dev
# Starts at ws://localhost:8787Production (Cloudflare Workers + Durable Objects):
cd packages/relay
npx wrangler deployDurable Objects are required for production — they maintain WebSocket state across Worker requests. Requires a Workers Paid plan ($5+/mo).
Observability:
npx wrangler tailstreams relay logs (connect/disconnect, forwarding at debug, errors) with the[pi-web-sync]prefix — useful when debugging connection issues on a deployed relay.
Local development:
cd packages/webapp
npm run dev
# Starts at http://localhost:5173Production (Cloudflare Pages):
cd packages/webapp
npm run build
npx wrangler pages deploy distNo build-time configuration needed — the relay URL travels with each share link as a ?relay= query parameter.
pi install npm:pi-web-syncStep-by-step:
- Deploy the relay —
cd packages/relay && npx wrangler deploy - Deploy the web app —
cd packages/webapp && npm run build && npx wrangler pages deploy dist - Create
~/.pi-web-sync.jsonwith your deployed URLs:{ "relayUrl": "wss://your-relay.workers.dev", "webappUrl": "https://your-webapp.pages.dev" } - Start a pi session, run
/web-sync, and open the URL in a browser.
Config file (recommended): create a JSON file at one of these locations:
| Location | Scope | Path |
|---|---|---|
| Global (all projects) | User-wide | ~/.pi-web-sync.json |
| Project (per-project) | Local override | .pi-web-sync.json |
Required fields:
{
"relayUrl": "ws://localhost:8787",
"webappUrl": "http://localhost:5173"
}| Field | Description |
|---|---|
relayUrl |
WebSocket relay URL (required) |
webappUrl |
Web app base URL for session links (required) |
Environment variables:
| Variable | Description |
|---|---|
PI_WEB_SYNC_RELAY_URL |
WebSocket relay URL |
PI_WEB_SYNC_WEBAPP_URL |
Web app base URL (for session URL display) |
Interactive: /web-sync connect <relay-url> <webapp-url>
This is an npm workspaces monorepo:
pi-web-sync/
├── packages/
│ ├── extension/ ← Pi extension (npm package)
│ ├── relay/ ← Cloudflare Worker
│ └── webapp/ ← React + Vite app
├── docs/
│ └── plans/ ← Design docs, ADRs, verification reports
└── package.json ← Workspace root
npm install # Install all workspace dependencies
npm run dev --workspace=packages/relay # Start relay locally
npm run dev --workspace=packages/webapp # Start web app locallycd packages/extension && npx vitest # Extension tests
cd packages/relay && npx vitest # Relay tests