Repository navigation
InBand v2: rewrite in Rust, with teams and session identity - #4
Merged
Merged
Conversation
An rmcp 3.5 stdio server pushes a notifications/claude/channel event that Claude Code shows in the session. rmcp advertises protocol 2026-07-28 by default, and Claude Code skips channel events on that revision. The server caps its supported versions at 2025-11-25. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signatures match vectors produced by the v1 TypeScript clients. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keeps the v1 schema and adds the sessions and audit tables. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mail content loses terminal escapes, control chars, bidi and zero-width chars, and forged channel tags before agents or the user see it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Send, read, wait, channel subscriptions, roles, presence, history and Codex and OpenCode wakes behave as in v1. New checks: - a mailbox bound to a session sends only from that session - only the bound session can take the lead - star routing: workers write only to the lead, only the lead writes to all - content is sanitized, and mail that carries a configured token is refused - per-sender rate limit and per-recipient unread cap - every send attempt goes to the audit log Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A session is solo by default and InBand delivers no mail to or from it. /lead <team> makes a session the lead of a team, /join <team> adds it as a worker, /solo removes it. The previous lead of a team becomes a worker and gets a notice. Star routing now applies inside each team: a worker writes only to the lead of its team, only the lead writes to all, and all means the team. No mail crosses teams. ping lists only the viewer's team, and its wake log keeps only the wakes of that team. The mesh routing option is removed. clippy.toml accepts SQLite and InBand in doc comments, which the current clippy flags. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018fHKe4hh7UshHrrNi8HVSJ
Thirteen attacks from an agent under prompt injection, in attack_tests.rs, found eight ways to act as another mailbox or to take the lead role. Fixes: - An unbound mailbox can be used only by a request signed for its session, or by a token whose patterns name that one mailbox. A shared family token such as claude-* no longer speaks for any session. - The bridge checks the token patterns itself: a Codex token cannot act as a Claude mailbox, even with a session claim. - bind_session takes the session from the signed request and never moves an existing binding to another session. - /lead, /join and /solo need a signed session, or the admin token of the user's CLI. - "all" is reserved like "codex" and cannot be a mailbox. - Content loses its escapes and invisible chars before the channel tag check, so a tag split by a zero-width char is escaped too. The list of invisible chars now covers soft hyphens, variation selectors and tags. Each protection was removed in turn to check that a test fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018fHKe4hh7UshHrrNi8HVSJ
Codex 0.160 starts one stdio MCP server per session and puts the calling session in _meta.sessionId of every tools/call. The model only writes the tool arguments, so it cannot change that field. A codex-<uuid> mailbox now needs a request whose session is exactly that uuid, for sends and for bindings. Claude Code sends no session in _meta, so Claude keeps the signed channel shim as its proof of session. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018fHKe4hh7UshHrrNi8HVSJ
OpenCode 1.18 sends no session in the _meta of MCP tool calls, but it passes the calling sessionID to the tools of a plugin. InBand will reach OpenCode through a small plugin, and each session gets the mailbox opencode-<16 hex chars of the SHA-256 of its session id>. OpenCode ids are case sensitive, so the digest keeps two ids that differ only in case apart. A request for such a mailbox must carry the session that owns it, the same rule as codex-<uuid>. Several OpenCode sessions can now work at once, in the same team or in different ones. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018fHKe4hh7UshHrrNi8HVSJ
A worker with the Claude token could read the lead's mailbox, and get_messages would mark that mail read, so the lead never saw it. Every read now goes through the same check as a send: peek, fetch, wait, channel subscription, presence and the Codex registry need the session that owns the mailbox. Family subscriptions and clear need the admin token. History shows a session only its own mail, and ping without a viewer is for the admin token only, so neither crosses teams. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018fHKe4hh7UshHrrNi8HVSJ
Hooks and the channel shim can now send x-inband-session with a signed request. The signed payload includes it only when it is present, so the signatures of v1 clients do not change. A changed, removed or added session fails the signature, and a session id can only hold chars that cannot end a line of the payload. Bearer requests never carry a session: their token is shared by every session of the family. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018fHKe4hh7UshHrrNi8HVSJ
Codex wakes run codex queue --thread <session> --message <prompt> as an argument list, never through a shell, and the CLI is killed after the timeout. OpenCode wakes post to /session/<id>/prompt_async: an OpenCode session mailbox wakes the session bound to it, and the fixed opencode mailbox of v1 clients wakes the most recent root session. The HTTP client ignores system proxies, since wake URLs are loopback only, and does not follow redirects. OpenCode session ids are checked before they become a URL segment: the url crate drops "." and ".." segments, so an unchecked id could reach another endpoint. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018fHKe4hh7UshHrrNi8HVSJ
The axum router serves the routes of the hooks and the channel shim: /health, /subscribe, /presence, /claude/hook, /codex/hook, and the team commands /team/lead, /team/join and /team/leave. Every request passes three layers. The loopback guard refuses a Host other than 127.0.0.1, localhost or [::1], which a DNS rebinding page sends, and any request with a browser Origin. Authentication reads the body, checks the bearer token or the signature, and attaches the caller and its signed session. The routes then call the bridge, which checks what that caller may do. A Claude SessionStart signed for a session binds the mailbox to it. A Codex hook must be signed for the session its payload names. /health gives the full status to the admin token only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018fHKe4hh7UshHrrNi8HVSJ
The MCP endpoint runs on rmcp's Streamable HTTP service without MCP sessions, like the v1 daemon, behind the same loopback guard and authentication as the other routes. Tools: send_message, get_messages, wait_for_messages, get_history, ping and clear_conversation. There is no claim_lead tool: only the user's commands change roles. Identity never comes from tool arguments. A tool call acts as the authenticated client, with the session of a signed request, or for a bearer request the _meta.sessionId that the client harness writes, as Codex does. A session id that a model slips into the arguments changes nothing. wait_for_messages sends a progress heartbeat at once and every 20 s, so long waits survive client timers, and returns a preview that leaves the mail unread. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018fHKe4hh7UshHrrNi8HVSJ
inband daemon loads config.json, tokens.env and bridge.db from the install directory (--dir, else $INBAND_HOME, else ~/.local/share/mcp-servers/inband), opens the socket and serves the hook routes and the MCP endpoint. It refuses to start with a weak token, an invalid config, or a non-loopback bind while auth is disabled, and warns when tokens.env can be read by other users. On SIGINT or SIGTERM it stops accepting requests and gives open waits a 5 s grace: a 30 min wait_for_messages must not hold a systemctl stop. The phase 0 channel spike leaves main.rs; the channel comes back in phase 3. The release binary uses about 9 MB of memory at rest. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018fHKe4hh7UshHrrNi8HVSJ
The job checks formatting, runs clippy with warnings as errors and the tests, and audits the dependencies with cargo audit. rust-toolchain.toml pins Rust 1.97.0, so a new compiler release cannot break the build with new lints. The workflow uses no third-party action: rustup comes with the runner. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018fHKe4hh7UshHrrNi8HVSJ
Measured on real daemon outputs with the o200k and cl100k tokenizers: compact JSON instead of indented JSON saves 20 to 27 percent of the tokens of every tool result. ping now carries every agent field, null when empty, so its agents form a uniform table: as TOON it takes 346 tokens against 443 in compact JSON and 607 in indented JSON. Messages stay JSON. In a TOON table the sender becomes a column position, while JSON labels it on every message, and the sender is what agents check to know who speaks. The gain there was 10 percent. toon-format is the official Rust implementation, without its CLI feature. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018fHKe4hh7UshHrrNi8HVSJ
The inband binary now runs the client side of every agent: - inband hook claude: SessionStart binds the mailbox to the signed session, PostToolUse reminds a working session of waiting mail, SessionEnd marks it offline. UserPromptSubmit runs /lead x, /join x and /solo, which only the user can type. - inband hook codex: forwards SessionStart and Stop for the session of the payload, and runs $lead x, $join x and $solo (Codex refuses unknown slash commands before its hooks run). - inband shim: the stdio MCP server of a Claude Code session. Claude names no session in its MCP requests, so the shim reads its session from the Claude registry (it follows /clear), signs every tool call for it, and pushes new mail as channel events. It answers server/discover itself: rmcp 3.5 otherwise keeps asking for the 2026-07-28 request metadata after the fallback to initialize. - inband opencode: what the OpenCode plugin runs with the sessionID OpenCode gives each tool. The plugin (opencode/inband.js) stays thin: tools, the protocol in the system prompt, and the team commands. Tested end to end with Claude Code 2.1.287, Codex 0.160.0 and OpenCode 1.18.34 against the daemon: team commands, sends, wakes of the right session, and refused lead impersonation in each client. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018fHKe4hh7UshHrrNi8HVSJ
inband install sets up this machine and is safe to run again: - the binary in ~/.local/bin, tokens.env (0600, a token per client) and config.json (0600), checked by the daemon's own config loader; - Claude Code: the hooks in settings.json, /lead, /join and /solo, and the shim as the inband MCP server (claude mcp add); - Codex: the hooks in hooks.json, the $lead, $join and $solo skills, and the HTTP MCP server (codex mcp add); - OpenCode: the plugin, baked with the installed binary path, and the /lead, /join and /solo commands; - the systemd user service. It migrates a v1 install: it replaces the v1 hooks, MCP entries and commands, gives the OpenCode token the opencode-<session> mailboxes, drops the mesh routing, and keeps a .bak of every file it changes. Files and hooks of the user stay as they are. --client prepares a machine whose daemon runs elsewhere. install.sh builds with cargo from a checkout, or downloads the static binary of the latest release and checks its SHA-256. A v* tag builds static musl binaries for x86_64 and aarch64, so they run on any distribution, Raspberry Pi OS included. Tested in a fresh home with the real Claude Code, Codex and OpenCode: after the install alone, the three join one team and mail goes through. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018fHKe4hh7UshHrrNi8HVSJ
Remove the TypeScript v1: the daemon, the shell and Bun hooks, the channel shim, the Windows script and their tests. The crate moves to the root of the repository, so install.sh, cargo install and the CI work from a plain checkout, and the CI runs on every branch. The README and the reference describe v2: teams, the commands of each client, the installer, the identity model and its limits. docs/migration.md gives the steps to move a v1 machine, and back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018fHKe4hh7UshHrrNi8HVSJ
opencode mcp add writes opencode.jsonc, so a v1 install keeps its inband MCP server there, and OpenCode would list every InBand tool twice next to the plugin. The installer now cleans both files; a file with comments, which it cannot rewrite without losing them, is left to the user with a note. Found by migrating a real v1 install, made with the v1 installer, to v2 in a fresh home: Claude Code, Codex and OpenCode then joined one team on the v1 database, each with the InBand tools once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018fHKe4hh7UshHrrNi8HVSJ
Codex used the HTTP endpoint with a bearer token that it read from its environment, so every shell that started Codex had to load tokens.env first. Codex also names the session in the _meta of each call to a stdio server, so inband shim --codex now serves it: the shim reads the token file itself and signs the session that Codex names. One Codex process serves several sessions, so the session comes from each call, not from the process. The model writes only the arguments, as before. The installer registers the shim and lets Codex call the InBand tools without approval prompts: a session that a wake starts in the background has nobody to approve the call that reads its mail. Tested with the real Codex after the install alone, without any token in its environment: $join x, then a send to the lead; a send as a Claude mailbox is refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018fHKe4hh7UshHrrNi8HVSJ
Every function, type and constant now has a Doxygen block: @brief, then @details for the reasons, @PARAM and @return when they tell more than the name, and @throws for the errors. The text follows ASD-STE100: short sentences, active voice, present tense, simple words. Plain comments inside the code are gone; what they explained, the security reasons above all, is now in the @details of the function. The doc comments that tools read stay plain text: the tool argument structs, whose docs become the JSON schema that the models see, and the clap types, whose docs become the --help text. Both outputs are unchanged. Clippy wants a "# Errors" section and backticks around identifiers; Doxygen wants @throws and bare names after @PARAM, so these two lints are off, with the reason in Cargo.toml. Also removes dead code found on the way: the WakeDisposition variant DeferredActiveTurn, never produced, and Client::list_tools, unused since the tool list comes from the binary. The OpenCode plugin and install.sh get the same treatment; install.sh --help now prints a real usage text instead of its own comments. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018fHKe4hh7UshHrrNi8HVSJ
The Doxygen tags of the previous commit render as raw text in rustdoc, and Doxygen does not read Rust. The docs now follow the Rust API guidelines: a one-line summary, paragraphs for the reasons, and an "# Errors" section on each public function that can fail. Parameters and return values are named in the prose only when the signature does not already say it. Docs that only repeated the name of a private helper are gone. The text stays in ASD-STE100 English, and every security reason that the old inline comments gave is still there. The doc lints of clippy are back on, and rustdoc builds with -D warnings, private items included. The tool schemas that models see and the --help text are unchanged. The OpenCode plugin uses plain JSDoc, and install.sh plain comments. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018fHKe4hh7UshHrrNi8HVSJ
Claude Code sends the text of a command file, such as ~/.claude/commands/lead.md, to the model with the trust of the user. An agent that changed that file could thus give instructions in the name of the user the next time they type /lead. Tested with the real Claude Code TUI: the injected line reached the model. The binary now holds the exact text of each file that it installs (module assets), and the hooks compare them: - at each session start of Claude Code and Codex, and in the context of each OpenCode session, the changed files are listed in a warning for the user, and the model is told not to follow them; - a Claude Code team command whose command file differs is refused before the model sees it; - inband install restores the files. The attack surface is also smaller: - the Claude Code commands have disable-model-invocation, so the model can neither see their description nor run them; - the Codex skills are gone, and the installer removes the old ones: Codex gives the hook $lead x without a skill, and it put the skill descriptions in the context of every session. Tested in the real TUIs: /lead x works with the hidden command; with a poisoned lead.md, the warning shows at start, /lead is blocked, and the injected text never reaches the model. Also tested for the first time with the real clients: new mail reaches an open Claude Code session as a channel event, and a lead message wakes an idle Codex TUI, which reads its mail through the shim. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018fHKe4hh7UshHrrNi8HVSJ
The ruleset of main requires a status check with the name test. The job had the name rust, so the check did not start and the pull request stayed blocked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
InBand v2 replaces the Bun daemon, the shell hooks and the channel shim with one static Rust binary. The main change is a different security model: the daemon knows which session calls, so an agent cannot act as another one, the lead included.
v1 clients cannot talk to a v2 daemon, so every machine of a setup moves at once. See
docs/migration.md.What changes
_metaof each tool call./lead x,/join xor/solo($lead xin Codex).sessionIDto the binary, and each wake reaches the exact session../install.shbuilds the binary, or downloads the static release binary and checks its SHA-256. Theninband installconnects Claude Code, Codex and OpenCode, and installs the systemd user service..bakof each file that it changes.v*tag builds static musl binaries for x86_64 and aarch64 (Raspberry Pi included).Testing
cargo audit, andsh -n install.sh.lead.mdis reported at session start, and/leadis blocked before the model sees it.Not covered by these tests
v*tag runs it.docs/migration.md.https://claude.ai/code/session_018fHKe4hh7UshHrrNi8HVSJ
🤖 Generated with Claude Code
Generated by Claude Code