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:
- a key for the other machine, and the other's key allowed in, from the other's addresses only;
- the other's SSH host key pinned, and an ssh config entry that uses it strictly;
- the SSH server on this machine set to let the other in (key only, no forwarding);
- the other machine in
~/.config/agent-bridge/peers.json.
Then a ping over the new link. The code is what makes this safe: see Why the code.
- Before you start
- Pairing in a terminal
- Pairing from Claude Code
- The owner's password prompt
- Who is let in
- What pairing writes
- After pairing
- Unpairing and pairing again
- A fleet of machines
- Finding a peer after an address change
- Pairing by address, over a VPN
- Setting up a link by hand
- 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:
- Windows: the SSH server, once, in an elevated
PowerShell 7
(
& '<plugin>\setup\enable-ssh-windows.ps1', no arguments: it installs and hardens OpenSSH Server and lets nobody in yet), and the network marked Private. - Linux: an SSH server
(
apt install openssh-server) andavahi-utilsfor discovery. - macOS: nothing; Remote Login is turned on by pairing, with your password.
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:
- 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.
- 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. - 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.
- Default: exactly the addresses the other machine announced. Each machine announces the addresses of its LAN interfaces only, not VPN tunnels or container and VM bridges.
- The whole network the two machines share, as wide
as this machine's own network there is (a home /24 or /22, an office
/16; never wider than /16), or the
/24around the other machine's address when they share none: for a laptop that moves between Wi-Fi, a cable and new DHCP leases. Offered at the confirm prompt or dialog, only to you, and only for a private (LAN) range. - A network you name:
agent-bridge pair --network 192.0.2.0/24(LAN ranges only, /16 or narrower). The other machine's agent can't widen this for you:--networkis something you pass, and the dialog checks it shows you what will actually be applied. - Connect out only:
agent-bridge pair --no-acceptpairs a machine that never accepts connections (it can use the other, not the other way round). - For messages only:
agent-bridge pair --messages-onlylets the other machine in to talk, and for nothing else (below). - A peer reached over a VPN (Tailscale, WireGuard),
where the two machines don't hear each other's mDNS: pair by address when you
already have an SSH login there. By hand: set
AGENT_BRIDGE_MY_IPS=100.64.0.5on that machine, or pass--networkon the other side.
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
- takes messages and task events from it and hands it the ones waiting for it, checked by this machine's rule, with the sender fixed by the key: it can't write as another machine;
- tells it which agent sessions are live in that project and whether they work, wait or are idle. Not what they do, not what they were asked, no jobs, no other project;
- answers
ping.
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.
- Which clones it reaches. A message is for a
project; this machine delivers it into its own clone of that project,
found by the project's first commit in the usual source folders. To say
it yourself:
"serve": {"repos": ["~/src/app"], "search": false}in this machine's config offers only the clones listed. - On the other machine the first
agent-bridge <this machine> ping(pairing runs one) notes"link": "messages"for this machine in its config. From then onmsg,task,inbox,watch,sessions,wait-idleandpingwork over the link, and anything else says that this peer takes only messages. - Changing it later, without pairing again:
agent-bridge pair <peer> --limit messages,agent-bridge pair <peer> --limit safeandagent-bridge pair <peer> --limit fullrewrite that machine's line inauthorized_keys. safe (macOS and Linux) adds jobs to messages: sync, jobs in this machine's sandbox, logs, fetch and get, neverrun; see Security. - On Windows the key's line runs this machine's own
serve.ps1, found through%LOCALAPPDATA%\agent-bridge\current.txt(agent-bridge install-cliwrites it), so it keeps working across plugin updates; the setup script, elevated, writes that line (an administrator's keys are in a file only an elevated shell may change) and takes no other command.pair <peer> --limitasks for the same elevation.
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:
- Where this machine already found clones on that
peer. The folders holding the other projects in
peers.<peer>.reposcome first, so once one project is found (or saved) in an unusual place, such asE:\Labs\acme, the others there are found by themselves. - 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. - The usual source folders:
~/src,~/code,~/GitHub,~/Projects,~/dev,~/work,~/repos, ...; on Windows alsosrc,dev,code,work,repos,git,GitHub,Projectsandsource\reposat 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.
- Each machine announces the address the SSH connection shows for it, so each lets the other in from its VPN address and reaches it there.
- The login is only the way the two find each other. The link itself uses the keys pairing makes, as always; the login you used isn't changed or kept.
- What the other machine may do there is its owner's choice, so
--messages-onlyand--networkapply to this side only; the other side's owner can limit this machine afterwards withpair <peer> --limit messages. - On a machine with no desktop (a server you reach over SSH), its
owner confirms in a terminal there, an SSH login included:
agent-bridge pair --confirmshows that machine's code first, then asks for the code the other shows. agent-bridgeis found on the other machine's PATH, or in~/.local/bin(whereinstall-cliputs it, and which most Linux and macOS machines put on PATH only for a login shell, not forssh host command).- IPv4 only for now.
Setting up a link by hand
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.
- A key, on the client:
ssh-keygen -t ed25519 -N '' -C 'agent-bridge laptop to buildbox' -f ~/.ssh/agent_bridge_buildbox_ed25519 - 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
.publine:- 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 withfrom=, 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 asfrom="…",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 withAllowUsers, the user is added there too). If systemd stops background processes at logout:loginctl enable-linger <user>.
- Windows, in an elevated PowerShell 7:
- Pin the host key, on the client, after comparing
it:
ssh-keyscan -t ed25519 buildbox.local > /tmp/k, thenssh-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. - 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 - 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"] } } } - The peer's repo: a clone of the same project,
ignoring
.claude/worktrees/. - 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.