# Relay: Making Coding Agents Work as a Team

Engineering case study of a personal project, by Muhammad Usman Mateen.
Canonical article: https://usmanmateen.com/build-log/relay
Published 2026-11-25.

> The full text of the article. The figures on the page are not reproduced here.

One coding agent checking its own work is marking its own homework. Relay is the orchestration layer I built to stop that: it runs the official Claude Code and Codex command-line tools, and local models on my own GPU, as a team. One plans, one builds, my tests run, and a different model reviews, round after round, until the reviewer approves. It uses the subscriptions I already pay for, keeps every run on its own git branch, records every step as an event, and can be driven from a laptop anywhere. This is what it does, how it's built, what it can't do yet and why, and what our last audit found.

Relay is a private, unreleased project with a working name. It has only ever run on my own machines, for me. Nothing is published and nobody else uses it.

## One agent marking its own homework

Coding agents are good enough now that the interesting failures are no longer syntax. They are judgement: an agent that declares a task done when it isn't, that edits a failing test until it passes, or that reviews its own diff and finds it excellent. Asking the same model to check its own work tends to repeat the blind spots that produced it.

The fix people reach for by hand is a second opinion. Paste the diff into a different model, ask what's wrong, paste the answer back. It works, and it's tedious enough that nobody does it consistently. Relay automates that habit. A *planner* reads the repository and writes a brief, a *builder* makes the change, the project's own tests run, and a *reviewer* from a different model family reads the diff and the test output and ends with a verdict. If it asks for changes, its review becomes the builder's next prompt.

Two constraints shaped everything after that. The first was money: I already pay for Claude and ChatGPT plans, and I didn't want a tool that also bills me per token through an API key. The second was trust: agents run unattended for minutes at a time, so whatever they do has to be contained, visible, and easy to throw away.

## Six rules before any code

Relay's repository opens with a short list of rules that every change has to respect. They read like restrictions, but most of the design follows from them.

The first rule matters most. Relay never touches a provider's login. It starts the unmodified `claude` and `codex` binaries as child processes, the same way you would in a terminal, and reads what they print. Anthropic's terms allow a person to use the unmodified Claude Code binary with their own subscription; they don't allow a third party to route or resell that access. So Relay is a tool for one person on their own machine, and anything that would host it for other people has to use their own API keys or local models instead. That one rule decides what a team version of Relay can and can't be.

The second rule is about safety rather than terms. A prompt can contain anything, including text written by whoever wrote the repository. If it went on a command line, quoting bugs on Windows could turn it into a command. So prompts always go in on standard input, and anything that does reach a command line, like a model name, is checked against a strict pattern first.

## Anatomy of a run

A run starts from a task in plain English and a repository. Relay creates a *git worktree*, a second checkout of the same repository in its own folder, on a new branch called `relay/<run-id>`. The agents only ever work there. My own checkout, including uncommitted work, is never touched until I press Merge.

The planner runs once and can't edit files. The builder is the only role that writes, and Relay commits its changes after every round, so each round is a commit you can inspect. Relay then runs the test command itself, rather than trusting the builder's word that tests pass. The reviewer is read-only too. It sees the task, the plan's checklist, the diff and the test output, and is told to block only on real problems: bugs, a missed requirement, failing tests or a security issue. Everything else goes in a list of optional suggestions, so runs don't spend extra rounds on polish.

The verdict is a single line at the end of the review, and the parser is deliberately suspicious. The last verdict line wins, and a review with no verdict line at all counts as *changes*. A reviewer that rambles never approves by accident.

A run stops in one of three ways: the reviewer approves and the tests pass, the round limit is reached (three by default), or the builder answers a review without changing anything. That last check exists because an agent that disagrees with its reviewer will otherwise burn round after round restating its position. A finished run can be merged, discarded, or continued with a reply, which becomes the builder's next instructions on the same branch.

Here is the real dashboard doing exactly that, on Relay's built-in demo. Scripted mock agents play every role, so it costs nothing to watch: the first review finds a missing section, the builder resumes its session and adds it, and round two is approved and ready to merge. The run graph, timeline, changed files, checks, rounds and usage all update live from the event log.

## One interface, four kinds of agent

Each kind of agent is one small file with the same shape: a name, a label, a `check()` that confirms the CLI is installed, and a `run()` that takes a prompt, a working folder and a few options, and streams back text, tool calls and token usage. The engine never knows which vendor it's talking to.

Claude Code runs in headless mode with streaming JSON output, so Relay can show every file it reads and every command it runs as it happens. Codex runs through `codex exec` with its workspace-write sandbox and approvals off, because nobody is there to approve. Local models run through Ollama or LM Studio. A scripted mock agent plays every role in the test suite and in the demo, so neither ever spends a real subscription.

Both CLIs report how much of the plan's five-hour and weekly windows are used, but neither documents how. Claude Code includes it in a rate-limit event in its stream, and Codex writes it to a session log on disk. Relay reads both, shows them as meters, and pauses a run at 95% of a window. Both readers fail soft: if a CLI update changes the format, the meters go blank rather than the run failing.

## Everything is an event

Every state change in a run is appended to a file of events, one JSON object per line: run started, step started, a tool call, some text, usage, a guard warning, a verdict, run finished. The dashboard keeps no state of its own. It is a pure function of that list, so replaying the file rebuilds exactly what was on screen.

That one decision paid for itself several times over.

- *Restarts.* A run's summary file holds its config, agent sessions, plan and usage, so a run can be rebuilt from disk after a crash and continued with a reply.
- *Several windows.* The VS Code extension runs its own engine. A dashboard in the browser tails that run's event file live, so both show the same run.
- *Reconnects.* Every event has a durable sequence number. A client that drops its connection asks for everything after the last number it saw, and nothing is missed or shown twice.
- *Retries.* Starting a run takes an idempotency key, so a flaky network that sends the request twice still creates one run.
- *Debugging.* When a run goes wrong, the event file is the trace. There is no separate logging system to keep in step with it.

## Spending a subscription like it's yours

Usage limits are the loudest complaint about coding agents, and a multi-agent loop makes them worse: every step is a full agent session, and an agent re-sends its whole context with every tool call. The first real run made that concrete. Relay built its own `relay clean` command in four rounds and seventeen minutes, and the Claude builder used about 5.5 million input tokens, almost all of them cached context re-sent between calls.

So the defaults changed.

- *Sessions carry over.* From round two, the builder resumes its own session instead of re-reading the repository. When the planner and reviewer are the same agent, they share one read-only session, so the reviewer already knows the plan.
- *Incremental review.* A resumed reviewer sees only the diff since its last review.
- *No MCP servers by default.* Claude Code normally loads every MCP server and claude.ai connector you have, and their tool lists ride along on every model call. With a typical set that was about 7,000 tokens per call, and a build step makes dozens of calls.
- *Proportionate prompts.* Short plans, reviews that only block on real problems, and a builder that is told Relay runs the tests, so it doesn't run them too.
- *Budgets.* A token budget per agent pauses the run when an agent's new tokens pass it. Usage is split into new input, cached input and output, because cached input costs far less.

Here is the honest part. Only three real runs have been measured, and the run that would show the Claude savings hasn't happened yet: my weekly Claude limit was already at 88% when the fixes landed. The Codex-only measurement is real but small. Treat the table as a record of what happened, not a benchmark.

## Guard rails for unattended agents

An agent running alone for ten minutes will eventually try something you wouldn't. Relay's guards target the failures people report most often.

The deny rules are passed to Claude Code as permission rules, so a recursive delete is refused before it runs rather than flagged afterwards. I checked this on a real run: the `rm -rf` was refused. Codex is held to its own workspace-write sandbox instead, and Relay flags any risky command either agent attempts.

The weakened-test check is the one I like best, because it's so simple. Agents are good at making tests pass, and sometimes they do it by editing the test. Adding new tests is fine. Changing or deleting existing lines in a test file is flagged in the transcript, and the reviewer is told to treat a weakened test as a blocking problem. These are guard rails, not a sandbox, and the README says so in as many words. Section 12 is about what that difference costs.

## A canvas for workflows

The first version was a list: planner, builder, tests, reviewer. That covered the default, but not the runs I actually wanted, such as a person approving the plan before anyone builds, or three builders working on different files at once. So runs became a versioned workflow graph of nodes and edges, and the dashboard got a canvas to draw them on.

The canvas works like any node editor. You add steps from a palette, drag them into place, and connect two steps by dragging from the circle on one's right to the circle on the next one's left. A connection can carry a condition. Selecting a step opens an inspector: role, agent, model and effort for an agent, a command for a check, a server name for an MCP step. The recording below is the real canvas.

In about a minute of real time it adds a second builder that runs in parallel and switches it to a local Qwen model on my GPU, adds an MCP server step so the agents after it get GitHub's tools, adds a Browse step between the tests and the reviewer, rewires the graph, and gives the tests a command. Pressing *Parallel builder* adds the parallel and combine steps and wires both branches by itself. From there, *Save to folder* writes the graph into the repository's `relay.config.json`, and *Start run* runs it.

The Browse step is the one I'd miss most. With the Playwright browser server installed from the dashboard's MCP marketplace, it opens the app in a real browser (serving the run's own files on a private local port when there's no dev server) and hands the console errors and what's on each page to the reviewers and the planner. A reviewer then judges the page it can see, not just the diff.

Try it yourself. The buttons add the same steps, and the graph rearranges the way the canvas does.

Under the canvas, a node is an agent, a check (a test command), a decision, a human approval, a tool command, an MCP server for the agents that follow, a Browse step, or parallel branches that meet at a combine node. An edge can carry a condition: approve, changes, pass or fail. The presets compile to graphs too, and the engine walks the edges. A human approval pauses the run until someone presses Approve or Reject, and a rejection's note becomes the next agent's feedback.

Parallel builders share one worktree, which is a real limitation. They must not edit the same files, so the planner hands each builder its own list of files, and any file two builders both commit in the same round is flagged before review.

## One recorded run, and the local models in it

The run below was recorded on 6 November 2026 and replayed with paths and prompts removed. The task was a small local-first ops console with four sections, JSON persistence and a test suite. A local Gemma model planned, three builders worked in parallel (two local models on my GPU and Codex in the cloud), the tests passed, and a local vision model reviewed and approved. Nine minutes, thirty-three files, one round.

It's a good run, and it hides the main limitation of the local path. A local model in Relay is not an agent. It gets one prompt and gives one reply. It writes files by printing them in a fenced block that Relay parses, it can call a tool by printing a line Relay executes (six calls at most), and it keeps no session between rounds. Claude Code and Codex read files, run commands and correct themselves in a loop; a local model in this adapter cannot.

Context is the other limit. One run sent a local reviewer 11,434 tokens with an 8,192-token window, and the run failed. Lockfiles are now left out of review diffs, a context error is retried with a shorter diff, and if that still doesn't fit the round continues as *changes* instead of failing. LM Studio also keeps one model loaded at a time, so parallel local steps queue behind each other.

The planned fix is to stop treating local models as a different kind of thing. Codex can run against a local model, which puts a real, sandboxed tool loop on a model running on my own GPU through an adapter Relay already has.

## Reaching it from anywhere

In early November I flew to Web Summit in Lisbon, and I wanted Relay to keep working while I was away: the agents, models and tests on my PC at home, and me on a laptop somewhere else. That's the part of Relay most worth getting right, because a remote control for a machine that runs commands is a remote shell if it's built carelessly.

The local dashboard already had strict rules: it listens on `127.0.0.1` only, rejects requests for any other hostname (which defeats DNS rebinding), and every API call needs a random token printed at startup. None of that changes. Instead, a second listener, the *gate*, sits in front of it and is the only thing published to the network, over Tailscale.

- *Device keys.* A browser pairs by generating a P-256 key pair in WebCrypto. The private key is non-extractable: page scripts can use it to sign, but can't read it out.
- *Signed requests.* Each request's signature covers the method, path, body, time, a nonce and the machine's id, so a request can't be altered, replayed later or sent to a different PC.
- *Pairing is approved on the PC.* A new device stays pending until I approve it at the machine, and starts with view-only access.
- *Scopes.* View, run, approve, merge, configure, shell, admin, GitHub and browse are granted one at a time. Anything that would run an arbitrary command needs `shell`, not `run`.
- *An allow-list, not a proxy.* The gate forwards an explicit list of routes to the local API over loopback and adds the token itself, so the token never crosses the network.
- *An interlock.* The gate refuses to start if Tailscale is publishing the local API port directly.
- *Revocation.* Revoking a device on the PC closes its open streams within a second, and every request leaves a line in an audit log.

An end-to-end smoke test passed 23 of 23 checks over the real tailnet: pairing, refusals, health, a real local-model run approved from the laptop, live events with resume, changed files and revocation. Then it got a real test: I used Relay from the airport in Portugal, with the laptop reaching the GPU in my house over Tailscale. A Cloudflare Access transport is implemented and tested against a stand-in, but isn't deployed.

## What it can't do yet, and why

Every limitation below has a reason, and most of the reasons were choices that made sense for a tool one person runs on their own PC.

The pattern is the same in most rows. Relay leans on the vendors' CLIs for the hard parts (the agent loop, the sandbox, the login), which kept the engine small and the terms clean. The price is that Relay inherits the CLIs' boundaries: it can't contain an agent more tightly than the agent's own sandbox does, and it can't read usage figures the CLIs don't publish.

## What our last audit found

On 14 November 2026 we audited the whole codebase: the engine, the adapters, the remote gate, and the GitHub and MCP layers, read in full. All three test suites passed (148 engine, 76 web, 7 extension), `npm audit` on the web app was clean, and every one of the 44 packages in the MCP marketplace was looked up on the npm registry. No live attack was run; the findings come from reading the code.

The verdict, in one line: the remote gate is well designed and the engine is tidy and well tested, but one layer down, *agents run as you, with your environment, on your real disk*. The four high-severity findings all come from that.

- *A remote permission could be widened.* One field in a workflow sent from a paired device reached an agent's tool permissions without being validated, so a device allowed to start runs could have granted an agent unrestricted shell access.
- *Agents can read the host's secrets.* The CLIs' sandboxes restrict writes, not reads. An agent, or a prompt injection hidden in a repository or web page, could print local secrets such as the dashboard token or the GitHub App key into a transcript.
- *A sandbox escape through git.* On macOS and Linux, the Codex builder's writable git directory would let it plant git configuration that Relay's own git commands then run outside the sandbox.
- *The marketplace's supply chain.* MCP entries installed the latest version of each package on every use, and some entries named packages that don't exist on npm, which anyone could register.

The medium findings follow the same theme: a repository's own config file can run commands and loosen the sandbox, a view-only device can see more than it should, a revoke can be lost to a write race, the secret scan before a push fails open on a diff it can't read in full, and the remote web app has no Content-Security-Policy. The reliability findings are the ones any long-running process meets eventually: no process-wide error handler, runs that don't resume by themselves after a restart, missing timeouts, and some files written non-atomically.

We're fixing these now, in the order the audit set out. The small, contained fixes come first: validate every workflow field, drop the writable git directory, pin and verify every marketplace package, fail the secret scan closed, and add error handling and atomic writes. Then come the structural ones: scrub the environment agents inherit, require the owner to trust a repository's config before it runs, and filter what remote devices see. None of this has been exposed: Relay has only run on my own machines, behind my own tailnet, for me. The repository stays private until every high and medium finding is closed with a test.

The audit also listed what's solid, and it's worth saying because it's the part most projects get wrong: the gate's keys, signatures, allow-list, scopes and interlock; a local server that only answers to loopback with a token; idempotent run creation with replayable events; worktree isolation with a read-only planner and reviewer; and an engine with no runtime dependencies.

## Where it's going

Before writing much code, I looked at who else does this. The answer was: a lot of people. Running Claude Code and Codex side by side in worktrees behind a dashboard is now a common feature, and the vendors' own apps run parallel sessions. Even "Codex reviews Claude" ships free as an official plugin.

What's still open is narrower: a quota-aware plan, build, test and cross-review loop with real safety guards, solid on Windows, vendor-neutral, and able to mix local and cloud models. That's the bet. Relay should win on the loop, not on running agents in parallel.

The longer direction, adopted on 14 November, is a self-hosted agent runtime: agents that run on hardware you own, use local models first and cloud models only where you allow it, and can be reached from anywhere. The same code would serve one person on one PC and a company on its own servers, with the runner staying free and open source. It's planned in stages, and each stage is meant to be a finished product if it's the last one.

Stage A comes first, and it's the audit. Evals come before features too. The next measurements will be a standard set of tasks scored on success rate, rounds, tokens and time for each preset, because "cross-family review catches more" is a claim, and it deserves numbers rather than one good run.

---

The two screen recordings show the real dashboard, recorded on a throwaway repository: the canvas recording is sped up 1.5 times with the cursor drawn in, nothing in it was saved and no run was started; the run recording is Relay's built-in demo with scripted mock agents, so no subscription was used. The interactive canvas uses the real step types and graph format. The loop, lifecycle, event and gate animations are illustrations of the real behaviour. The adapter details, rules, guards, graph shape, code and audit counts come from the source and its documentation. The recorded run is a real run from 6 November 2026, replayed from its sanitised record. The measurements are the only three real runs recorded so far, and the token-per-call figure is an illustration built from the one measured number (about 7,000 tokens of MCP tool lists per call). The market scan is from 3 November 2026.

Claude, Claude Code and Anthropic; OpenAI, Codex and ChatGPT; Gemma and Google; Qwen; Ollama; LM Studio; Tailscale; Cloudflare; GitHub; Git; Model Context Protocol; Visual Studio Code; Node.js; React; Vite and the other names and logos shown are trademarks of their respective owners. They are used only to identify the products Relay works with. Relay is an independent personal project and is not affiliated with, endorsed or sponsored by any of them.
