Skip to main content
Glama

agent-bus

A local message bus that lets Claude Code, Codex and Antigravity talk to each other directly, instead of a human relaying messages between windows. Designed in fantashley/dotfiles#131.

  • One stdio MCP server (agent-bus mcp --agent <type>) registered in every client. The server stamps the sender from its launch command, so agents can't impersonate each other.

  • SQLite (WAL) per host at $XDG_STATE_HOME/agent-bus/bus.db, mode 0600. History is never deleted; read state is a per-session, per-thread cursor.

  • On-demand worker, no daemon. Typed actions (start_discussion, advance_discussion, request_review) queue a job and spawn agent-bus run-job <id>, which holds an SQLite lease and runs the peers headless and read-only (claude -p --permission-mode plan, codex exec with a read-only sandbox, agy --mode plan --sandbox), resuming each peer's conversation every round.

  • Safety in the server: peer text (including an agent's discussion question) is returned as trust: "peer_data" inside visible fences; only the CLI posts trust: "human". Round caps, message caps (THREAD_LIMIT_REACHED until the human runs resume), deadlines and job de-duplication. Jobs whose worker died are reaped, so a crash never wedges a thread.

  • Headless peers can't use tools that act. Claude runs with --strict-mcp-config and only Read/Grep/Glob/web tools; Codex has every live MCP server disabled (and the turn fails if they can't be listed); Antigravity has no per-session switch, so its turns are refused while it has any MCP server besides agent-bus configured, unless peers.antigravity.allow_mcp is set. Any agent-bus MCP server a peer launches sees AGENT_BUS_PEER and refuses every call. The repo allowlist decides which repos requests may target and where peers run; reads are bounded by each CLI's read-only mode, not by the allowlist.

Discussions

agent-bus ask "SQLite or a JSON file for a small CLI?" --with claude,codex,antigravity --wait
  1. Round 1 is blind: each participant proposes without seeing the others (P1, P2, …).

  2. Later rounds run peers in turn; each votes agree/object on a proposal id or revises one. Authoring a proposal counts as agreeing with it.

  3. Consensus = every participant agrees on the same proposal. The bus posts a final message and marks the thread resolved.

  4. Out of rounds or past the deadline → needs_human, with who backs what and who objects.

An agent can start one from its own chat with the start_discussion tool; it takes part with send + wait. If its turn ends, it's marked absent, and if the peers agree without it the thread waits in its inbox for its vote.

Related MCP server: tincan

Reviews

request_review(reviewer, repo, base_commit_id, head_commit_id, …) pins full commit ids. The worker computes jj diff --from base --to head --git, the reviewer returns a structured verdict, and it lands as a review_verdict in the requester's inbox.

For the next pass, request again with prev_head_commit_id set to the head that reviewer last saw. That continues the same thread and resumes the reviewer's own conversation, so it remembers its earlier findings; it gets the interdiff plus anything you posted on the thread since (e.g. a send explaining how each finding was addressed). If the resume fails it falls back to a fresh session with the full diff and thread.

Watching and stepping in

agent-bus threads                 # list open threads
agent-bus tail t-1a2b3c [--peer codex|--events]
agent-bus reply t-1a2b3c "Prefer the simpler option" [--to codex]
agent-bus cancel t-1a2b3c
agent-bus resume t-1a2b3c --rounds 2
agent-bus watch t-1a2b3c          # inside Rex: open viewer panes
agent-bus stream [t-1a2b3c …]     # one line per verdict / final / failure, as each arrives

stream is meant for notifications: each event is one stdout line, so a harness that turns lines into alerts (or a plain while read) hears about each reviewer as it finishes.

tail emits OSC 7501 program status (working, done, blocked/question on needs_human), so Rex shows discussion state on any client, local or attached to a remote host. Viewer panes are output-only; nothing is ever typed into a block. Everything works without Rex.

Rex sessions and wake-ups

agent-bus never types into a terminal, its own panes included. All three clients report idle/working to Rex (OSC 7501), but an idle agent with a half-typed draft reports idle too, and no client or Rex signal says whether the input box is empty. A check followed by a separate write could always race a human typing. So interactive sessions pick up messages with wait/inbox, and peers run headless. Automatic wake-ups wait for an atomic "deliver only if idle and empty" path or a dedicated notification channel. (Agreed by Claude, Codex and Antigravity in an agent-bus discussion, after measuring all three clients in Rex.)

agent-bus rex-check shows what Rex does report for a session, one check per line. Each check fails if it's missing or can't be read:

agent-bus rex-check                       # the latest session of each agent
agent-bus rex-check --session s-1a2b3c4d
agent-bus rex-check --block block:… --agent codex

The checks are:

  • rex_env: REX_SESSION/REX_BLOCK were recorded when the session registered.

  • mcp_server: the session's server process is still running.

  • block: the block exists.

  • app: the expected client reports OSC 7501 status there.

  • owner: the status owner is the block's foreground process.

  • client: the status owner is this session's own client.

  • state: the reported state and when it was last reported.

  • input_ready: always unavailable.

It exits non-zero if any check fails. Claude Code and Antigravity pass REX_* to MCP servers. Codex filters its MCP servers' environment, so agent-bus setup-codex (run by the home-manager module) sets env_vars on Codex's agent-bus entry.

Install (Home Manager)

# flake inputs
agent-bus = { url = "github:fantashley/agent-bus"; inputs.nixpkgs.follows = "nixpkgs"; };

# home-manager modules
imports = [ agent-bus.homeManagerModules.default ];
local.agentBus = {
  enable = true;
  repos = [ "~/dotfiles" "~/src" ];   # what peers may read
};

This installs the CLI, writes ~/.config/agent-bus/config.json, and registers the MCP server:

  • Claude Code: a local plugin from a directory marketplace in the store, enabled through local.claude.extraKnownMarketplaces/enabledPlugins when those options exist (otherwise use config.local.agentBus.claudeMarketplace).

  • Codex: agent-bus setup-codex at activation: codex mcp add agent-bus …, then env_vars on that entry so REX_SESSION/REX_BLOCK/REX_SERVER reach the server (Codex filters MCP server environments; codex mcp add can't set env_vars). Skipped when the entry already matches; the rest of ~/.codex/config.toml is left alone.

  • Antigravity: a plugin linked at ~/.gemini/config/plugins/agent-bus (on by default when local.antigravity.enable is set).

Add docs/AGENTS-section.md to the shared global agent rules.

Development

nix develop -c pytest      # tests use fake peer CLIs that speak each client's stream format
nix build                  # package (runs the tests)

Not in v1

Interactive peer panes and automatic wake-ups, until a client or Rex can deliver input atomically only when it's ready (see above). Cross-host discussions, per-client fixed-hint hooks, and writable participants in separate jj workspaces (v1.5).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      Enables multiple coding agents (Claude Code, Codex, Cursor) to discover each other's sessions, search transcripts, ask questions, and handoff tasks through a shared MCP server.
      5
      4 npm
      MIT
    • A
      license
      A
      quality
      A
      maintenance
      Enables live Claude Code and Codex sessions on the same machine to send each other text messages directly. It provides peer discovery, message sending, and a shared message log through MCP tools.
      5
      74 npm
      1
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables Claude Code, Codex and opencode sessions on the same machine to message each other live over a local pipe, with threaded replies and offline queuing, and to delegate or spawn one another as background subagents. Messages persist in SQLite and any running server can take over as broker, so peers stay reachable without a daemon.
      4
      MIT
    • A
      license
      A
      quality
      C
      maintenance
      Enables Claude Code, Codex, and other coding-agent sessions on the same machine to message each other, exchange tracked tasks with owners and states, and coordinate through channels, broadcasts, and multi-session asks without typing into terminals. Messages are routed by what the receiver is doing — next tool call, end of turn, or a held-back digest — so a flood of traffic doesn't interrupt active work.
      254
      14
      52 npm
      1
      MIT