Tandem Claude + Codex tandem
Claude + Codex tandem
Implementation and independent review split between two models: Claude coordinates and is the only author of code; Codex, from another maker, runs read-only and researches, challenges, reviews and verifies.
My work
Together with AI agents, I wrote the contract the two models work under and built the MCP server that runs the checker. This site was made this way.
How it is built
This layout is real: it is how I work today. The contract is a file in a repository: the coordinator loads it at the start of every session, and the checker is given what it needs inside each question.
While the checker does not answer
the route after the failure unavailable
- An error of the checker marks the job failed; the watcher ends on a failure as on a completion, and on a timeout if neither comes.
- Work can go on, but by the contract nothing is called done without a verification against the written criteria.
- This is the contract’s rule, not a lock in the code: it holds because the coordinator keeps it.
Components
Press a component to read what it does.
Owner task, decisions
Sets the task and keeps the decisions that are his: money, scope, privacy, anything that cannot be undone.
Claude the only author
The coordinator. States the problem, forms the solution, writes every change, runs the checks and records the outcome.
Subagents read and report
Helpers for narrow reading and searching, in the project and on the web. A guard limits their tools and the files they can read.
Repository code and tests
The code, the tests and the contract. One model changes them; the checker runs in a sandbox that can only read.
Tandem server MCP, local
A local MCP server between the two: turns a question into a run of the checker, queues long jobs, keeps one session per topic.
Second brain what was proved
Where a durable decision goes with its evidence, so that the next session starts from it.
Codex read-only
The independent checker, a model from another maker. Its file operations run in a read-only sandbox, with approval prompts off.
-
The task
I set the task and keep what is mine to decide: money, legal matters, privacy, the scope of the product, publication, and anything that cannot be undone.
My part Together with AI agents, I wrote the contract the two models work under: the roles, the order of the steps, the limits of an argument, and what is brought to me.
In detail
Those matters are not settled between the models: they are brought to me, and nothing moves until I answer. A trivial mechanical edit, a rename or a typo, goes without the checker; every decision of substance goes through the cycle.
Where it breaks The contract does not let a phase be repeated unless the diff, the claim or the evidence has changed.
-
An independent position
The first question to the checker is the problem alone: it gives its own position before it has seen another. The server runs it in a sandbox that can only read.
My part Together with the agents I built the MCP server that runs the checker: a read-only sandbox, a queue for long jobs, sessions that keep the thread of a discussion.
In detail
By the contract’s rule against anchoring, the checker answers before it is shown the coordinator’s solution: shown it first, it would just confirm it. The server starts the checker in a read-only sandbox with its approval policy set to never: it cannot ask to step outside the sandbox, so no write can be granted to it during a check. Each new check names its mode: research, challenge, review, verify, visual critique, debate. 1
Where it breaks The checker reads the repository and Git itself; what it cannot get there has to be in the question.
-
The challenge
Then the coordinator shows its solution, and the checker’s job is to break it: where it misleads, overclaims or fails.
In detail
A dispute continues in the same session, under a stable key that names the thread, with what was already said. It stops after two rounds without new evidence, and a claim that can be tested is settled by an experiment, not by a vote.
Where it breaks The agreement of two models is not evidence: by the contract, a verified fact outweighs the certainty of either.
-
One author
Claude writes every change. The checker is told never to edit, and its sandbox can only read.
In detail
Two agents never edit the same file, and for every line it is clear who answers for it. The one exception the server allows is a single generated picture saved into one folder of references; it changes no code. 4
Where it breaks A question has a size: the server passes it as a command-line argument, and on Windows a whole command line is limited to 32,767 characters, the terminating null included. A large review is sent in parts.
-
Review and verification
Before anyone says "done", the checker reviews the diff, then verifies the result against acceptance criteria written down in advance.
In detail
By the contract, a verification is asked against criteria written down in advance. Work longer than a moment is a job in a queue: the server tries to write the job’s file at every change of its state, a failure included, and a background watcher the coordinator starts checks that file every ten seconds by default and ends on a completion, a failure or a timeout; then the coordinator reads the result.
Where it breaks A job that completed is not a result that was confirmed: the server counts a run as done by its exit and its text, and the text can say "not verified".
-
Subagents
Narrow reading and searching go to subagents, which can only read and report. What they bring back is a lead, not a fact.
In detail
A subagent runs in a context window of its own, with its own system prompt, its own access to tools and its own permissions. A PreToolUse hook is the guard: it checks a subagent’s tool calls against an allowlist, keeps its reading to approved folders and refuses listed secret paths; the subagent gets no shell and no writing. 2
3 Where it breaks Before a lead is used, the files it names are opened and its key check is run again.
-
Memory
The durable decision and its evidence go to the second brain. Claude writes them: the checker cannot.
In detail
A verified fact outweighs the certainty of either model. What was decided, why, and what proves it is written down, so that the next session, of either model, starts from it.
Where it breaks The checker runs at the highest reasoning effort; the contract allows lowering it when usage limits are reached, and the check itself stays.
Code: a template
A tandem to adapt
A template, not the server this site was made with: the contract both models read, a read-only run of Codex, and an MCP server with one tool, to be adapted to your own project. The core has no dependencies; the server needs the official MCP SDK for TypeScript, version 1, and zod.
CLAUDE.md The contract: who writes, who checks, and when. 30 lines
Lines 1–11 Claude is the only author of code; Codex never writes code and is reached through ask_codex, the one tool of the tandem MCP server. The file sits at the repository root, where both agents read it before they start.
# Tandem: the contract
A template to adapt: two models on one project, one writes, the other checks. Keep this file at the
root of the repository; both agents read it before they start.
## Roles
- **Claude** coordinates and is the only author of code.
- **Codex** is read-only: it researches, challenges, reviews and verifies. It never writes code.
It is reached through the `tandem` MCP server, whose one tool is `ask_codex`.
Lines 12–23 Codex answers in step 2, before it sees Claude’s position: a reviewer shown an answer first tends to confirm it. Without new evidence a dispute runs at most two more rounds; a testable claim goes to an experiment.
## The cycle, at every decision that matters
1. Claude states the problem.
2. Codex gives its own position **before** it sees Claude's. Shown an answer first, a reviewer
tends to confirm it.
3. Claude forms a solution and has Codex challenge it.
4. Claude writes the code.
5. Codex reviews every change that is not trivial.
6. Before anything is called done, Codex verifies it against criteria written down in advance.
7. Where they disagree: at most two more rounds without new evidence. A claim that can be tested
is settled by an experiment, not by a vote.
Lines 24–30 Trivial edits skip Codex, and anything irreversible, legal, about money or personal data goes to the owner. Codex cannot see Claude’s session, so each request carries the diff and results and points it to this file.
## Limits
- Trivial edits (a rename, formatting, an obvious typo) go without Codex.
- Codex reads the repository but not Claude's session: put the diff, the texts and the results in
the request. It loads AGENTS.md by itself, not this file, so `ask_codex` tells it to read this one.
- Evidence beats confidence: a verified fact outweighs how sure either model sounds.
- Anything irreversible, legal, about money or about personal data goes to the owner.
codex.mjs One read-only run of Codex, apart from any protocol. 82 lines
Lines 1–9 codex exec runs one task unattended and prints only its final message to stdout; --sandbox read-only keeps it from changing anything. The module imports only spawn from node:child_process and needs no dependencies.
// Asking Codex, apart from any protocol: one read-only run of the Codex command line, and its answer.
//
// A template to adapt. `codex exec` runs one task without a person and prints only its final message
// to stdout; `--sandbox read-only` keeps it from changing anything; with `-` it reads the prompt
// from stdin, so a long context never meets the command line's length limit. Node 18 or later,
// no dependencies.
import { spawn } from 'node:child_process';
Lines 10–17 Each of the four MODES is one order, stated before the task so Codex answers as a reviewer: RESEARCH without seeing another position, REVIEW with line and severity, VERIFY with PASS or FAIL and evidence per criterion.
/** What Codex is asked to do: the mode is said first, so it answers as a reviewer, not an author. */
export const MODES = {
RESEARCH: 'Give your own position on the problem, with sources. You have not seen anyone else’s.',
CHALLENGE: 'Try to break the proposed solution: what fails, under which input, and why.',
REVIEW: 'Review the change below. Name each problem with the line it is on, and its severity.',
VERIFY: 'Check the result against each criterion. Answer PASS or FAIL, with the evidence for each.',
};
Lines 18–33 prompt() throws on an unknown mode and first sends Codex to CLAUDE.md, since it auto-loads AGENTS.md, not the contract. filter(Boolean) drops an empty context or criteria, and join puts blank lines between sections.
/** The prompt Codex reads: the contract, its role, the mode, the task, and what it is asked about. */
export function prompt({ mode, task, context = '', criteria = '' }) {
if (!MODES[mode]) throw new Error(`unknown mode ${mode}`);
return [
// Codex loads AGENTS.md by itself, not CLAUDE.md: so the contract is named here.
'Read CLAUDE.md at the root of this repository first: it is the contract you work under.',
'You are a read-only reviewer. Read any file you need; modify none. Answer in plain text.',
`Mode ${mode}: ${MODES[mode]}`,
`Task:\n${task}`,
context && `Context (the change, the texts and the results you are asked about):\n${context}`,
criteria && `Acceptance criteria:\n${criteria}`,
]
.filter(Boolean)
.join('\n\n');
}
Lines 34–45 command() ends the arguments with "-", so a long prompt goes through stdin, clear of the command-line limit (the server above passes its question as an argument, and sends a large review in parts). On Windows stop() runs taskkill /T /F to end the tree, because the codex.cmd shim starts Codex under a shell.
/** The command line of one read-only run. (On Windows the npm shim is `codex.cmd`.) */
export function command() {
const bin = process.platform === 'win32' ? 'codex.cmd' : 'codex';
return { bin, args: ['exec', '--sandbox', 'read-only', '-'] };
}
/** Stop a run and everything it started: on Windows the shim runs Codex as a child of a shell. */
function stop(child) {
if (process.platform === 'win32') spawn('taskkill', ['/pid', String(child.pid), '/T', '/F']);
else child.kill();
}
Lines 46–65 ask() runs Codex in cwd, process.cwd() by default, and settles once through finish(), whose done flag drops later outcomes. After ms, 30 minutes by default, the timer ends the run with stop() and rejects.
/** Run Codex once in `cwd`, its workspace, and resolve with its final message; reject on a failed
* run or after `ms`. */
export function ask(request, { cwd = process.cwd(), ms = 30 * 60_000 } = {}) {
const { bin, args } = command();
return new Promise((resolve, reject) => {
const child = spawn(bin, args, { cwd, shell: process.platform === 'win32' });
let out = '';
let err = '';
let done = false;
const finish = (error, answer) => {
if (done) return;
done = true;
clearTimeout(timer);
if (error) reject(error);
else resolve(answer);
};
const timer = setTimeout(() => {
stop(child);
finish(new Error(`codex did not answer within ${ms / 60_000} minutes`));
}, ms);
Lines 66–72 Both streams use setEncoding('utf8'), so a character split between two chunks stays whole. The answer arrives on stdout; stderr carries progress, and ask() keeps it only to explain a failure.
// Decoded as a stream: a character split between two chunks stays one character.
child.stdout.setEncoding('utf8').on('data', (text) => {
out += text;
});
child.stderr.setEncoding('utf8').on('data', (text) => {
err += text; // progress goes here; it is kept only to explain a failure
});
Lines 73–82 An error from spawn, or from writing the prompt after Codex has exited, becomes a failed run, not a crash. Exit code 0 resolves with the trimmed stdout; any other code rejects with the last five stderr lines.
child.on('error', (error) => finish(error));
// If Codex exits before reading the whole prompt, writing it fails: that is a failed run, not a crash.
child.stdin.on('error', (error) => finish(error));
child.on('close', (code) => {
if (code === 0) finish(null, out.trim());
else finish(new Error(`codex exited with ${code}: ${err.trim().split('\n').slice(-5).join('\n')}`));
});
child.stdin.end(prompt(request));
});
}
server.mjs The MCP server and its one tool, ask_codex. 38 lines
Lines 1–13 The tandem server imports MODES and ask from codex.mjs, so the run stays in one protocol-free file. Because stdout carries the protocol over stdio, the server’s own notes go to stderr.
// The tandem's MCP server: one tool, ask_codex, for the coordinating agent. A template to adapt.
//
// The official TypeScript SDK, version 1: `npm install @modelcontextprotocol/sdk zod`. The tool's
// input schema is a plain object of zod fields; the answer comes back as text content. The server
// speaks over stdio, so it writes nothing to stdout itself: its notes go to stderr.
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { z } from 'zod';
import { MODES, ask } from './codex.mjs';
const server = new McpServer({ name: 'tandem', version: '1.0.0' });
Lines 14–27 ask_codex takes mode as z.enum(Object.keys(MODES)), so a mode added in codex.mjs reaches the schema by itself. The description warns the caller that Codex cannot see the session and needs the change in context.
server.registerTool(
'ask_codex',
{
title: 'Ask Codex',
description:
'Ask the read-only reviewer for an independent position, a challenge, a review or a verification. ' +
'Codex reads the repository, read-only, but not this session: put the change and the results it is asked about in the context.',
inputSchema: {
mode: z.enum(Object.keys(MODES)),
task: z.string().min(1).describe('What to answer, in a sentence or two.'),
context: z.string().default('').describe('Everything Codex needs to see.'),
criteria: z.string().default('').describe('For VERIFY: the criteria, written down in advance.'),
},
},
Lines 28–38 The handler logs the mode with console.error and returns Codex’s answer as text, or isError: true with the message when the run fails, so the agent sees why. server.connect() then starts the stdio transport.
async (request) => {
console.error(`ask_codex ${request.mode}`);
try {
return { content: [{ type: 'text', text: await ask(request) }] };
} catch (error) {
return { isError: true, content: [{ type: 'text', text: String(error.message ?? error) }] };
}
},
);
await server.connect(new StdioServerTransport());
.mcp.json The server registered for the coordinating agent. 8 lines
Lines 1–8 Under mcpServers the key tandem names the server, and command with args starts it as node server.mjs, a local process the client talks to over stdio. Change the path in args if server.mjs lives elsewhere.
{
"mcpServers": {
"tandem": {
"command": "node",
"args": ["server.mjs"]
}
}
}
Next story
A team of agents
One coordinating model, read-only helpers on models chosen for the task, skills loaded when they are needed, and checks run in parallel, blind to each other.