@cocodrino/bridge-harness-pi0.3.16
Pi coding agent extension for bridge-harness โ real-time NATS communication with Claude Code
Untested on omp
This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.
Reports 0
No reports yet.
Readme
๐ bridge-harness ยท Pi Extension
Real-time messaging between AI coding agents โ no matter the provider.
Claude Code โ Pi, talking to each other live. They ask, they answer, they go back and forth โ on their own. No files, no copy-paste, no polling.
๐ฌ See it in action
Two agents. One conversation. Neither one is a chatbot window โ these are real coding agents wiring a fix together in real time:
โญโ ๐ต Claude Code โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ Pi, review the auth module while I refactor the payments โ
โ flow โ ping me with anything you find. โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ
โก delivered over NATS ยท Pi wakes up on its own
โผ
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ ๐ฃ Pi Agent โโฎ
โ On it. โฆ Found 2 issues in middleware.ts (lines 42 & 88). โ
โ Missing token expiry check + a timing-unsafe compare. Patch? โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ
โก asyncRewake fires ยท Claude answers instantly
โผ
โญโ ๐ต Claude Code โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ Yes please. Send the patch, I'll wire it in and run tests. โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ
โผ
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ ๐ฃ Pi Agent โโฎ
โ Sent. ๐ฏ Tests green on my side too. Nice teamwork. โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
no files ยท no copy-paste ยท no polling ยท pure real-time
That whole exchange happened without you touching the keyboard. You started it; the agents carried it.
โจ Why it's different
- โก Real-time. Messages travel over NATS pub/sub โ sub-millisecond, in-process. No inbox to poll, no webhook to wire.
- ๐ง Reactive, both ways. When Claude sends, Pi wakes up and processes it (
triggerTurn). When Pi replies, Claude wakes up too (asyncRewake). It's a genuine back-and-forth loop, not a one-shot. - ๐ Provider-agnostic. The transport doesn't care who's behind the agent. Claude Code, Pi, or anything that speaks the bridge โ different vendors, same conversation.
- ๐๏ธ No intermediate files. No shared scratch file, no
/tmphandoff, no glue script relaying output. Agents address each other directly. - ๐ฏ Reach anyone by identity. DM any agent with
agent:<id>โ it works across projects and git worktrees. No matching config, no shared room required. - ๐ They find each other. Active presence discovery is global โ
list_agentsshows everyone online (and their project), and late joiners still see who's already there. - ๐ Local or remote. Same machine, same LAN, or a NATS server in the cloud. Point both at the same URL and they connect.
๐ The reactive loop
sequenceDiagram
participant C as ๐ต Claude Code
participant N as โก NATS bridge
participant P as ๐ฃ Pi Agent
C->>N: send "review the auth module"
N-->>P: deliver โ Pi wakes automatically
P->>N: send "found 2 issues, patch?"
N-->>C: deliver โ asyncRewake fires
C->>N: send "yes, wiring it in"
N-->>P: deliver
Note over C,P: no files ยท no copy-paste ยท pure real-time
๐ Install
pi install npm:@cocodrino/bridge-harness-pi
That's it โ Pi loads the extension automatically on the next session start. The package
also ships an agent-bridge skill (declared via pi.skills) that Pi picks up on
install โ it teaches the agent how to operate the bridge (routing, discovery, use_bridge,
worktree alignment). Trigger it with "activa bridge harness" or "who's connected?".
Updating to the latest version. Pi caches the installed package, so pin @latest
(or an explicit version) to force it to fetch the new one, then restart the session:
pi install npm:@cocodrino/bridge-harness-pi@latest
# or a specific version: pi install npm:@cocodrino/bridge-harness-pi@0.3.0
Prerequisite: a local NATS server with JetStream (needed for DM durability).
brew install nats-server && nats-server -js &
Pairing with the Claude Code side (the other half of the bridge):
npm install -g @cocodrino/bridge-harness@latest
bridge-harness-setup # registers the MCP server + reactive hook
Once both are running, the bridge is live. Say the word and they'll talk.
๐ ๏ธ The agent_bridge tool
Pi gets one tool with everything it needs to join the conversation:
| Action | What it does |
|---|---|
send |
Message another agent or a room (to, message) |
read |
Pull messages that arrived mid-turn |
list_agents |
See who's on the bridge right now |
whoami |
Show this agent's identity (agentId, displayName, project, rooms) |
join_room |
Announce presence in a room (room) |
use_bridge |
Hop to another bridge namespace at runtime (bridge) |
set_name |
Give yourself a memorable, stable handle โ reachable as agent:<name> (name) |
// Pi replying to Claude โ mid-task, unprompted
agent_bridge { action: "send", to: "agent:claude-code",
message: "Auth review done. 2 issues in middleware.ts." }
๐ก How it works
The extension plugs into Pi's native ExtensionAPI. On session_start it:
- Connects to NATS (
localhost:4222by default) - Subscribes to its DMs and every room
- On an incoming message, calls
pi.sendMessage({ triggerTurn: true })โ Pi reacts on its own - Publishes a presence heartbeat every 30s so others know it's online
๐ต Claude Code ๐ฃ Pi Agent
(MCP server) (this extension)
โ โ
โโโโโโโโโโโโโโโโบ โก NATS โโโโโโโโโโโโโโโโโโโ
bridge.dm.<agent> # GLOBAL โ DM by identity
bridge.registry / presence # GLOBAL โ discovery
bridge.<project>.room.* # project-scoped rooms
Routing model. DMs and discovery are global by identity โ send to
agent:<id> reaches that agent across any project/worktree, and list_agents
shows everyone. Rooms are project-scoped (isolated per worktree). So to reach an
agent elsewhere, just DM it โ no shared room needed.
Message delivery. Idle โ the message is delivered immediately and wakes Pi.
Mid-turn โ it's buffered (no interruption); Pi pulls it with read, or it's
flushed automatically when the turn ends. Nothing is dropped.
DM durability (JetStream). DMs (bridge.dm.*) are captured by a JetStream stream
(30-min / 100-per-recipient retention). On the Claude side this guarantees the rewake
hook wakes for every DM โ even replies that land during its restart โ via a durable
consumer that gets redelivered anything it missed. Recipients that reconnect within the
window also catch up on messages sent while they were offline. Rooms stay ephemeral. This
needs a nats-server with JetStream (-js); the bundled auto-start enables it.
๐งญ Presence discovery (global)
Discovery is global โ list_agents shows every agent online across all
projects/worktrees, each with its project. NATS pub/sub doesn't retain events, so
on connect each agent also broadcasts a who-there query and everyone replies with
a here carrying their identity, so late joiners still fill their roster instantly.
Check it with agent_bridge { action: "list_agents" }.
๐ฏ Reaching agents across worktrees
DMs route by identity, globally โ to: "agent:<id>" reaches that agent no
matter which project or git worktree it's in. You don't need a shared room or any
matching config; list_agents gives you the exact IDs.
Rooms, by contrast, are project-scoped (an isolated lobby per worktree). If
you specifically want to share a room with agents in another project, both call
use_bridge with the same name to land in the same room space:
- Pi:
agent_bridge action: "use_bridge", bridge: "<other-project>" - Claude Code:
use_bridge bridge: "<other-project>"
For plain messaging, though, just DM by ID โ use_bridge is rarely needed.
๐ Default room (project lobby)
On connect, both agents auto-join the room named after their project โ an isolated
lobby per worktree (to: "room:<project>"). The project name comes from the git
worktree root, so each worktree's rooms stay separate. This only affects rooms;
DMs and discovery are global regardless. Override with BRIDGE_PROJECT to share a
room space across worktrees.
๐ Remote agents
Pi doesn't have to sit next to Claude Code. nats-server listens on
0.0.0.0:4222, so any reachable machine can join:
# Same LAN
BRIDGE_NATS_URL=nats://192.168.1.10:4222 pi
# Cloud NATS (fly.io, Railway, any VPS)
BRIDGE_NATS_URL=nats://your-server.fly.dev:4222 pi
Same NATS URL = same bridge. DMs and discovery work across everyone connected; rooms are still grouped by project.
โ๏ธ Environment variables
| Variable | Default | Description |
|---|---|---|
BRIDGE_PROJECT |
git worktree name (falls back to basename(cwd())) |
Scopes your rooms (isolated per worktree). DMs/discovery are global and ignore this. |
BRIDGE_NATS_URL |
nats://localhost:4222 |
NATS server URL โ change to connect remotely |
BRIDGE_AGENT_ID |
pi-{pid} |
Pin a stable agent ID across restarts (this is how others DM you) |
BRIDGE_DISPLAY_NAME |
Pi Agent (or Pi Agent @ <cmux-surface> under cmux) |
Human-readable name shown to other agents |
๐ฉ Session lifecycle
| Event | What the extension does |
|---|---|
session_start |
Connects to NATS, subscribes, announces active, rolls call |
agent_end |
Flushes messages that arrived during the turn |
session_shutdown |
Announces offline, drains, closes cleanly |
๐ฉบ Troubleshooting
Pi doesn't react to messages โ make sure nats-server is running, both sides
share the same BRIDGE_PROJECT, and restart Pi to reload the extension.
agent_bridge not available โ reinstall with
pi install npm:@cocodrino/bridge-harness-pi and restart the session.
The model insists it has no agent_bridge tool (oh-my-pi) โ this is usually not an
install problem, and asking the model is not a reliable way to check. oh-my-pi has a
setting, tools.xdev, that keeps "rarely-used" tools out of the request to save prompt
space. While it is on, extension-registered tools are dropped before the model ever sees
them: the extension loads, connects and appears in getActiveTools(), but is absent from
the tool list in the request. The model is telling the truth โ it really wasn't given the
tool.
omp config get tools.xdev # true means agent_bridge is being withheld
omp config set tools.xdev false
Verify rather than trust either side. PI_REQ_DEBUG=1 omp -p 'hi' writes the outgoing
request to rr-session-1.json in the current directory; the tools array in its body is
the definitive list the model received.
The trade-off is prompt size โ every mounted tool schema now ships on each request (on a
host with many MCP servers this measured 107 KB โ 261 KB). Disabling MCP servers you do
not use brings it back down. omp --tools=agent_bridge,read,bash also works as a
per-invocation escape hatch without changing any setting.
Messages lost while offline โ DMs are durable (retained by JetStream and
redelivered within 30 min), so a recipient that reconnects in that window catches up.
Room messages are still ephemeral core-NATS pub/sub. This needs a nats-server with
JetStream enabled (the bundled auto-start does this; a remote server must run with -js).
๐ Links
- GitHub โ cocodrino/bridge-harness
- Claude Code side โ @cocodrino/bridge-harness
Give two agents one bridge, and watch them figure it out together.
MIT ยฉ cocodrino