@sjawhar/claude-envoy
v6.97.0
Published
Claude Code plugin for Legion's Envoy bus
Readme
claude-envoy
Claude Code plugin for Legion's Envoy subsystem. One MCP stdio server consumes Envoy NATS events and puts them into the current Claude Code session's own conversation, and takes a person's message from Dispatch's Agents page as that person's own turn.
Architecture
bin/dispatchis thedispatchcommand, which Claude Code puts on the Bash tool'sPATHwhile the plugin is enabled; it runs the built bundledist/dispatch.js. Agents reach Dispatch through it (see "Dispatch" below)..omp-plugin/plugin.jsondeclares an emptymcpServers, so Oh My Pi starts no server from this plugin: the channel server needs Claude Code's session identity and exits without it, and an omp session already gets Envoy and Dispatch from@sjawhar/pi-envoy. omp reads that manifest before.claude-plugin/plugin.jsonand a manifestmcpServersreplaces.mcp.jsoninstead of merging with it; Claude Code reads only.claude-plugin/plugin.json, so it still launches the server. Omitting the key would not work — omp would fall through to.mcp.json. Skills are unaffected: both harnesses resolve them from.claude-plugin/plugin.json.hooks/hooks.jsonrunsdist/session-hook.js open-askson everySessionStart(startup, resume, clear, compact, fork). Each of its hooks that resolves Dispatch with commands run has a 20 stimeout(Claude Code's field is in seconds): a!dispatch.tokenmay run for up to 10 s in the hook's own process after Bun starts, so the hook outlasts it and says why rather than being killed silently. It writesexport DISPATCH_HOST=claudeandexport ENVOY_CONFIG_FILE='<path>'(the session's envoy.json, below) toCLAUDE_ENV_FILEonce each, which Claude Code sources into every later Bash command of the session, records the current session id for the channel server, and puts the session's open Dispatch asks into the model's context (Dispatch authored-ask summary:;unavailable: <reason>when Dispatch cannot be reached; nothing when Dispatch is not configured or a file setsdispatch.enabledto false, unless the session's missing file is what turns it off while~/.config/opencode/envoy.json, which is not read, is there: thenunavailable: <notice>, the notice naming what to do with it, after the lost-DISPATCH_URLtext whenDISPATCH_TOKEN_FILEis set). Before that, whether Dispatch is on or off, a checkout's.opencode/envoy.json, which is not read, is oneenvoy: <file> is not read: mkdir -p … && mv …line while the checkout has no.envoy/envoy.json. Thedispatchcommand reads the fileENVOY_CONFIG_FILEnames wheneverDISPATCH_HOSTis set (dispatch loginreads none, anddispatch proxynone withoutDISPATCH_TOKEN_BROKER=1). A subagent's Bash can lack what the hook writes there (Claude Code issue 46696); itsdispatchcommand, finding noDISPATCH_HOST, then takes hostclaudefrom theCLAUDE_CODE_CHILD_SESSION=1Claude Code sets in every Bash, and readsCLAUDE_CONFIG_DIRitself. With Dispatch configured,dist/session-hook.js dispatch-firstputs thedispatch-firstskill into the context of every session on the sameSessionStartevents and of each subagent (SubagentStart), as a hook of its own so neither output crowds the other past Claude Code's 10,000-character hook limit. On a resume or fork Claude Code adds it only when the transcript does not already hold the same text, so a session keeps one copy, and one opened before the skill shipped gets it. On the sameSessionStartevents and at eachSubagentStart,dist/session-hook.js answers, a third hook of its own, puts what people wrote to the session in the last 72 hours (answers to its asks, replies to its comments, comments on documents it wrote, messages to it) into the context, read fromGET /api/v1/agents/{session_id}/answersfor the hook input'ssession_id, which atSubagentStartis the parent's: the same list, under 8,000 characters, that every Oh My Pi model request carries (@legion/envoy-client/session-answers). It prints within 800 ms of its start, Bun's start-up included, or 150 ms after its own code begins when the start-up alone took longer, carrying the last list read (answers.jsonin the session's Dispatch state directory) when Dispatch has not answered by then, or one line saying the list could not be read and why when no list read before has an item to show, and exits 50 ms after that, always with status 0 and with no output when there is nothing to show; itstimeoutis 5 s. A Dispatch build older than the answers route answers its own404 NOT_FOUND"no route for …": the hook then adds no line (a list read before from it is still carried, its left-out line naming no command) and writes one line to stderr naming that Dispatch. A proxy's 404 page or a 200 that is no answers list is a failed read like any other. A!command in envoy.json runs in a process of its own that the hook starts detached, one per session at a time, and waits on until that same deadline: a slower command costs that hook the fresh list, never the bound, and still runs to its end (or its 10 s timeout, its output file removed either way) in that process, which reads the list with its token for the next hook; until then only a list read from the Dispatch URL envoy.json names now stands in, never one another Dispatch answered. On everyUserPromptSubmit,dist/session-title-hook.jsrecords the name a person gave the session (below, "Session title"); itstimeoutis 5 s, and it is a bundle of its own because Claude Code holds the prompt until it returns.- The session's messages come from a durable consumer the listener keeps for it on
Envoy's notification stream and relays on
notifications.envoy.deliver.<session_id>, which the server subscribes before it registers: the session's own subject, the stored copies of role messages to a role it holds, and every followed topic, in stream order. The server answers each framereceivedas it decodes anddoneonce the session has it: in a Legion pane once the bridge reports that Claude Code took the delivery, and in a terminal session once the mod reports the write: a row stored in the turn running ($.session.append), or, while the session is idle, a prompt the engine took ($.prompt.submit). Envoy sends a frame the mod reported no write for again, and the mod writes each Envoy event once, by its event id (writeOnceinhooks/mod-writer.ts), so the repeat is answered from the first write's record. A frame not taken yet when Claude Code stops, or published while the session was not running or disconnected, comes again and is delivered once, for up to 72 hours. Anotifications.team.<name>topic is stored and delivered like any other followed topic. The resume point is kept inreplay-<session id>.jsonwith the ledger below.packages/envoy/docs/architecture.md, "Runtime shape" (its "Session consumers" item), states the listener's side. - Nothing is fetched back: a message published while the session was not running, restarting or
disconnected (NATS restarting, the connection dropped) waits in that consumer and is delivered
when the session returns, the same way as any other, with a line saying when it was published
while the connection was down. It runs nothing: a Dispatch delivery delivered this way is that
event and no more.
The server pings NATS every 10 seconds and drops a connection that leaves two pings unanswered,
so a connection that stops answering without closing is left within 30 seconds and redialed,
and the listener restarts the relay at the consumer's ack floor.
A connection nats.js closes for good is replaced too. nats.js gives up after a repeated
authorization refusal under an nkey seed or no credential, and when the session's broker token
cannot sign the hub's greeting (a hub that sends no nonce). The server dials a new connection
as it dialed at start, warning of each redial on stderr, subscribes the relay subject on it and
registers a new epoch, so the listener restarts the relay at the ack floor. Until then the
session is told once that it receives nothing, naming why, and once that it receives again. A
dial that fails for good (an authorization refusal under a seed) is dialed again at the next
heartbeat, and a
/clearmade meanwhile completes on the new connection. What the consumer does not hold: anything older than 72 hours, anything from before the session followed the topic, and anything from before it first registered; a/clearstarts afresh, as a new session does. What the session was delivered, and where it read to, are kept inreplay-<session id>.jsonin the plugin's data directory, so a resume delivers nothing again (up to 20,000 messages in 72 hours); a crash between handing a message over and recording it can deliver it twice, never lose it. A message that fails three times is replaced by one notice naming it. A registration the listener can give no consumer is refused by name, and the server says once, on stderr and as a notice to the session, that Envoy inbound is unavailable, and asks again at every heartbeat. When a registration is accepted after that, it says once on stderr that the session receives again, and tells the session once, as a notice, that Envoy inbound is restored and that what the stream stored meanwhile arrives now. A registration the listener answers with the bus-outage 503 (its message bus did not answer) is held for two minutes from the first such answer, also where its retry got no answer or a 5xx that names no reason; after that the server says once that the registration is not recorded for certain, since the retry may have landed, and, when one is accepted, that the listener recorded one. A retry the listener refuses with a reason, such asconsumer_limit, is told at once as Envoy inbound unavailable. A refusal or a lost relay subject after that notice is told once more, as Envoy inbound unavailable, and the accepted registration after it says that Envoy inbound is restored. An edge listener's 503repositories_unknown(it could not read the repositories of the session's projects) is told at once as Envoy GitHub topics withheld: the listener withholds the messages of the session's GitHub topics. If the listener already held the session's registration, it kept that registration and the session's consumer, so the session receives its other messages; if it held none, the session receives nothing until a registration is accepted. The notice and the stderr line say both. The accepted registration after it says that the listener follows those topics again. A refusal or a lost relay subject after that notice is told once more, as Envoy inbound unavailable. A session whose shutdown has begun registers nothing, and is told neither that Envoy inbound is unavailable nor that it is restored. - No receipt is published. A role message reaches this session as a forward the listener stored on
the session's own subject, which its consumer relays and whose
doneanswers for it; the listener waits only for the stream's acknowledgement that it stored the forward. A frame's reply subject is a publisher's acknowledgement inbox, and an empty receipt there fails the publish. - The server registers the session as self-subscribed with what it can take now
(
sessionCapabilitiesinsrc/envoy-channel-server.ts), read again at every registration. A terminal session reaches the model only through its mod (hooks/mod.ts,src/mod-session.ts), so it advertises nothing until the mod connects andaside,btwandsteeronce it has; a Legion pane, whose deliveries go to the bridge's inbox (below), advertisesasideandsteerfrom the start and gainsbtwwith the mod. It registers again as soon as the link hears from the mod - its hello, or its first poll, since a mod says hello once per Claude Code process - so Dispatch learns what the session takes without waiting for a heartbeat. With no capability the listener refuses every targeted delivery (session … does not advertise aside) and Dispatch shows the session as taking no messages, which is the right answer for a session nothing can reach. A plainenvoy_sendnames no mode, so the listener stores it, and it answersno_receiverwith norecipient_state: the sender reads that the session runs but takes no message into its conversation now, and never that it islive. - A targeted Dispatch delivery the shared renderer rejects is never shown to the model: when it
names a message, the server posts
Invalid Dispatch targeted delivery frametoPOST /api/v1/messages/{id}/replyso the attempt fails visibly; otherwise it is logged and dropped. - A resumed server rebuilds the interests its session id already registered.
envoy_listreports the union of live NATS subscriptions and registry interests with each topic'ssource(live,registry,both). envoy_role_setpersists the held role in${CLAUDE_PLUGIN_DATA}/roles/<session-id>.json, which names the writing process's client instance beside the session id and the role.claude --resume <session-id>finds that file and soft-reclaims the role with the savedprevious_session_id; a plain relaunch is a new session and inherits nothing. A record another process wrote is pressed only while this process holds no role, since twoclaudeprocesses of one user share the state directory and a record is keyed by session id alone. The listener moves the role off that predecessor only when the predecessor has no live registration, when its live registration carries this process's own client instance id, or when either side carries no instance id. A predecessor another process still runs keeps the role, and the claim is refused naming it: this session goes on running and registered without the role, claims it again only on an explicit claim, and keeps the predecessor's role file, since that record belongs to the live holder. A claim of a role already held under this session's own id is decided on the standing claim: the listener grants it to the process that claim names, grants it once nobody renewed that claim inside its live window, and otherwise refuses it naming this very session, which keeps the role and the record here and asks again on the next heartbeat. Only a refusal naming a different session ends the role and removes the record. Every claim that lands, the tool's, a restore's, a heartbeat's or a Legion pane's, writes each warning the listener answers it with to stderr, naming the role and the session, such as that it handed over no message of the replaced session and why;envoy_role_setalso returns them beside the interest row, aswarnings. Every healthy registration heartbeat checks and reasserts the role if the listener lost it, and it confirms the role only when the lookup names this session and this process and reports no hand-back (handed_back); each heartbeat also renews the claims this process holds, whatever topics that registration carries, and renews no claim the listener has marked handed back. A client built before a release stated its process can hand this session's role lane back without freeing the claim, which the listener marks rather than frees, so the mark is read as a role this process does not hold and the next heartbeat claims it back, its grant a fresh record with no mark. This process hands no lane back itself. Shutdown (stdin end, SIGTERM, SIGINT, or the SIGHUP a closing pane sends the whole process group) drains NATS and deregisters the session, naming this process's client instance id, so the listener removes the registry entry only while it still carries that id or none, and every topic hand-back names it too, so a release frees only the role claims this process holds; a release the holder's own renewal beat under each of the route's three conditional deletes fails rather than reporting one it did not make./clearmints a new Claude session id, but a stdio MCP server keeps theCLAUDE_CODE_SESSION_IDit was spawned with. The SessionStart hook writes the current id to${CLAUDE_PLUGIN_DATA}/sessions/<claude-pid>/session-id(keyed by theclaudeprocess both the hook and the server are children of, so concurrent sessions never share a file). The server polls that file every 250 ms and follows a changed id within that time, with the heartbeat as the fallback: it subscribes the new direct subject first, deregisters the old id under this process's client instance id, drops the old subject, registers the new one, and moves a held role by soft claim. The listener removes the old entry only while it still carries this instance's id, so a process that resumed that id keeps both its registration and its role. The listener merges registered topics into the entry and never removes one, so the old subject goes before the registration, and the server sends its registry writes one at a time, each registration reading the id and topics when it runs. Asks authored before/clearcarry the old Dispatch actor id and drop out of the open-asks summary (the same shape as OMP on fork).ENVOY_SESSION_ID(QA override) disables the handoff.envoy_inboxis local recovery state: the most recent 50 event summaries, with no envelope body, ordered newest first.bin/envoy-send.tssends direct messages through the Envoy listener's HTTP API, to the listener and with the bearer a command resolves:envoySettingsover the envoy.jsonenvoyConfigPath("command")chooses (theENVOY_CONFIG_FILEtheopen-askshook hands the session's Bash first), withENVOY_URLandENVOY_TOKEN_FILEorENVOY_TOKENover itsenvoysection. With Envoy off it sends nothing and exits 1, saying why. It sends through envoy-client's own send (createEnvoyClient().send), the transport every other client uses: one idempotency key on every attempt, so the listener stores the message at most once; an attempt with no answer, a 408 or a 5xx sent again under that key; and the listener's URL named only asurlForTextnames it, never its user info. It sends the session its shell names (ENVOY_SESSION_ID, elseCLAUDE_CODE_SESSION_ID) assource_session, so the listener's limit on each session's sending counts its messages. A send the listener stored without this machine's credential (a listener that asks for none takes one whose broker trade failed) prints itsSentline, exits 0, and writes one line to stderr naming why it went without the credential, and where the refusal is final (a revoked sign-in) that it is, with its remedy. A send that may have arrived (an attempt that got no answer, a 408 or a 5xx: the listener writes no 408, and a hop in front of it can answer one after it forwarded the send) is not a failure: it exits 75 (EX_TEMPFAIL), names the key, and prints the command that sends it again under that key, which the listener drops as a repeat if the first copy arrived:cd <dir> && [ENVOY_CONFIG_FILE=<file>] [ENVOY_URL=…] [ENVOY_TOKEN_FILE=…] [ENVOY_SESSION_ID=…] bun <the envoy-send.ts it ran> --idempotency-key <key> <target> <message>, which carries what chose the listener so it goes there from any shell (ENVOY_CONFIG_FILEwhere an envoy.json was read, the others where set), each word quoted so bash and zsh read it alike. Where that command would hold a secret this process withholds (the message names one, say), a printed copy would send a different message under the same key, and where itsENVOY_URLis not a plain http(s) URL (one with user info of any length, say) the URL is never printed; either way only the key is printed, with how to resend the original. A resend under a key exits 75 on any failure, since the send before it may have arrived. A send whose idempotency key another sender's message already holds stored nothing: it printsClaude Envoy send not delivered: …, naming that message's event id, and exits 1; run again without the key, it goes under a new one. Any other refusal, one for the sender's rate among them, prints the listener's own sentence afterClaude Envoy send failed:, exits 1 and is not sent again; so does a listener that refused the connection or whose name did not resolve.
What a delivered line carries
Every line the server writes into the session is one Envoy envelope as the shared
@legion/envoy-client/delivery renderer renders it; raw envelope bytes are never exposed.
The rendering names the sender (from), the time (at) and the event's id (id), and, where the
envelope carries them, urgency, expects_reply — what the sender wants back, as a string:
false (nothing, so do not reply and do not acknowledge), optional or required, the old none
reaching the reader as false — re for a correlated inbound event, and
reply_with, the command that answers it.
Three envelope fields the server acts on and shows nowhere:
| Field | What the server does with it |
| --- | --- |
| event_id | Envoy event identity of this publish; the listener mints a new one for every send. The server writes one copy of a publish that arrives on two overlapping subscriptions. |
| dedupe_key | Identity a re-send shares with the first delivery; the server drops the re-send. |
| topic | The NATS subject the event arrived on: the session's own subject, a followed topic, or a role lane. |
Envoy tools
The server exposes the shared Envoy messaging contract, every tool of envoyToolSpecs: the ten
envoy_* tools, envoy_inbox and envoy_role_get among them, and slack_post, a reply in a Slack
thread. It exposes no Dispatch tool: a dispatch_* call is an unknown
tool.
A tool that fails answers a tool result with isError: true whose text is the error, so the model
reads the listener's own sentence for a refused send or publish, a refusal for the sender's rate
among them. An unknown tool, and a call before the server has started, answer a JSON-RPC error.
Dispatch
Agents reach Dispatch through the dispatch command in Bash: dispatch --help lists the
commands, dispatch <command> --help each one's flags, and the dispatch skill teaches them. The
command runs as the Claude Code session that called it: the open-asks hook names the host
(DISPATCH_HOST=claude), and the command reads the session id from CLAUDE_CODE_SESSION_ID,
which Claude Code sets fresh in every Bash command and moves to the new id on /clear, so a
DISPATCH_SESSION_ID inherited from a parent session is ignored. A write that makes the session
follow an ask prints Following ask <id> on <issue>: … once per ask, after its result; a result
longer than 25,000 characters is written to a file the output names. It reads the envoy.json
below on every call. dispatch login acts as no session and reads no envoy.json, and
dispatch proxy reads it only under DISPATCH_TOKEN_BROKER=1.
Dispatch asks remain on native Dispatch. An Envoy delivery is one-way ingress, not a remote human approval surface.
Codex CLI
The Codex CLI plugin is a package of its own, @sjawhar/codex-envoy, built from
this package's source and released with it at the same version. One package cannot be both:
Codex's plugin validator refuses a manifest that names its hooks file, so Codex's hooks sit at
hooks/hooks.json, where Claude Code reads its own, and an npm install takes a package's root.
Codex reads the repository's .agents/plugins/marketplace.json, which names that package:
codex plugin marketplace add cybermonklabs/legion
codex plugin add codex-envoy@legion-pluginsThe package's bin/dispatch is the dispatch command for a terminal of your own, and its npm
bin. Run there what the plugin's dispatch tool cannot hold: the tool ends a command after
120 s, and the device login of a machine with no identity of its own,
dispatch login --device --person <address>, waits until that person approves its code. Run it
from the installed plugin, or from npm:
"${CODEX_HOME:-$HOME/.codex}"/plugins/cache/legion-plugins/codex-envoy/<version>/bin/dispatch login --device --person <address>
npx --package @sjawhar/codex-envoy dispatch login --device --person <address>Where the deployment serves Dispatch sign-ins, the same command with --scope person (or
--scope none) signs a session or tool in to Dispatch alone instead: the person approves the code
on Dispatch's machine-login page, ticking the scopes it may hold, and the login enrolls no session
and reads no secret:
npx --package @sjawhar/codex-envoy dispatch login --device --person <address> --scope personIt runs dist/dispatch.js with bun, as the plugin's server does, and follows the link npm
makes for a package bin to find it.
bun scripts/build.ts --codex-out <dir> builds it from this tree into a directory outside the
repository: codex/'s manifests, hooks, README and bin/dispatch, this package's skills and a
fresh dist/.
A skill that sets disable-model-invocation: true, which Codex's validator refuses, is shipped
with Codex's own form of it, an agents/openai.yaml whose policy.allow_implicit_invocation
is false: the skill stays out of the model's context until a person names it as $<skill>.
Start codex as usual and trust the plugin's hooks when Codex asks (it asks again after an update
that changes them; an untrusted hook does not run). The session reads the same envoy.json as every
other session on the machine: the file ENVOY_CONFIG_FILE names, else
${XDG_CONFIG_HOME:-~/.config}/legion/envoy.json. Under the Codex home (CODEX_HOME, else
~/.codex) the plugin reads the session's transcript, writes only to the state directory Codex
gives each plugin (plugins/data/), and adds to Codex's message queue through codex queue;
it never touches Codex's configuration.
Measured on Codex CLI 0.154.0.
Which sessions get Envoy depends on how Codex runs them.
A session in a codex process of its own (the terminal on 0.154.0, codex exec) registers with
Envoy and gets everything below.
Codex's shared app server runs several sessions in one process: codex agents (with or without --no-daemon), a plain codex that joins a running app server, and on 0.170.0 every terminal session, which runs in a background codex app-server --managed-daemon.
The plugin cannot tell those sessions' Envoy traffic apart, so there it registers none of them:
they get no Envoy messages and do not show on the Agents page, and the hook tells the model so.
Everything else still runs there: the dispatch tool, as the session that calls it, and the
SessionStart hooks (the open-asks summary, the dispatch-first skill and the answers list).
A fork (/side, /btw) is never registered: its session's registration stays where it was.
Neither is an ephemeral session (codex exec --ephemeral), which no message could reach.
codex/.codex-plugin/plugin.jsonnames the skills and one MCP server,bun ./dist/envoy-channel.js --host codex, run in the plugin's own directory ("cwd": "./"; Codex expands no${PLUGIN_ROOT}in a server's arguments). Codex hands a plugin's server onlyHOME,PATHand a few more, soenv_varsnames the ones the server reads.- The session appears on the Agents page at its first prompt, not when the terminal opens: Codex
gives the MCP server no session id, and its
SessionStarthook, which runs at the first prompt and again after/new, records the id under thecodexprocess both are children of (hooks/codex-hook.ts,src/codex/codex-session-record.ts). Codex starts one MCP server per thread, so a/newor a fork starts another; one server percodexprocess owns the session (src/codex/codex-owner.ts) and the others stand by, serving only their thread'sdispatchcalls. After/new, the owner moves the registration to the new session at its first prompt. Until then, a message to the old session can still be queued into it, since Codex runs the old thread'sSessionEndhook only when it unloads that thread:thread_unload_delay(60 s by default, and configurable) after the thread is idle with no subscriber, and after it has stopped that thread's servers. Until every server started before the new thread's has exited, the new thread's own Envoy tools (envoy_sendand the rest) answer that another server serves the session; messages to it arrive meanwhile, and itsdispatchtool works. A fork or an ephemeral session (codex exec --ephemeral) keeps no transcript and is never registered, since Codex refusescodex queuefor an ephemeral thread. - The
dispatchtool acts as the thread whose turn called it, which Codex names on every tool call (_meta.threadId), and runs in the directory that thread's newest turn ran in. - A message reaches an idle session through
codex queue, which Codex takes as a new turn a few seconds later. One that arrives during a turn waits in the plugin's inbox, and thePostToolUsehook (hooks/codex-tool-hook.ts) hands it to the model in the turn's next request; one no tool call took is queued when the turn ends (src/codex/codex-delivery.ts). A person's Send or Aside is accepted on Dispatch and arrives as their own words; a/message is answered that it was not run. - A BTW is answered by a separate
codex app-serverthat forks the session's conversation ephemerally with plugins and hooks off, a read-only sandbox and no approvals (src/codex/codex-cli.ts); the session's own conversation is left as it was. - The live view reads the session's transcript file into the frames the Agents page draws
(
src/codex/codex-transcript.ts,src/codex/codex-agent-stream.ts). - Agents reach Dispatch through the server's
dispatchtool, which takes the command's words asargsand its standard input asstdinand runsdist/dispatch.jsas the session: Codex puts no plugin command on the shell'sPATH, and its default sandbox keeps shell commands off the network. The manifest pre-approves that one tool, since Codex asks before every call of a plugin's tool; the Envoy tools are asked about as usual. Thedispatchcommand itself takes hostcodexfromCODEX_THREAD_ID, for a shell that can reach Dispatch.
tests/codex-real.test.ts runs the real binary (LEGION_TEST_CODEX=<path to codex>) against a
stand-in model; it skips without one, and nothing in CI installs Codex.
Skills
The plugin ships eleven skills, claude-envoy:envoy, claude-envoy:dispatch,
claude-envoy:dispatch-first, claude-envoy:dispatch-writing-specs, claude-envoy:asd-ste100,
claude-envoy:outside-message, claude-envoy:plain-words, claude-envoy:agent-secrets,
claude-envoy:approval-review and the reviewer's pair,
claude-envoy:thermonuclear-code-quality and claude-envoy:thermonuclear-deep-review.
The first four teach the Envoy tools, the dispatch command and how to write a spec; asd-ste100 gives the
ASD-STE100 rules for text a person reads; outside-message holds the steps and the approval before text
reaches a person outside the company; plain-words the empty verb phrases to delete from any text a
person reads, and agent-secrets the secrets broker's client, which gives a credential to one command
in that command's environment, so no value reaches your shell or your transcript.
approval-review is read by no other session than one judging an approval request: what such a
request asks, what an agent never decides and hands back, and how to retrieve the nearest past
decisions.
skills/ holds one relative symlink per skill into the repository-root skills/, which
stays their only source; the pack resolves each link into the skill's own files, since a published
package carries no link of this kind (package.json's prepack, scripts/pack-skills.sh). With
Dispatch configured, the dispatch-first hook also puts dispatch-first into the model's context
on every SessionStart (startup, resume, clear, compact, fork) and SubagentStart, as the
hooks/hooks.json bullet above describes; it sends a spec, or an ask, comment or message a person
reads, to dispatch-writing-specs, which the session loads by name.
envoy, dispatch, dispatch-first, dispatch-writing-specs, asd-ste100, outside-message, plain-words and agent-secrets are the eight a standalone Claude Code session uses, approval-review the ninth, which only a session judging an approval request reads, and the
reviewer's pair, thermonuclear-code-quality and thermonuclear-deep-review, ships here too, so
one copy of each rubric reaches both harnesses. The other root skills
stay out of this plugin: they belong to Legion's roles (the architect, controller, oracle and retro
skills, and the phase workers' legion-worker and simplify-settled-diff; the partition is in scripts/pi-plugin-prepack.sh at the repository root). A phase worker on Claude Code gets them from the
generated legion/ plugin (below). Link another root skill here only when a standalone Claude
Code session needs it.
Legion phase workers
A Legion daemon can run a phase worker (planner, implementer, tester, reviewer or merger) on
Claude Code when legion.yaml sets worker_backends: {<role>: claude} (tmux runtime only; see
docs/deployment.md, "Phase workers on Claude Code"). The daemon launches
legion claude-bridge -- claude -p … with two plugin directories, this package and its generated
legion/, and a per-claim CLAUDE_CONFIG_DIR. In that pane the MCP server:
- registers the session with the daemon once its transcript exists, claims the issue's Envoy role
and reports ready (
src/legion-claim.ts, over the claim boot@sjawhar/pi-legionshares); - serves the
legiontool:read_record,handoff_completeandrequest_backward_move, the phase ops@sjawhar/pi-legion's tool serves, on the same schema and executor (src/legion-tool.ts); - hands each Envoy delivery to the bridge's socket (
LEGION_CLAUDE_INBOX), which sends it to Claude Code as a user turn (src/legion-inbox.ts): the bridge starts a turn with it when Claude Code is idle, and sends it as the next user message of the running turn otherwise. So the session advertisessteer(Dispatch's Send) besideaside, and the bridge handles both alike. The bridge runs Claude Code with--replay-user-messagesand answers a delivery only once Claude Code re-emits it as the user message it took, or with an error once Claude Code ended a step without taking it or exited; a relayed frame isdoneon that answer.
legion/ is generated by scripts/build.ts: it copies the skills @sjawhar/pi-legion ships
(staged by scripts/pi-plugin-prepack.sh --stage-skills @sjawhar/pi-legion) and turns that
package's task agents (packages/pi-legion/agents/) into Claude Code's agent format. The
release builds it with the bundle and packs it into the published package (below), and nobody
edits it by hand. A standalone Claude Code session doesn't load it.
The bundle
The marketplace installs this package from npm, as @sjawhar/claude-envoy, into Claude
Code's plugin cache with no node_modules: Claude Code never runs an install script, and it
installs dependencies only when a supported lockfile sits beside package.json in the tarball,
which this one does not ship (the monorepo's lockfile lives at the repository root). So the
package declares no runtime dependency at all — every one of them is a devDependency, as
@sjawhar/pi-envoy's are — and the four executables ship as built single-file Bun
bundles,
dist/envoy-channel.js, dist/session-hook.js, dist/session-title-hook.js and
dist/dispatch.js (the dispatch command, built from @legion/envoy-client's
bin/dispatch.ts), with every dependency inlined (@legion/contracts,
@legion/envoy-client, @modelcontextprotocol/sdk, nats, zod and theirs; the package version
is inlined from package.json, so the MCP server reports package.json's version, which
.omp-plugin/plugin.json repeats). dist/THIRD_PARTY_NOTICES beside them carries the license of
every third-party package they inline, written from Bun's metafile by
scripts/third-party-notices.ts at the repository root.
- The published tarball carries the bundles and
legion/; nothing commits them, and.gitignorenames both.release.yaml'sclaude_envoy_buildbuilds them after each merge whose commits touch one of$CLAUDE_ENVOY_VERSION_ARGS' paths (the paths ofscripts/build-inputs.txt; a merge that touches none releases nothing and leaves the newest release standing), packs them into the tarball with the rest of the package, and thepublishjob uploads that tarball to npm with provenance, tags the releaseclaude-envoy-v<version>and creates its GitHub release. Nothing is pushed tomain, so a release resets no merge queue. The hand-written plugin files (hooks/hooks.json,.mcp.json,bin/and.claude-plugin/) are packed from the same tree as the build beside them, so a change that makes one of them name a new or renamed bundle ships with that bundle in one release.scripts/build.tstakes its one mode and refuses a run that names none (exit 2); it never writes the package's owndist/orlegion/.--out <dir>makes a new or empty directory outside the repository a runnable copy of the plugin built from the tree (its manifests,.mcp.json,bin/,hooks/,package.jsonand skills, the skill links dereferenced, with a freshdist/andlegion/), which is how to run an unmerged tree. bun run verify-build <tar>(scripts/verify-build.sh) is that job's build step: it builds the plugin twice into a scratch directory outside the repository and says so when the two builds differ, packs the two directories into<tar>, which must be outside the repository, and runsrelease-push.sh check-builtover it, the member checks a build must pass before the job extracts it into the checkout it packs. It writes no file of the checkout, so running it on a pull request's tree changes nothing jj records; nothing a person runs locally writesdist/orlegion/. The jobs that run it are named in its header, and the jobs that extract the checked tar into their own CI checkout inrelease-push.sh'sextract-builtparagraph. Pull-request CI runs it, so a skill file that is executable, a symlink or named with a space, or a bundleBUNDLE_ENTRYPOINTSno longer names, fails there instead of failing every release on main. The private-name check of the build runs in a job of its own after the pack (verify-build.sh's header names both), since it reads the deployment's term list, which no job that runs dependency code holds.- The build is
Bun.build, targetbun,minify: false, no sourcemap, notices included. Minification is off entirely, not case by case: the partial-disable form ({whitespace: false, identifiers: false, syntax: false}) still routes through Bun 1.3.14's minifying code-generation path, which picks a non-deterministic CJS/ESM interop check on repeated builds of this exact module graph — on top of the syntax minifier's own separate bug, truncating constant-folded multi-operand string concatenation in CI builds, that made the partial form necessary before this. A plainfalsebypasses that whole path; whitespace and identifiers stay readable as a side effect, so independent changes still merge at line level. - The build runs only on the Bun version pinned in the repo-root
.bun-version, because the bundler's own output depends on the exact Bun build, not only the declared version. Two separate, compounding causes made two builds of one tree disagree: the minify setting above (a non-determinism within one Bun build's own bundler) and a second, independent bug (LEGION-568) —bun run verify-buildspawns a new "bun" process to runscripts/build.ts, and that spawn resolves "bun" from PATH rather than reusing whichever binary the caller invokedbun runwith, so a devbox whose default Bun (a version manager's active version) differs from the pin would otherwise silently bundle with that other Bun version instead — confirmed directly between a devbox and the CI runner, same source, same lockfile, same.bun-version. Either alone could produce this symptom; the first investigation (LEGION-548 round 5) found the first and mistakenly attributed a failure actually caused by the second to the build machine itself. The build now refuses outright when the running Bun does not match the pin, rather than publish whatever that other build produced: invoke the pinned binary's own path directly — notbun run— when a version manager's default differs from it. - pi-envoy solves the same problem with
scripts/pi-plugin-prepack.sh(at the repository root, the prepack of both Oh My Pi plugins). This plugin is a third released package of the same build and publish split, beside@sjawhar/pi-envoyand@sjawhar/pi-legion, versioned and tagged from the tags as they are. A commit onmaincarried the build before, and every push tomainresets the merge queue; publishing to npm takes that commit away without putting the build on a branch of its own, which was the design before this one and was rejected.
Updates
The marketplace entry declares no version of its own, and the committed
.claude-plugin/plugin.json declares none either; the entry's npm source declares
version: ">=1.0.0", a range that keeps an install off the 0.0.0 placeholder a person published
so that trusted publishing could attach to the package, and otherwise takes latest, which the
resolver prefers while it satisfies the range.
Claude Code names an installed plugin by the version of the .claude-plugin/plugin.json it
installed and never by the version the registry served, so release.yaml's claude_envoy_build
writes the release's version into the .claude-plugin/plugin.json it packs, beside the one it
writes into package.json, and its
tarball check refuses a tarball without it: a package published with none is cached under the
name unknown and no later release reads as an update (measured on Claude Code 2.1.311). The
version a session reports is therefore the version that was published, which is what makes this
plainer than the derivation before it, where it was the first 12 characters of the commit the
plugin was installed from.
claude plugin marketplace update legion-plugins then
claude plugin update claude-envoy@legion-plugins installs the newest release, which the
Claude Code session loads. Claude Code's background auto-update does the same once it is on for
legion-plugins, which it is not by default: Enable auto-update on the marketplace under
/plugin Marketplaces, or set "autoUpdate": true beside source on the marketplace's
extraKnownMarketplaces entry, in whichever settings file declares it. A version committed in
either file would hold every install at that string until someone changed it, so a test holds
both committed files to none; the range is a field of the entry's source, not a version of the
entry.
A checkout's package.json version names no release either, for the same reason: the build job
writes the release's version into the manifest it packs.
On npm 12 or later, claude plugin update claude-envoy@legion-plugins fails with
code EALLOWREMOTE, unless the one command allows a fetch from a URL:
npm_config_allow_remote=all claude plugin update claude-envoy@legion-pluginsClaude Code fetches the package by its tarball URL on the registry
(https://registry.npmjs.org/@sjawhar/claude-envoy/-/claude-envoy-<version>.tgz) and not by its
name. npm 12 sets allow-remote to none by default, and with that setting it refuses to fetch a
package from a URL: Could not download @sjawhar/[email protected] from the npm registry: code
EALLOWREMOTE (Claude Code 2.1.325, npm 12.0.1). The same package fetched by its name passes, and
the package declares no dependencies, so the cause is in how Claude Code asks npm and no change to
this package or to the marketplace entry removes it. The variable applies to that one command, so
every other install on the machine keeps npm's default.
In a shell that a Claude Code session started, CLAUDE_CONFIG_DIR names that session's
configuration directory, so put env -u CLAUDE_CONFIG_DIR in front of the command to update the
default ~/.claude. Each scope that holds the plugin (user, project) updates on its own, so run
the update in each one.
Each release publishes its own changelog entries into its GitHub release body, rendered from the
fragments its own commits added, and each fragment stays under .changes/unreleased/.
CHANGELOG.md is the history before that and stops where the fragments begin.
How a message reaches the model
Nothing has to be enabled on the machine: the plugin carries a Claude Code mod (hooks/mod.ts,
loaded by the modules key of hooks/hooks.json), and the mod and this server meet on a Unix
socket of the session's own (hooks/mod-protocol.ts, src/mod-link.ts). Claude Code 2.1.310 or
newer runs the mod; below that it never connects, and a terminal session advertises no delivery
mode, so Dispatch refuses a message to it rather than reporting it delivered. The same holds for
a session started with --bare or --safe-mode, and one whose settings turn hooks or mods off
(disableAllHooks, or allowManagedModsOnly or allowManagedHooksOnly in managed settings).
That socket is claude-envoy/ce-<hash of the session id>.sock under XDG_RUNTIME_DIR, and
under Claude Code's own configuration directory — CLAUDE_CONFIG_DIR, else $HOME/.claude —
where that variable is unset. Both are directories only their own user can create anything in,
which is where ssh's ControlPath and gpg-agent put theirs; TMPDIR and /tmp are no bases,
since whoever else can write a directory can bind the path first and then read the conversation
and submit prompts as the person. The server also refuses a directory that is anyone else's or
open to anyone else, rather than binding in it, and a session whose environment names no base of
its own gets no link at all, with the reason on stderr. The name is the session id's hash
because the whole path has 100 bytes to fit in (Claude Code's bound on HttpInit.socketPath):
a macOS /Users/<name>/.claude comes to 62 bytes and a Legion pane's CLAUDE_CONFIG_DIR to 78,
where the id spelled out passed 100 on a macOS temp directory. A resolved path past that bound
is refused with the reason too, never moved to a base other users share. One link serves one
mod: the first mod instance to name itself holds it, and a second Claude Code process booted on
the same session id is refused and stops, so one conversation is in the live view and a person's
Send has one place to go.
A person's own message from Dispatch's Agents page becomes the session's own user turn
(src/user-turn-router.ts): the frame is only a candidate, and what makes a turn is Dispatch
recording that this session accepted that attempt, whose stored body is what is injected. During
a turn it is a row of the conversation the model reads at the turn's next request; while the
session is idle it is the prompt of a new turn, in the person's own words. A / message runs as
the command it is and its output is the reply on Dispatch; /model and /effort set what they
name; a BTW is answered off to the side and adds nothing to the conversation. Every other frame
arrives as the rendered card that names its sender.
The plugin reads one envoy.json: $CLAUDE_CONFIG_DIR/envoy.json when CLAUDE_CONFIG_DIR is set,
else the file ENVOY_CONFIG_FILE names, else ${XDG_CONFIG_HOME:-~/.config}/legion/envoy.json,
with the dispatch section of a <cwd>/.envoy/envoy.json merged over it: its server only with the
token beside it, and its token only beside its own server. An envoy section in that checkout's
file is not read, which the channel server's notice says, and a checkout's file that is not valid
refuses Dispatch alone, only while DISPATCH_URL is unset. The chosen file's dispatch section
(enabled, serverUrl, token) and envoy section (enabled, url, natsUrls, token,
natsSeed, natsAuth, inbound) are resolved each on its own; enabled: false turns one off, a
missing file contributes nothing (each section is then on only when its variables name it), and a
token or natsSeed starting with ! is a command whose trimmed output is the value.
DISPATCH_URL, DISPATCH_TOKEN_FILE, DISPATCH_TOKEN, ENVOY_URL, ENVOY_NATS_URL,
ENVOY_TOKEN_FILE, ENVOY_TOKEN, NATS_NKEY_SEED_FILE, NATS_NKEY_SEED, NATS_AUTH and
ENVOY_INBOUND each override their own field; a file's token or seed goes with a variable's server
only when it is the file's own. With
NATS_AUTH=broker and no seed the NATS connection presents the session's own broker token, which
a hub's NATS auth service admits to that session's subjects alone, and a /clear moves it to the
new id's token before the new id's relay subject is subscribed. With ENVOY_INBOUND=listener (or
"inbound": "listener"), a Claude Code or Codex session takes its inbound messages through the
listener's relay socket, <ENVOY_URL>/v1/sessions/<id>/relay, over HTTPS alone, with the session's
own broker token, rather than over NATS, and a /clear or /new opens the socket again for the
new id; it is refused beside ENVOY_NATS_URL or envoy.natsUrls, naming both, with a bearer for
the listener, with no broker route, and for a process that names no session. With the setting, a
listener at a plain http address of another machine turns Envoy off as a whole, its tools
included, a NATS server named or not (the token would cross the network unencrypted; a conflict
with a NATS server is named first; this machine's own listener may be plain http, and a session
not set to listener keeps plain http). The
socket carries no agent stream, so neither live view
takes its control subject and the Agents page shows nothing of the session's turns, which the
start notice says. The open-asks hook
hands the file on to the session's Bash as ENVOY_CONFIG_FILE beside DISPATCH_HOST=claude, and
the dispatch command reads the file ENVOY_CONFIG_FILE names whenever DISPATCH_HOST is set
(but for dispatch login, and for dispatch proxy without DISPATCH_TOKEN_BROKER=1); a
Bash with neither, as a subagent's can be, has CLAUDE_CODE_CHILD_SESSION=1 and takes this plugin's
rule. With Envoy off the channel server lists no tool, refuses every call with
Envoy is off for this session: <why> (the section's notice or error), subscribes nothing, and
exits 0 when stdin ends. With Envoy on and no NATS server (envoy.natsUrls or ENVOY_NATS_URL),
or with its NATS seed refused, it serves the Envoy tools, which call the listener, and takes no
inbound messages: it registers nothing with the listener, its inbox stays empty, and
envoy_subscribe is refused with inbound messages are off for this session: <why>. Why a section
is off, and that inbound messages are off, is written once to its stderr
(envoy-channel: no envoy.json at <path>: Dispatch and Envoy are off, the section's error, what a
checkout's file holds that is not read, or Envoy's inbound messages are off: <why>; the Envoy tools
still work, <why> being Envoy has no NATS server (envoy.natsUrls, ENVOY_NATS_URL) or the seed's
refusal). The variables are inherited from the environment that
launched claude
— .mcp.json passes through only CLAUDE_PROJECT_DIR, because an unset ${VAR} in .mcp.json
is substituted as the literal text, which used to register a session as the literal id
${ENVOY_SESSION_ID}. Claude Code provides CLAUDE_CODE_SESSION_ID and CLAUDE_PLUGIN_DATA; set
ENVOY_SESSION_ID only to use a controlled identity for QA (the smoke does).
The session registers under a title, which Dispatch's Agents page shows in place of its session id:
ENVOY_SESSION_TITLE when it is set and holds a character that shows
(ENVOY_SESSION_TITLE='review the listener' claude), on one line. Otherwise it is the name the
person running the session gave it — claude -n 'review the listener', --name, or /rename —
alone, with no short id after it, since a name somebody chose already tells its session apart.
Otherwise the title is a name and the first eight characters of the session id
(work:review 3084299d, legion 3084299d), so two sessions in one tmux window, or in one project
outside tmux, keep apart, and the id part follows the new id after /clear.
Claude Code hands the chosen name to a hook and to nothing else, as session_title on the
SessionStart and UserPromptSubmit payloads, so the plugin's hooks record it under
${CLAUDE_PLUGIN_DATA}/titles/, by session id, and the channel server reads that file every time
it registers. The UserPromptSubmit hook is a bundle of its own, dist/session-title-hook.js,
because Claude Code holds the prompt until it returns: it parses its payload and writes one file,
and costs about what starting bun at all costs. A rename therefore reaches the Agents page on
the session's next prompt and the registration heartbeat that follows it, within about two
minutes; nothing watches the file. Taking the name away removes the record, so the session
returns to the name-and-short-id title instead of wearing a name nobody chose any more, and a
name that is blank or invisible once cleaned falls back the same way; a name written on several
lines is put on one, not refused. Records untouched for thirty days are pruned as the channel
server starts — the titles, and the role files beside them — so a session resumed weeks later
still finds its name and its role, and neither directory grows for ever; a sweep that fails says
so on stderr and the session starts regardless.
Inside tmux that fallback name is session:window for a window whose automatic-rename is off
(one named with rename-window or new-window -n, one a program in it renamed through
allow-rename, or any window where the tmux configuration turns it off), else the tmux session's
name; in grouped sessions, the group's name, which tmux keeps even after the sessions are renamed
or end. A window index is never used, since tmux moves it under renumber-windows. The server
asks the tmux server TMUX names about the pane TMUX_PANE names, and uses the answer only when
that server's pid is the one in TMUX (a server started again on the socket gives out the same
pane ids) and the pane's process is one of the session's own ancestors (tmux hands a popup or
run-shell job a TMUX_PANE left over from elsewhere). Otherwise, and for a session named only
by digits (plain tmux names its first one 0) in a window nobody named, the name is the project
directory's. The server works that name out once as it starts, with at most one
tmux display-message call bounded at one second (on a host without /proc, reading the pane's
process chain adds one ps call per step, each bounded the same way), so a later tmux rename
shows from the next start. The chosen name is read afresh on every registration instead, which is
why a rename needs no restart. The server also writes the title to the session's Dispatch state
directory, where the dispatch command reads it to stamp the session's Dispatch writes, so a
comment or message from the session carries the same name. With inbound messages or Envoy off it
writes it once, for the id the session starts with. It writes nothing when the session starts with
Dispatch off, or under the QA override ENVOY_SESSION_ID.
claude -p can run a session with this plugin, but it disables features that need terminal
input, including multiple-choice questions and plan approval.
Production Legion workers must have
MCP consent preconfigured and must not depend on local dialogs.
Intentionally omitted
- A delivery to a session with no mod: a terminal session whose mod has not connected advertises no delivery mode at all, rather than taking a message nothing can show. Claude Code below 2.1.310 never runs the mod, so such a session takes nothing.
- Permission relay: remote permission decisions have no sender-authenticated reply path or reply-ack design here; carrying them would let unauthenticated Envoy payloads approve tool use. Dispatch asks stay on Dispatch.
Manual smoke
smoke-clear-rebind.sh and smoke-session-title.sh are real manual smokes, never CI steps. Each
needs a live Envoy listener, NATS, Claude authentication and a configured model.
To exercise an unmerged checkout the way the marketplace would install it, register a development
marketplace with a command source in copy mode whose command builds a copy of the plugin with
bun packages/claude-envoy/scripts/build.ts --out <dir> (a new or empty directory outside the
repository, without node_modules) and prints it, install claude-envoy@<dev-marketplace>, and
run the smoke against that entry. Never claude plugin marketplace add cybermonklabs/legion#<branch>: the
marketplace name comes from the repository's marketplace.json and would replace the real
legion-plugins registration.
smoke-clear-rebind.sh checks the /clear handoff against the live listener. It starts Claude
Code with user settings left out (--setting-sources project,local) and the build under test from
--plugin-dir (CLAUDE_PLUGIN_DIR, default: a copy of the plugin it builds from this tree with
scripts/build.ts --out in its temp directory), sends /clear, and passes when the registry entry
has moved to the new session id, lists the new direct subject, and still lacks the old one two
heartbeats later. It also fails when the entry moves later than the handoff poll allows; with
ENVOY_HEARTBEAT_MS=60000 that checks the poll rather than a heartbeat that happened to fall soon
after /clear. It needs tmux, curl, jq, bun (for the default build), an authenticated
claude, and the listener and NATS; it sends no prompt to the model and removes both ids' registry
entries when it exits. It runs its session on its own tmux server, on a socket in its temp
directory, and prints the tmux -S <socket> attach -t <session> line that
watches it. Pointed at an older build (an installed plugin cache directory), it reproduces the
stale subject that build leaves behind:
ENVOY_NATS_URL=nats://127.0.0.1:4222 packages/claude-envoy/scripts/smoke-clear-rebind.shsmoke-session-title.sh checks that the name a person gave a session is what the plugin
registers. It starts a nats-server and an Envoy listener built from this tree, builds a copy of
the plugin from this tree in its temp directory (scripts/build.ts --out), runs that copy's
dist/session-hook.js and dist/session-title-hook.js on the payloads Claude Code's hooks
reference documents and its dist/envoy-channel.js as the session, and reads each title back
through the listener's GET /v1/sessions: the chosen name registers alone, a rename replaces it,
taking the name away brings the folder-and-short-id title back, and the dispatch command's stamp
in the session's Dispatch state directory carries the same name. Its negative control runs the
first case again against the committed dist/envoy-channel.js of BASE_REV (default
0306bcbe16df-, the last revision without the fallback), which registers the folder name instead.
It needs bun, curl, jq, go and nats-server
(go install github.com/nats-io/nats-server/[email protected], the version packages/envoy/go.mod
pins: the listener refuses a nats-server below v2.11.12, v2.12.4 or v2.14.0), and no Claude
authentication: the two hook payloads are written by the script, and that the field arrives
at all rests on Claude Code's documentation. Claude Code is not installed in an issue pod's
image, though it runs there from bunx --package @anthropic-ai/claude-code@<version> claude, as
scripts/e2e/envoy-session-delivery.sh runs it. Like the other two, it is never a CI step:
bash packages/claude-envoy/scripts/smoke-session-title.shLocal checks
bun run --cwd packages/claude-envoy lint
bun run --cwd packages/claude-envoy typecheck
bun run --cwd packages/claude-envoy test
(cd packages/claude-envoy && bun run test tests/mod.test.ts) # one file
bun packages/claude-envoy/scripts/build.ts --out "$(mktemp -d)"bun run --cwd packages/claude-envoy verify-build "$(mktemp -d)/built.tar" builds the plugin
twice and compares the two builds, which is what the release's build job runs; nothing in a
checkout holds a built copy to compare against.
bun packages/claude-envoy/scripts/build.ts --codex-out <dir> builds the Codex plugin ("Codex
CLI" above).
The real-binary tests skip unless LEGION_TEST_CLAUDE names a Claude Code binary.
tests/answers-claude.test.ts runs the real Claude Code, the release .claude-code-pin at the
repository root pins, against a stand-in Messages endpoint and Dispatch: the list reaches the model
at startup, on --resume, after /compact and in a subagent. It skips without LEGION_TEST_CLAUDE,
except on GitHub Actions, where .github/actions/install-claude-code installs the pin.
tests/envoy-channel-stall.test.ts runs a real NATS server and Envoy listener, so it runs only
with LEGION_E2E_ENVOY_STACK=1, and then builds both with go on PATH, or starts them from the
directory LEGION_ENVOY_STACK_BIN names (envoy-client's README says how). Run it with
(cd packages/claude-envoy && LEGION_E2E_ENVOY_STACK=1 bun run test:stall), with that variable
set as the job sets it: that script is the
command the envoy-session-stall job's step queues in that job's harness pool, with the one guard
of that command, its --timeout, and the row-deadline preload, where a bare bun test of the file
gets Bun's 5 s.
To run tests/answers-claude.test.ts locally:
mkdir -p "$TMPDIR/claude-code" && bun add --cwd "$TMPDIR/claude-code" --exact --no-save "@anthropic-ai/claude-code@$(<.claude-code-pin)"
cd packages/claude-envoy && LEGION_TEST_CLAUDE="$TMPDIR/claude-code/node_modules/.bin/claude" bun test tests/answers-claude.test.ts