Skip to content

How Do You Use Orchestrator Mode with Sub-Agents in AI Coding Assistants?

The Problem: Why Single-Agent Mode Falls Short

I used to run everything through one agent. A single AI assistant handling my entire workflow—planning, coding, reviewing, debugging. It worked, but the costs were eating my budget and the results were inconsistent.

Here’s what I noticed:

ProblemImpact
Context pollutionEvery task shares the same context window, causing confusion
No specializationOne model does everything, even tasks it’s bad at
Cost inefficiencyExpensive models handle trivial tasks
No parallel executionTasks run sequentially, wasting time

I needed a better architecture. That’s when I discovered orchestrator mode with sub-agents.

The Solution: Orchestrator Architecture

Orchestrator mode uses a lead agent that delegates tasks to specialized sub-agents. Each sub-agent has:

  • Isolated context (doesn’t pollute other tasks)
  • A specific role (security reviewer, code writer, test generator)
  • The ability to run in parallel with other sub-agents

Here’s what this looks like:

Orchestrator architecture diagram
┌─────────────────────────────────────────────────────────┐
│ ORCHESTRATOR │
│ (Cheap Model: GPT-4o-mini) │
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Planner │ │ Coder │ │ Reviewer │ │
│ │ (Claude) │ │ (Sonnet) │ │ (Opus) │ │
│ │ Specialized │ │ Specialized │ │ Specialized │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ │
│ ┌─────────────┐ ┌─────────────┐ │
│ │ Tester │ │ Security │ │
│ │ (Haiku) │ │ (Opus) │ │
│ │ Specialized │ │ Specialized │ │
│ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────┘

The orchestrator doesn’t do the heavy lifting—it routes tasks to the right specialist.

Why This Matters: Real Cost Savings

I ran a comparison on a typical coding session (10 tasks, mixed complexity):

ModeModel UsedCostTime
Single-agentClaude Opus 4$2.4012 min
OrchestratorMixed models$0.858 min

The orchestrator used:

  • GPT-4o-mini for routing and simple tasks
  • Claude Haiku for test generation
  • Claude Sonnet for coding
  • Claude Opus only for complex reviews

Result: 65% cost reduction and 33% faster execution.

Implementation: Three Approaches

1. OpenCode Native Configuration

OpenCode supports orchestrator mode out of the box. Here’s how I configured it:

opencode-config.yaml
orchestrator:
enabled: true
model: gpt-4o-mini
agents:
planner:
model: claude-sonnet-4
context: isolated
coder:
model: claude-sonnet-4
context: isolated
reviewer:
model: claude-opus-4
context: isolated
tester:
model: claude-haiku-4
context: isolated

The key settings:

  • enabled: true activates orchestrator mode
  • context: isolated prevents context pollution
  • Different models for different tasks optimize costs

2. Claude Code CLI: Manual Implementation

Claude Code CLI doesn’t have an orchestrator mode toggle. But you can implement the pattern using the task tool:

orchestrator-agent.ts
async function orchestrateTask(task: Task) {
// Step 1: Analyze and route (cheap model)
const route = await analyzeTask(task);
// Step 2: Delegate to specialists (parallel execution)
const results = await Promise.all([
delegateToAgent('coder', route.codingTasks),
delegateToAgent('reviewer', route.reviewTasks),
delegateToAgent('tester', route.testTasks)
]);
// Step 3: Aggregate and finalize
return aggregateResults(results);
}

The task tool spawns sub-agents:

subagent-spawn.ts
// Spawn a specialized sub-agent for code review
const reviewResult = await task({
agent: 'security-reviewer',
prompt: 'Review this authentication code for vulnerabilities',
context: isolatedContext
});

3. LangGraph: Full Control

For maximum flexibility, LangGraph gives you complete control over the orchestrator pattern:

langgraph-orchestrator.py
from langgraph.graph import StateGraph, END
from langchain_anthropic import ChatAnthropic
from langchain_openai import ChatOpenAI
# Define models
orchestrator_model = ChatOpenAI(model="gpt-4o-mini")
coder_model = ChatAnthropic(model="claude-sonnet-4")
reviewer_model = ChatAnthropic(model="claude-opus-4")
tester_model = ChatAnthropic(model="claude-haiku-4")
# Define state
class AgentState(TypedDict):
task: str
code: str
review: str
tests: str
# Orchestrator node
def orchestrator(state: AgentState) -> AgentState:
# Route to appropriate sub-agents
return {"task": state["task"]}
# Specialist nodes
def code_agent(state: AgentState) -> AgentState:
code = coder_model.invoke(state["task"])
return {"code": code}
def review_agent(state: AgentState) -> AgentState:
review = reviewer_model.invoke(state["code"])
return {"review": review}
def test_agent(state: AgentState) -> AgentState:
tests = tester_model.invoke(state["code"])
return {"tests": tests}
# Build graph
workflow = StateGraph(AgentState)
workflow.add_node("orchestrator", orchestrator)
workflow.add_node("coder", code_agent)
workflow.add_node("reviewer", review_agent)
workflow.add_node("tester", test_agent)
# Define edges (parallel execution)
workflow.add_edge("orchestrator", "coder")
workflow.add_edge("coder", "reviewer")
workflow.add_edge("coder", "tester") # Runs in parallel with reviewer
app = workflow.compile()

The graph structure enables parallel execution:

Workflow graph
orchestrator
coder
├──────────┐
▼ ▼
reviewer tester
│ │
└────┬─────┘
END

Common Mistakes I Made

Mistake 1: Expecting a Toggle

I wasted hours looking for an “orchestrator mode” switch in Claude Code CLI. It doesn’t exist—you need to implement it yourself using the task tool or background agents.

Mistake 2: Using Expensive Models for Everything

My first orchestrator used Claude Opus for all sub-agents. The costs were higher than single-agent mode. The key insight: match model capability to task complexity.

Task ComplexityRecommended Model
Routing, simple tasksGPT-4o-mini, Haiku
Coding, planningSonnet
Security review, architectureOpus

Mistake 3: No Context Isolation

I initially shared context between sub-agents. The reviewer saw the planner’s internal notes, causing confusion. Always use isolated context:

context-isolation.ts
// WRONG: Shared context
const context = { task, plannerNotes, coderDrafts };
// CORRECT: Isolated context per agent
const coderContext = { task, requirements };
const reviewerContext = { code, standards };

Mistake 4: Blocking Execution

My first implementation ran sub-agents sequentially:

execution-patterns.ts
// WRONG: Sequential execution
const plan = await planner(task);
const code = await coder(plan);
const review = await reviewer(code);
// CORRECT: Parallel execution where possible
const [review, tests] = await Promise.all([
reviewer(code),
tester(code)
]);

When to Use Orchestrator Mode

ScenarioUse Orchestrator?Why
Single file editNoOverkill
Multi-file refactoringYesContext isolation helps
Code review + testsYesParallel execution
Simple bug fixNoSingle agent is faster
Complex featureYesSpecialization matters

Summary

In this post, I showed how orchestrator mode with sub-agents solves the context pollution and cost problems of single-agent workflows. The key principles:

  1. Use a cheap model for orchestration—routing doesn’t need Claude Opus
  2. Match model capability to task complexity—Haiku for tests, Opus for security reviews
  3. Isolate context between sub-agents—prevent cross-contamination
  4. Parallelize independent tasks—run reviews and tests simultaneously
  5. Implement manually if needed—Claude Code CLI requires custom setup

The result: better outputs at lower costs. Start simple—don’t implement a full orchestrator for every task. Use single-agent mode for trivial work, and scale to orchestrator mode when complexity justifies the setup cost.

Final Words + More Resources

My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me

Here are also the most important links from this article along with some further resources that will help you in this scope:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!

Comments