# Pair devices with flow-remote

> Pair your Macs into a Puddle, grant open and create per device, and use another Mac's sessions from your sidebar as live mirror groups.

`flow-remote` is the link between your own devices that run Flow. You pair two devices once; after that either one can reach the other over an encrypted, mutually authenticated channel, through Tailscale, your local network or a tailcat relay. In the app it is called **Puddles**: the **Puddle** page invites, joins and manages devices, and the sidebar shows each paired Mac's sessions so you can open them in local panes.

This is not the same as [remote hosts](https://flow.worldbreakstudios.com/docs/sync/remote-hosts.md), which run a group's panes on a server over `ssh`. `flow-remote` connects Flow to Flow.

## The peer model

- **Every device is a peer.** The same program serves and dials. There is no server, no account and no third party.
- **One daemon per device.** `flow-remote serve` listens for your other devices and answers this device's own commands on a local socket. The app runs it for you while Puddles is on.
- **Pairing is mutual.** Both devices store each other, so either one can dial later.
- **Permissions are per device, on each side.** A pairing lets the other device *list* your sessions. Opening and creating sessions are granted afterwards, by you, per device ([Let a device open or create sessions](#let-a-device-open-or-create-sessions)).

Each device has an identity: a name and a keypair, created on first use. Its **device id** is 16 hex digits derived from its public key; Flow shows it beside the name.

### Where its state lives

State lives in `~/.flow/remote` (or `$FLOW_REMOTE_DIR` when set), mode `0700`. Flow refuses the folder if another user owns it or if it is a symlink.

| File | What it holds |
|---|---|
| `identity.json` | this device's name and keypair; the only place the private key is written (`0600`) |
| `devices.json` | the paired devices: id, name, public key, permissions, when paired, when last seen, addresses (`0600`) |
| `daemon.log` | the output of the daemon the app started |
| `tailcat.json` | with the Tailcat network only: the tunnel's keys, so its address survives restarts (`0600`) |

Don't edit these files by hand; use the Puddle page or the [`flow-remote` commands](https://flow.worldbreakstudios.com/docs/sync/flow-remote-commands.md).

## Turn on Puddles

1. Open Settings (`⌘,`) › **Experiments** and switch on **Puddles** (`features.remote`, default `false`).
2. Open the Puddle page: the **Puddle** row in the Tools band, `⌃⌥⌘2` (Go to Puddle), or `flow-cli page puddle`.
3. The **This device** card shows the device's name, short id and a status pill. If the service isn't running, press **Start**.

The page has four cards: **This device**, **Invite a device**, **Join a puddle** and **Members**.

### Choose the network

**This device › Network** sets where the daemon listens (`puddle.bind`). Changing it, or the port, restarts the daemon.

| Network | `puddle.bind` | Listens on | Notes |
|---|---|---|---|
| Automatic | `auto` (default) | your Tailscale IPv4 when Tailscale is up, else this Mac only | With no Tailscale, other devices can't reach you; the page says so |
| Tailscale | `tailscale` | your tailnet IPv4 only | Needs Tailscale running |
| Local network | `lan` | every network interface | Opt-in; anyone on the network can reach the port (they still can't pair or connect without a key) |
| Tailcat | `tailcat` | inside a tailcat tunnel, through public relays until a direct path forms | Opt-in, never picked automatically. Needs no Tailscale account. The address is a secret, so **Copy address** has nothing to copy |

The port is `puddle.port` (integer, 1024–65535, default `47633`). Both settings are found by Settings search ("Puddle network", "Puddle port"), which opens the Puddle page.

## Pair two devices in the app

You need both devices in front of you, with Puddles on in both.

1. On the first device, open the Puddle page and press **Show invite** in **Invite a device**. Flow shows a QR code, the invite link (`flow://puddle/join?t=…`) with **Copy link**, and a countdown. An invite is good for one pairing within 5 minutes.
2. Get the link to the second device: press **Copy link** and send it, or open the link there. Opening a `flow://puddle/join` link opens the Puddle page with the **Join** field filled in; it never joins by itself.
3. On the second device, paste the link (or the bare token) into **Join a puddle** and press **Join** (or `↩` in the field).
4. Both devices now show the same **six-digit confirmation code**, and the first device shows the name and id the joiner gave.
5. On the first device, compare the codes. If they match, press **Approve**; otherwise press **Deny**. You have 60 seconds to answer.
6. Each device now lists the other under **Members**.

If the Puddle page isn't on screen when someone joins, a toast offers to open it, and the Puddle row shows a badge.

> **Warning:** The name on the approval prompt is chosen by the joining device. Anyone can call their device "Tyler's iPhone". Only the code tells your device from someone else's: approve only when your other device shows the same six digits.

Pairing is human-only. Approve, Deny and Join run only from a click (or `↩` in the Join field). They are not palette actions or bus commands, so an agent or a script can't pair your device. The palette's **Invite a device to your puddle…** shows an invite, but the bus refuses it, because the QR code is the secret.

The invite link is a password for 5 minutes. **Copy link** puts it on the clipboard marked transient, so clipboard history never records it, and Flow takes it back off the clipboard when the invite ends, if it is still there.

## Pair from the command line

The CLI does the same pairing. The daemon must run on device A (`flow-remote serve`, or Puddles on in the app); run it on device B too, so that A can reach B later. `flow-remote` is not on your `PATH`: it ships inside the app at `Flow.app/Contents/MacOS/flow-remote`.

On device A:

```sh
/Applications/Flow.app/Contents/MacOS/flow-remote pair
```

`pair` prints a pairing token (`fr1.…`), single use and valid for 5 minutes, and waits. It needs a terminal on stdin and stdout, and refuses to run with its output redirected.

On device B:

```sh
/Applications/Flow.app/Contents/MacOS/flow-remote join
```

`join` prompts for the token with echo off; paste it and press Return. It never takes the token as an argument. Then:

1. B dials A and both print the same `Confirmation code: NNNNNN`.
2. A prints the name and id B gave and asks `Pair with this device? [y/N]`. Type `y` or `yes` within 60 seconds to approve. Anything else, no answer, or Ctrl-C refuses.
3. On approval both devices store each other and print `Paired with …`. On a refusal neither stores anything.

A pairing is always refused when the token is wrong, expired or already used, when no pairing is waiting, or when a device tries to pair with itself. If someone else used your token first, your own `join` is refused (the token is spent) and the prompt on A shows a code your device isn't showing: answer N.

## Let a device open or create sessions

A new pairing can only list your sessions. Each row under **Members** has two switches, both off by default:

| Switch | CLI | Lets that device |
|---|---|---|
| **Can open my sessions** | `flow-remote grant <device> open` | watch any shareable session and type into it: full shell access on this Mac |
| **Can create sessions** | `flow-remote grant <device> create` | have Flow here start new sessions |

`flow-remote deny <device> open|create` takes a grant back. Turning **open** off ends that device's live views at once. Pairing the same device again keeps the grants it already had. Grant these only to devices that are yours; see [Security and trust](https://flow.worldbreakstudios.com/docs/sync/security.md).

This device's card lists who is viewing what under **Viewing now**. A device starting to view one of your sessions records a notification, "`<device>` is viewing `<group · tab>`", in the notification history only. Change that with `notifications.puddle.viewing` (`toast`, `system`, `silent` or `off`; default `silent`) in Settings › Notifications, or `flow-cli settings set notifications.puddle.viewing toast`. A paired device starting a session here is `notifications.puddle.created` (default `toast`).

## Use another Mac's sessions

Once a Mac lets you open its sessions, you work in them from your own sidebar.

### Device spaces in the spaces bar

After your own label chips, the main window's spaces bar shows, for each paired device:

- a device chip, **All `<device>`**, with a green dot while it is online and shares its sessions;
- one chip per label of that device that has a group on show, **`<label>` · `<device>`**.

`⇧⌘←` and `⇧⌘→` (Previous label / Next label) walk into them like your own labels. Select one and the sidebar (and the Dashboard) lists that device's sessions in its order. When the device can't be shown you see one muted line instead: "`<device>` is offline", "Not shared with this device" (it hasn't granted you **open**), or that it hasn't been reached yet. Your pick is remembered.

### Open a session as a mirror group

Click a session in a device space to open a **mirror group** named "`<device>` · `<group>`": one local pane per remote tab, each showing the remote session live. You type into it as if it were local.

- Closing a mirror pane only detaches; the session keeps running on its device.
- A remote tab already shown in some pane here never gets a second pane.
- If the link drops (sleep, network change, the other daemon restarting), the pane reconnects by itself and says "Reconnecting to `<device>`…". Press Enter to try at once.
- If the device stops sharing, the pane says so and names the switch to turn back on there (**Can open my sessions**), then waits for Enter.
- If the session ended on the device, the pane says "`<device>` closed this session."
- Mirror groups come back on relaunch and with `⇧⌘T` (Reopen closed session).

A mirror group's header shows the remote session's folder, branch and pull request as its device publishes them. The folder button copies the remote path. Its right-click menu has **Open in Finder**, which mounts that folder from the device under `~/.flow/remote-mounts/<device name>/<folder name>` and opens it; this needs the device to grant you both **open** and **create**.

### Start a session on another Mac

With **Can create sessions** granted, the device space offers **New session on `<device>`**, which starts a session there and opens it here as a mirror group. With the same grant, a new terminal tab or split in a mirror group starts a new session on that device, in that group. From the CLI:

```sh
flow-cli new-session --device Studio ~/src/app
```

The path is on that device (`~`, `~/…` or absolute). `--label` may be added; `--host`, `--base`, `--layout` and `--background` don't go with `--device`.

### Close here or everywhere

Closing a mirror group of a device that is live follows **Close on the other device too** (`puddle.close_remote`):

| Value | Behavior |
|---|---|
| `ask` (default) | asks "Also close on `<device>`?" with **Close everywhere** and **Just here** (Enter is Just here) |
| `always` | closes on the device too |
| `never` | closes here only |

The palette action **Close session everywhere** (no default shortcut) and `flow-cli group <g> close --everywhere` close on both sides without asking. Pinning a mirror group pins it on its device too while the device is live. Closes, pins and renames from another device need [sync](https://flow.worldbreakstudios.com/docs/sync/sink.md) on.

### Organize mirror groups locally

A mirror group takes your local labels like any group and can join a session group with local groups. A labelled mirror group shows under that label beside your local groups; an unlabelled one that you haven't organized lives only in its device space. A mirror pane may also be dropped into a local group (beside its primary, never as the primary).

Right-click a device chip or a remote label chip for **Hide**, **Change icon…**, **Open in New Window** and **Open Puddle page**. Hidden chips come back from the Members row's **Show in spaces bar**. **Open in New Window** puts a device's space, or one of its labels, in a window of its own.

### Shared pane size

When a session is on screen on two devices, **Shared pane size** (`puddle.pane_size`) decides its size. It is set on the Puddle page (**Device used last** / **Fit smallest screen**) and is found by Settings search.

| Value | Behavior |
|---|---|
| `latest` (default) | the device you typed in last sets the size |
| `smallest` | fit the smallest screen |

The setting on the device that owns the session is the one that counts. It applies to sessions started after a change.

## Settings reference

| Key | Type | Default | What it does |
|---|---|---|---|
| `features.remote` | bool | `false` | Puddles on or off (Settings › Experiments) |
| `puddle.bind` | `auto` \| `tailscale` \| `lan` \| `tailcat` | `auto` | where the daemon listens |
| `puddle.port` | integer | `47633` | the daemon's TCP port |
| `puddle.pane_size` | `latest` \| `smallest` | `latest` | how a shared terminal is sized |
| `puddle.sync` | bool | `true` | Sync sessions with your devices ([sync](https://flow.worldbreakstudios.com/docs/sync/sink.md)) |
| `puddle.close_remote` | `ask` \| `always` \| `never` | `ask` | closing a mirror group closes it on its device too |
| `notifications.puddle.pairing` | delivery | `toast` | a device asking to join, off the Puddle page |
| `notifications.puddle.viewing` | delivery | `silent` | a device starting to view one of your sessions |
| `notifications.puddle.created` | delivery | `toast` | a device starting a session here |
| `notifications.puddle.remote_action` | delivery | `silent` | a device closing, renaming or pinning one of your sessions |

A delivery is `toast`, `system`, `silent` (history only) or `off`. These rows only appear in Settings while Puddles is on.

## Remove a device

On the Puddle page, press **Remove** on the device's Members row and confirm. From the CLI, `flow-remote revoke <device>`. Removing ends that device's live connections at once. It only removes the device here: the other device still lists yours until you remove it there too, but it can do nothing with the entry. See [Revoke and unpair](https://flow.worldbreakstudios.com/docs/sync/security.md#revoke-and-unpair).

## Limits

- Puddles is a Beta experiment. `flow-remote serve` refuses to start while `features.remote` is off, and reads it only when it starts.
- Turning Puddles off stops only the daemon the app started. One you started by hand keeps running until you stop it.
- Device spaces are part of the vertical sidebar; with horizontal tabs there are none.
- There is no watch-only grant: a device that may open a session may also type into it.
- A local pane never joins a mirror group, and a mirror pane is never a local group's primary.
