agent-bridge

Documentation

Pairing machines

Pairing links two machines on the same LAN so that each can run work on the other over SSH. You run agent-bridge pair on both at about the same time; they find each other over mDNS, both show the same 6-digit code, and once you confirm the code on each, everything is written by itself, in both directions:

Then a ping over the new link. The code is what makes this safe: see Why the code.

Before you start

On both machines: install the plugin, then

agent-bridge pair --check

Do what any needs the owner: line says first. The usual ones:

Both machines must be on the same LAN segment, with mDNS (UDP 5353) allowed between them, and start pairing within the same 5 minutes (--timeout S changes that).

Pairing in a terminal

On each machine (with agent-bridge on your PATH):

agent-bridge pair
  agent-bridge pair  laptop (macos, me@laptop.local, 192.0.2.10)
         Run 'agent-bridge pair' on the other machine now.

  ✓ 1/4  Looking for machines on the LAN
  ✓ 2/4  Found buildbox
  ● 3/4  Check the code

  ╭─────────────────────────────────────────────────╮
  │  Pairing laptop ⇄ buildbox                      │
  │  windows · Me@BUILDBOX.local · 192.0.2.20       │
  │  host key  SHA256:1aB2...                       │
  │  let in    192.0.2.20                           │
  │                                                 │
  │  CODE   482 913                                 │
  ╰─────────────────────────────────────────────────╯

  Does buildbox show the same code? [y/N]

In a terminal, pairing shows its steps, and the code in a frame, in color (NO_COLOR=1 turns the colors off; a terminal that isn't UTF-8 gets an ASCII frame). Piped, or run by an agent (pair --bg), it prints the same steps as plain lines, and never the code.

Compare the two screens. Answer y on each only if both show the same code. If they differ, answer N: something else answered, or one side restarted (nothing is written on a side that says no). After y you may be asked whether to let the other machine in from its whole network instead (see Who is let in), then for your password (sudo; on Windows a UAC prompt), and you'll see:

  ✓ 3/4  The code matches
  ● 4/4  Applying, then testing the link
         Pinned buildbox's host key as bridge-buildbox, added 'Host bridge-buildbox' to ~/.ssh/config, and buildbox to ~/.config/agent-bridge/peers.json.
         Let buildbox's key in from 192.0.2.20 (~/.ssh/authorized_keys).
         sshd: allows me from 192.0.2.20
         Waiting for buildbox's owner to confirm there too...
  ✓ 4/4  Applied here, and buildbox confirmed there
  ✓ Paired, and the link works: buildbox up rtt_ms=4 os=windows ...
         Next, in a project: agent-bridge buildbox doctor (its repo there is found by itself the first time).

With more than two machines pairing at once, name the one you want: agent-bridge pair buildbox.

Pairing from Claude Code

/agent-bridge:pair (or just ask Claude to connect the other machine). Claude runs the same pairing in the background (agent-bridge pair --bg), but it can never see or type the code: only you can finish a pairing. What you'll see on each machine:

  1. A window with this machine's code ("This machine (laptop) shows code 482 913 ... Type it into agent-bridge's dialog on buildbox"). It stays until the pairing ends. Its text never appears where Claude can read it.
  2. A dialog asking for the other machine's code (agent-bridge pair --confirm, which Claude opens). Type the code that the other machine's window shows, not this one's. If the dialog offers "Pair: all of 192.0.2.0/24", that's the whole-network choice, yours alone.
  3. Your system's password prompt (macOS, a Linux desktop) or a UAC prompt (Windows), which lets the other machine through this one's SSH server and firewall. See below.

Claude follows along with agent-bridge pair --status (phases: looking, found, code, applying, applied, done, or failed with the reason) and reports the result. You can mix the two ways: pair one machine in a terminal and the other from Claude Code.

A machine without a desktop (reached over SSH, a headless server) can't show its code to an agent session: run agent-bridge pair in a terminal there. pair --check warns about it.

The owner's password prompt

Letting another machine in changes the SSH server's settings, so it needs an administrator, every time it changes something:

In a terminal From Claude Code
macOS sudo the system's administrator dialog ("agent-bridge pair: let buildbox in over SSH, as me, from 192.0.2.20 only...")
Linux sudo polkit's dialog (pkexec), on a desktop
Windows a UAC prompt a UAC prompt

It runs the plugin's own setup script (setup/enable-ssh-<os>.sh --add, enable-ssh-windows.ps1 -Add) for the other machine's addresses and your user, only after the code was confirmed, and it never asks for anything wider. Before the code, the only request ever made is on a machine without SSH host keys (ssh-keygen -A, which turns nothing on and opens nothing). Cancel it, and pairing still writes the rest; the result says sshd: NOT updated. The owner runs, on this machine: ... with the command to run yourself later. On a server that doesn't limit who logs in, it says instead that only the hardening is missing (the peer can already get in).

The setup scripts never change anything for other users or other addresses: they write one sshd drop-in (/etc/ssh/sshd_config.d/010-agent-bridge.conf) with a Match block for your user from the allowed addresses (key only, no forwarding of any kind, few auth tries), check it with sshd -t (the previous one comes back if sshd refuses it), and on macOS turn Remote Login on. If Remote Login can't be turned on (macOS needs Full Disk Access for the terminal for that), the result says "Remote Login is off": turn it on in System Settings > General > Sharing. On Windows the script also keeps a firewall rule (agent-bridge-ssh) admitting the SSH port from the allowed addresses only, on Private and Domain networks.

Who is let in

Each machine lets the other's key in only from the other's addresses (from="..." in authorized_keys, and the Windows firewall rule). An address outside that list is refused: the link fails closed.

Each side records what the other accepts from it (allowed_from in its config), so doctor can tell you when your address has moved outside it.

A machine that may only talk

An ordinary pairing gives the other machine a login as you, limited to its addresses: that is what jobs, sync and run need. For a machine you want your agents to talk with but not to run things here (a teammate's, a machine you trust less than your own), pair with --messages-only on your side:

agent-bridge install-cli            # once: the agent-bridge command at a path that stays (~/.local/bin)
agent-bridge pair --messages-only   # while the other machine runs: agent-bridge pair

Its key is then let in with a forced command, agent-bridge serve --peer <its name>. Whatever that machine asks for, sshd runs that and nothing else: this machine's own installed code, which

No script it sends is run; no job, sync, run, fetch or status. Each side says what the other may do there: --messages-only on one side leaves the other side's choice as it is, and both sides can pass it.

What pairing writes

Each machine writes only its own files, and only after you confirmed the code there:

What Where Removed by
A key for the other machine ~/.ssh/agent_bridge_<peer>_ed25519 (+ .pub) unpair
The other's host key, pinned ~/.ssh/known_hosts, as bridge-<peer> unpair
An ssh config entry ~/.ssh/config: a Host bridge-<peer> block (key only, StrictHostKeyChecking yes, HostKeyAlias bridge-<peer>, no forwarding), between # agent-bridge:<peer> begin/end lines unpair
The other's key, allowed in ~/.ssh/authorized_keys: from="<addresses>",restrict ssh-ed25519 ... agent-bridge <peer> to <self> (Windows administrators: %ProgramData%\ssh\administrators_authorized_keys) unpair
The peer ~/.config/agent-bridge/peers.json: ssh, os, name, addresses, allowed_from, and self if it wasn't set unpair
sshd's allow list the drop-in or sshd_config block above; the Windows firewall rule by hand (it may serve other peers)

The first change to each existing file keeps a backup next to it (<file>.agent-bridge.bak). Pairing again replaces each entry for that peer, never adds a second one.

After pairing

Inside a project:

agent-bridge buildbox doctor

It checks the link both ways (ssh config, key, pin, name resolution, your address against what the peer accepts, the port, the login and its key exchange, the peer's tools, its sleep settings) with one ok/warn/FAIL line each and the fix. The first command that needs the project on the peer finds its clone there by itself (a clone holding the project's first commit) and keeps it in peers.json as peers.<peer>.repos.<project>. It looks, in this order:

  1. Where this machine already found clones on that peer. The folders holding the other projects in peers.<peer>.repos come first, so once one project is found (or saved) in an unusual place, such as E:\Labs\acme, the others there are found by themselves.
  2. Where the peer's own projects are. These are the folders holding the projects Claude Code has opened on that machine (its ~/.claude.json), whatever their drive or name. The home folder, a whole drive and system folders are too wide for this step, so they're left to step 3.
  3. The usual source folders: ~/src, ~/code, ~/GitHub, ~/Projects, ~/dev, ~/work, ~/repos, ...; on Windows also src, dev, code, work, repos, git, GitHub, Projects and source\repos at the top of every local drive.

One folder counts once however it's spelled (on macOS ~/GitHub and ~/github are the same folder). With several candidates: agent-bridge buildbox locate-repo lists them, and locate-repo --save <path> picks one.

The peer's clone should ignore job worktrees: add .claude/worktrees/ to its .gitignore or .git/info/exclude (doctor warns otherwise), so they don't show up in its owner's git status.

Unpairing and pairing again

agent-bridge unpair buildbox        # on this machine; asks first (--yes in a script)

It removes, on this machine only, everything in the table above except sshd's allow list. Run it on both machines. To pair again (a reinstalled machine, a new address, a renamed machine), just run pair on both again: each entry is replaced, and the other machine's old key is no longer let in.

A name is forever per pair: the name one machine uses for another must be that machine's own self name, on every machine. Rename a machine ("self" in its peers.json) only together with unpairing and pairing it again everywhere.

A fleet of machines

With more than two machines, a fleet key replaces the code per pair: machines that hold the same key pair without it.

agent-bridge fleet init        # on one machine: prints a new 256-bit key
agent-bridge fleet join        # on each other machine: asks for that key (type or paste it; never in a chat or a command line)
agent-bridge pair              # between two members: no code needed
agent-bridge fleet status      # the fleet's id, whether joins are accepted, the last fleet.log entries

The key is kept in ~/.config/agent-bridge/fleet.key, readable by you only. Members prove they hold it with an HMAC over the whole pairing exchange; only a hash of it is announced. Anyone with the key can pair with your machines, so treat it like a password: fleet init --force makes a new one (everyone joins again), fleet leave drops it here.

Zero-touch joins. A machine can accept a fleet member's pairing by itself, with nobody at it:

agent-bridge fleet accept on --network 192.0.2.0/24     # who joiners are let in from
sudo setup/enable-ssh-<os>.sh --add 192.0.2.0/24 <user>  # sshd must already allow that network: a background service can't ask for a password
agent-bridge advertise --install                         # keep announcing this machine (and answering joins)

A new machine then runs agent-bridge fleet join and agent-bridge pair --fleet, which pairs it with every member that accepts joins. Every such pairing is logged in ~/.cache/agent-bridge/fleet.log. fleet accept off stops it.

Finding a peer after an address change

A peer is reached by its mDNS name (buildbox.local), which follows it to a new address by itself. When the name doesn't resolve, agent-bridge tries the last address that worked, then the address the peer announces on the LAN (only if it runs advertise, and only when it announces the host key already pinned), then the addresses in its config. The pin holds at any address, because it's kept under the alias (HostKeyAlias bridge-<peer>), so a different machine at the old address still fails the host-key check.

agent-bridge advertise --install    # announce this machine from now on: a launchd agent, a systemd user unit, or a logon entry on Windows
agent-bridge advertise --status
agent-bridge advertise --uninstall
agent-bridge discover               # what's on the LAN right now: machines pairing or advertising, and whether each is paired here

What advertise announces: the machine's agent-bridge name, OS, host name, addresses and SSH host key (all public). Never a project, a path or a user name.

Installed, it runs for as long as the service does. advertise --run started by hand from an agent session (Claude Code, Codex, Gemini) stops when that session's shell does, and any copy stops once its own script is deleted (a temp folder, a scratchpad), so no advertiser is left announcing after a test or a session. To keep one you started from an agent session running, use advertise --run --keep. A test can name the process to follow in AGENT_BRIDGE_ADVERTISE_PARENT.

Pairing by address, over a VPN

Pairing finds the other machine with mDNS, which stays on one LAN. Across a VPN (Tailscale, WireGuard) or another subnet, pair by address instead, from a machine that already has an SSH login on the other (your own key, the VPN's SSH, a password in a terminal):

agent-bridge pair --host buildbox.tailnet.example     # or user@100.64.0.7, or a Host from ~/.ssh/config

The other machine needs agent-bridge on its PATH (agent-bridge install-cli there). This machine starts the other's pairing over that login and carries over it what the two would have announced on the LAN; no port is opened and nothing listens. Everything else is the pairing you know: the same code on both, confirmed by the owner on each (agent-bridge pair --confirm on the other machine: a dialog on its desktop, or its terminal), each side writing only its own files, the owner's password prompt for the SSH server's allow list on each.

When mDNS is blocked, the peer has no plugin, or you want full control (/agent-bridge:setup walks you through this). The machine that starts work is the client, the one that runs it the peer; for both directions, do it twice with the roles swapped. In the examples the client is laptop, the peer buildbox (buildbox.local on mDNS), and the addresses are 192.0.2.x.

  1. A key, on the client: ssh-keygen -t ed25519 -N '' -C 'agent-bridge laptop to buildbox' -f ~/.ssh/agent_bridge_buildbox_ed25519
  2. The peer's SSH server, on the peer, as an administrator, with the client's addresses (or its network, if the client moves between addresses) and the client's .pub line:
    • Windows, in an elevated PowerShell 7: .\setup\enable-ssh-windows.ps1 -SourceIPs 192.0.2.10,192.0.2.11 -PubKey 'ssh-ed25519 AAAA… agent-bridge laptop to buildbox' It installs and hardens OpenSSH Server (key only, only the users it let in, no forwarding), adds the key with from=, a firewall rule for those addresses only, makes PowerShell 7 the SSH shell, and prints the user, addresses and host-key fingerprint. Run it again with new addresses and it replaces the key's line and the rule.
    • macOS: sudo setup/enable-ssh-macos.sh 192.0.2.10,192.0.2.11 <user> 'ssh-ed25519 AAAA… agent-bridge laptop to buildbox' (the sshd drop-in, Remote Login on, the key as from="…",restrict, the host-key fingerprint). Remote Login doesn't need Full Disk Access; leave that switch off.
    • Linux: sudo setup/enable-ssh-linux.sh 192.0.2.10,192.0.2.11 <user> 'ssh-ed25519 AAAA… agent-bridge laptop to buildbox' (the same drop-in; if the server already limits logins with AllowUsers, the user is added there too). If systemd stops background processes at logout: loginctl enable-linger <user>.
  3. Pin the host key, on the client, after comparing it: ssh-keyscan -t ed25519 buildbox.local > /tmp/k, then ssh-keygen -lf /tmp/k. Only if that fingerprint matches the one the peer printed on its own screen, add it under the alias: sed 's/^[^ ]*/bridge-buildbox/' /tmp/k >> ~/.ssh/known_hosts.
  4. ssh config, on the client (~/.ssh/config):
    Host bridge-buildbox
      HostName buildbox.local
      HostKeyAlias bridge-buildbox
      User <user>
      IdentityFile ~/.ssh/agent_bridge_buildbox_ed25519
      IdentitiesOnly yes
      StrictHostKeyChecking yes
      ForwardAgent no
      ForwardX11 no
      ClearAllForwardings yes
  5. agent-bridge config, on the client (~/.config/agent-bridge/peers.json, see Configuration):
    { "self": "laptop",
      "peers": { "buildbox": { "ssh": "bridge-buildbox", "os": "windows", "allowed_from": ["192.0.2.10", "192.0.2.11"] } } }
  6. The peer's repo: a clone of the same project, ignoring .claude/worktrees/.
  7. Check: agent-bridge buildbox doctor.

Why the code

Pairing has to trade public keys over a network you don't control: anything on the LAN can answer an mDNS query. The 6-digit code is a hash over both machines' names, users, addresses, host keys, client keys and a random nonce from each, so when both screens show the same code, each machine holds the other's real keys. Each side commits to its keys and nonce (a hash) before either reveals its nonce, so nothing in the middle can try codes until one matches: it would have to commit first, and then it's caught. Comparing the code replaces reading a fingerprint aloud. Nothing is written before your yes, and a wrong code or a timeout writes nothing.

sequenceDiagram
  actor O as You (at both machines)
  participant A as laptop
  participant L as the LAN (mDNS)
  participant B as buildbox
  A->>L: announce: name, keys, and a commitment = hash(keys, nonce)
  B->>L: announce the same
  L-->>A: buildbox is pairing
  L-->>B: laptop is pairing
  Note over A,B: both have committed before either reveals its nonce
  A->>L: reveal the nonce
  B->>L: reveal the nonce
  A->>A: buildbox's nonce matches its commitment?
  B->>B: laptop's nonce matches its commitment?
  Note over A,B: code = hash(both machines' names, users, addresses,<br/>host keys, client keys and both nonces)
  A-->>O: CODE 482 913
  B-->>O: CODE 482 913
  O->>A: the same code? yes
  O->>B: the same code? yes
  Note over A,B: nothing is written before both yeses
  A->>A: pin buildbox's host key, let its key in, sshd (your password)
  B->>B: the same for laptop
  A->>B: ping over SSH: the link works

That is also why an agent can start a pairing but never finish it: pair --confirm takes no code; it asks a person, at a terminal or in a dialog, for the code the other machine shows, and the code is never printed where the agent can read it. More in Security.

Edit this page on GitHub →