agent-bridge
# agent-bridge
[](https://github.com/noobhacker02/agent-bridge/actions/workflows/ci.yml)
[](LICENSE)


Let AI coding agents working in **different repos** send each other messages.
You have a `frontend/` repo and a `backend/` repo, each open in its own Claude Code (or Codex, or Cursor) session.
agent-bridge gives each session a few MCP tools (`send_message`, `check_inbox`, `wait_for_message`, ...) and a shared
mailbox, so the frontend agent can ask the backend agent "what does `/api/login` return?" and get an answer, without you
copy-pasting between windows.
```
Claude Code (frontend) Codex (backend)
| MCP (stdio) | MCP (stdio)
agent-bridge server ---> mailbox <--- agent-bridge server
default: one SQLite file on your machine
optional: Supabase, a Slack channel, or your own relay
```
- **Clients:** Claude Code, OpenAI Codex CLI, Cursor, in any mix on one bridge.
- **Backends:** a local SQLite file (default, zero setup), Supabase (other machines), Slack, or a self-hosted relay.
- **No build step.** Plain Node.js; three runtime dependencies (MCP SDK, zod, smol-toml).
## Requirements
- **Node.js 22.13 or newer** (it uses the built-in `node:sqlite`).
- **Older Node 22.5 to 22.12 also works** for the local backend, but only with the flag `--experimental-sqlite`. `init`
detects this and writes `NODE_OPTIONS=--experimental-sqlite` into the generated config, and `doctor` tells you if it is
missing. If you run the CLI yourself on such a Node (`node cli.js log`, `tail`, `send`), set it in your shell first:
`export NODE_OPTIONS=--experimental-sqlite` (PowerShell: `$env:NODE_OPTIONS="--experimental-sqlite"`).
Easiest fix: upgrade Node.
## Quick start (2 minutes, one machine)
```bash
git clone https://github.com/noobhacker02/agent-bridge.git
cd agent-bridge
npm install
```
Wire up each repo with its own agent name. Both use the same local mailbox (`~/.agent-bridge/bridge.db`) by default.
**Claude Code** (macOS, Linux, Windows; the commands are the same in any shell):
```bash
node cli.js init ~/code/frontend frontend "React app, owns the login UI" --hook
node cli.js init ~/code/backend backend "API server, owns /api/*" --hook
```
Open Claude Code in each repo, approve the `bridge` MCP server when asked, then say: *"run whoami on the bridge"*.
On Windows use real paths, e.g. `node cli.js init C:\code\frontend frontend "React app" --hook`.
**Codex CLI**:
```bash
node cli.js init ~/code/frontend frontend "React app" --client codex --trust-codex
node cli.js init ~/code/backend backend "API server" --client codex --trust-codex
```
`--trust-codex` matters: **Codex ignores a repo's `.codex/` folder until the project is trusted**, so without it
`codex mcp list` shows no `bridge` and `codex exec` simply has no bridge tools. The flag appends a
`[projects.'<repo>'] trust_level = "trusted"` entry to your `~/.codex/config.toml`. Without the flag, `init` prints that
snippet instead and never edits your user config. Interactive `codex` can also just ask you to trust the folder.
Check it: `cd ~/code/backend && codex mcp list` must list `bridge`.
Cursor works the same way with `--client cursor`; use `--client all` for a repo you open in several tools.
**Try it.** In the frontend session: *"Ask the backend agent what the /api/login response looks like, and wait for the
answer."* In the backend session: *"Check your bridge inbox and answer any requests."* Watch the traffic from a terminal:
```bash
node cli.js tail # live feed
node cli.js log 20 # last 20 messages
```
An idle session does not wake up by itself: either tell it to check its inbox, have it `wait_for_message`, or use
`--hook`, which tells the agent about unread mail on its next prompt.
## What was tested
Verified on Windows 11 with Node 22.12.0 (the flag path) and codex-cli 0.173.0: two Codex agents in two separate repos
(`frontend`, `backend`), each started with `codex exec`, ran `whoami`, sent a message and replied in the same thread
through one local SQLite mailbox. The automated suites (`npm test`, see [docs/TESTING.md](docs/TESTING.md)) start real MCP
server processes and hold conversations on every backend. Running a real Claude Code or Cursor session end to end, macOS
and Linux, and Node 24 are covered by the test suites and CI only; they were not run by hand for this README. The
Supabase and relay suites need a Postgres for their stand-in (see [CONTRIBUTING.md](CONTRIBUTING.md)).
## The tools your agents get
| Tool | What it does |
|---|---|
| `whoami` | This agent's name, the backend, and the unread count |
| `list_agents` | Agents on the bridge, with their project dirs |
| `send_message(to, body, type?, subject?, thread_id?)` | Send a message; omit `thread_id` to start a thread, pass it to reply |
| `check_inbox(limit?, mark_read?, from_agent?)` | Read unread messages |
| `wait_for_message(timeout_seconds?, thread_id?, from_agent?)` | Block until a message arrives |
| `get_thread(thread_id)` | The whole back-and-forth of a thread |
`init` also installs a small **skill** (`.claude/skills/agent-bridge/`, `.agents/skills/...` for Codex) that tells the agent
when to message a peer, how to write a useful message, and the safety rules.
## How it works
- Each coding session starts its own copy of `server.js` as an MCP stdio server. `init` writes the config that does this
(`.mcp.json` for Claude Code, `.codex/config.toml` for Codex, `.cursor/mcp.json` for Cursor), with the agent name and
mailbox path in the server's environment. These files contain absolute paths for your machine, so you will usually
`.gitignore` them.
- Servers that point at the same mailbox can talk. Locally that is a SQLite file in WAL mode; messages are claimed
atomically, so two sessions as the same agent never receive the same message.
- **Peer messages are data, not orders.** Every message is rendered with a bridge-generated header and each body line is
prefixed with `| `, so a message cannot pose as a header or as another agent. Threads stop at a hop cap
(`AGENT_BRIDGE_MAX_HOPS`, default 20). Outgoing messages are scanned for secrets (`AGENT_BRIDGE_DLP`, default `block`).
This is a safety net, not a guarantee. Local mode has no authentication between agents on the same machine.
- Other backends (Supabase for several machines, one Slack channel, or a self-hosted relay with audit log and mTLS) are
covered in the [full guide](docs/GUIDE.md), plus [enterprise notes](docs/ENTERPRISE.md).
## Troubleshooting
Start with `node cli.js doctor ~/code/frontend` (add `--client codex` or `--client cursor` for those files). It prints
OK/WARN/FAIL lines with a fix for each.
| Symptom | Likely cause and fix |
|---|---|
| `this Node (22.x) has no node:sqlite` | Node older than 22.13. Upgrade, or re-run `init` (it adds `NODE_OPTIONS=--experimental-sqlite`), or set that variable yourself |
| `codex mcp list` has no `bridge`; `codex exec` says the bridge tools are unavailable | The project is not trusted. Re-run `init --client codex --trust-codex`, or add the printed `[projects...]` snippet to `~/.codex/config.toml` |
| `codex exec` fails on `send_message` ("approval policy is never") | `exec` cannot ask you. Allow it once, e.g. `codex exec -c 'mcp_servers.bridge.default_tools_approval_mode="approve"' "..."`, or approve it in interactive `codex` ("always allow") |
| Two agents do not see each other | They must use the **same** `AGENT_BRIDGE_DB` path. Check `whoami` in each; the `backend` line shows the file |
| Claude Code does not show the server | Approve the `bridge` server in the prompt, or run `/mcp`. `init` must have been run in the folder you opened |
| `AGENT_NAME` not set / name rejected | Names are lowercase letters, digits, `-` and `_`, up to 40 characters |
| Hook seems silent | Run the hook command with `AGENT_BRIDGE_DEBUG=1` to see why. Codex runs a hook only after you trust it (`/hooks`) |
| Corporate proxy or TLS inspection | See the "Corporate networks" part of the [guide](docs/GUIDE.md) and [docs/ENTERPRISE.md](docs/ENTERPRISE.md) |
## More
- [docs/GUIDE.md](docs/GUIDE.md): full reference: Supabase, Slack, relay, DLP, proxies, every environment variable, known limits
- [docs/clients/codex.md](docs/clients/codex.md), [docs/clients/cursor.md](docs/clients/cursor.md): what was checked against each tool
- [docs/TESTING.md](docs/TESTING.md): every test suite and what it proves
- [docs/ENTERPRISE.md](docs/ENTERPRISE.md), [docs/NETWORK-AND-DATA.md](docs/NETWORK-AND-DATA.md): regulated and locked-down environments
- [CONTRIBUTING.md](CONTRIBUTING.md)
## Origin
This project began as an AI-assisted coding session and was then reviewed and extended, including several rounds of
adversarial review whose findings and fixes are recorded in [docs/adversary/](docs/adversary/). Treat it as young
software: read what `init` writes before you trust it with anything sensitive.
## License
[MIT](LICENSE) (c) noobhacker02
TDQS
Scored across 6 tools
Each tool targets a distinct operation: identity (whoami), roster (list_agents), write (send_message), non-blocking read (check_inbox), blocking read (wait_for_message), and thread history (get_thread). The boundary between check_inbox and wait_for_message is explicitly clarified by the blocking/timeout semantics, and get_thread is clearly scoped to threads rather than individual inboxes.
Five of six tools follow a clean verb_noun snake_case pattern (list_agents, send_message, check_inbox, wait_for_message, get_thread). The lone outlier, whoami, is a well-known idiom but breaks the pattern slightly.
Six tools is a tight, well-scoped surface for an agent messaging bridge. Every tool maps to a necessary part of the send/receive/list/thread lifecycle with no filler.
Core messaging lifecycle is covered: discovery, send, read, block-for-reply, and thread history. Minor gaps exist around message management — no explicit mark-read/mark-unread control (check_inbox marks read as a side effect), and no way to update own status/description or search messages across threads.