Open History to see the last commit
1---
2title: Delegate to coding agents
3id: harness-coding-agents
4order: 11
5description: "Let a harness hand coding work to Claude Code, Codex, Grok Build, or any ACP agent. Each one works in a sandbox and keeps its own session."
6keywords:
7 - tanstack ai
8 - harness
9 - claude code
10 - codex
11 - grok build
12 - sandbox
13 - subagents
14---
15
16Your lead agent plans the work, but you want Claude Code or Codex to do the edits, because they are good at code and you already use them. `codingAgents` gives the lead model one tool per coding agent. Each agent works in a sandbox and keeps its own session between calls.
17
18## 1. Add the plugin
19
20<!-- ::start:tabs variant="package-manager" mode="install" -->
21
22react: @tanstack/ai-harness @tanstack/ai-sandbox @tanstack/ai-sandbox-local-process @tanstack/ai-claude-code @tanstack/ai-codex
23vue: @tanstack/ai-harness @tanstack/ai-sandbox @tanstack/ai-sandbox-local-process @tanstack/ai-claude-code @tanstack/ai-codex
24solid: @tanstack/ai-harness @tanstack/ai-sandbox @tanstack/ai-sandbox-local-process @tanstack/ai-claude-code @tanstack/ai-codex
25svelte: @tanstack/ai-harness @tanstack/ai-sandbox @tanstack/ai-sandbox-local-process @tanstack/ai-claude-code @tanstack/ai-codex
26preact: @tanstack/ai-harness @tanstack/ai-sandbox @tanstack/ai-sandbox-local-process @tanstack/ai-claude-code @tanstack/ai-codex
27angular: @tanstack/ai-harness @tanstack/ai-sandbox @tanstack/ai-sandbox-local-process @tanstack/ai-claude-code @tanstack/ai-codex
28octane: @tanstack/ai-harness @tanstack/ai-sandbox @tanstack/ai-sandbox-local-process @tanstack/ai-claude-code @tanstack/ai-codex
29vanilla: @tanstack/ai-harness @tanstack/ai-sandbox @tanstack/ai-sandbox-local-process @tanstack/ai-claude-code @tanstack/ai-codex
30
31<!-- ::end:tabs -->
32
33```ts group=harness-coding-agents
34import { defineHarness } from '@tanstack/ai-harness'
35import { permissions } from '@tanstack/ai-harness/plugins'
36import { claudeCodeText } from '@tanstack/ai-claude-code'
37import { codexText } from '@tanstack/ai-codex'
38import { openaiText } from '@tanstack/ai-openai'
39import { defineSandbox, defineWorkspace, localSource } from '@tanstack/ai-sandbox'
40import { codingAgents } from '@tanstack/ai-sandbox/harness'
41import { localProcessSandbox } from '@tanstack/ai-sandbox-local-process'
42
43const repo = '/path/to/your/repo'
44
45export const lead = defineHarness({
46 name: 'acme/lead',
47 adapter: openaiText('gpt-6.1-sol'),
48 plugins: () => [
49 permissions(),
50 codingAgents({
51 sandbox: defineSandbox({
52 id: 'repo',
53 provider: localProcessSandbox({ dir: repo }),
54 workspace: defineWorkspace({ source: localSource(repo) }),
55 }),
56 agents: {
57 claude_code: {
58 adapter: claudeCodeText('claude-opus-4-8', { permissionMode: 'acceptEdits' }),
59 description: 'Larger changes, refactors, and reviews',
60 },
61 codex: {
62 adapter: codexText('gpt-5.3-codex', { sandboxMode: 'workspace-write' }),
63 description: 'Quick fixes and tests',
64 },
65 },
66 }),
67 ],
68})
69```
70
71`localProcessSandbox({ dir: repo })` works in your repo folder itself, so every thread and every agent shares that folder. Leave out `dir` to give each sandbox its own copy of the repo.
72
73The lead model now has a `claude_code` tool and a `codex` tool. Each tool takes one `task`: the whole job, in words. The agent sees only that text and the files in its sandbox.
74
75## 2. Ask for work
76
77Open a session, and give the lead a task for both agents:
78
79```ts group=harness-coding-agents
80import { createHarnessHost } from '@tanstack/ai-harness'
81import { memoryPersistence } from '@tanstack/ai-persistence'
82
83const host = createHarnessHost({ persistence: memoryPersistence() })
84const session = await host.open(lead, { threadId: 'date-parser' })
85
86const turn = await session.send(
87 'Have claude_code add a test for the date parser, then have codex fix what fails.',
88)
89console.log(turn.text)
90```
91
92The lead calls `claude_code` with a task, and gets back its answer. Then it calls `codex`. Each agent works in the same sandbox, one after the other.
93
94## Sessions
95
96Each agent keeps its own session per harness thread. The next task for `claude_code` resumes the same Claude Code session, so it still knows the files it read. The session ids live in the plugin state, so they also survive a restart of the host.
97
98To start over, run `/fresh claude_code`, or `/fresh` for every agent.
99
100## Workspaces
101
102`workspace` chooses where the agents work:
103
104| Value | Where each agent works | At the same time |
105| --- | --- | --- |
106| `'shared'` (default) | One sandbox per harness thread | One agent at a time |
107| `'per-agent'` | A sandbox per agent | Yes |
108
109Use `'shared'` when the agents build on each other's changes. Use `'per-agent'` when they work on separate copies and you merge the results.
110
111Only the host that owns the log of the thread runs its agents. So with many servers, `'shared'` still runs one agent at a time.
112
113## Plan mode
114
115When the `permissions()` plugin is in [`plan` mode](./permissions#pick-a-mode), the agents start read-only:
116
117- Claude Code gets `permissionMode: 'plan'`.
118- Codex gets `sandboxMode: 'read-only'`.
119- Any other agent gets its `planModelOptions`, for example `{ permissionMode: 'default' }` for an ACP agent that asks before each edit.
120- An agent with no `planModelOptions` does not run in `plan` mode. Its tool call gets an error.
121
122## Other agents and sandboxes
123
124- `adapter` takes any coding-agent adapter: `grokBuildText` from `@tanstack/ai-grok-build`, or `acpCompatibleText` from `@tanstack/ai-acp` for any ACP agent.
125- `sandbox` takes any sandbox provider. [Sandbox providers](../sandbox/providers) lists them.
126- `modelOptions` on an agent is added to every call, for example a fixed `permissionMode`.
127
128## What you have now
129
130- A lead model that hands tasks to Claude Code and Codex.
131- One sandbox per thread, and one saved session per agent.