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:
| Problem | Impact |
|---|---|
| Context pollution | Every task shares the same context window, causing confusion |
| No specialization | One model does everything, even tasks it’s bad at |
| Cost inefficiency | Expensive models handle trivial tasks |
| No parallel execution | Tasks 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 ││ (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):
| Mode | Model Used | Cost | Time |
|---|---|---|---|
| Single-agent | Claude Opus 4 | $2.40 | 12 min |
| Orchestrator | Mixed models | $0.85 | 8 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:
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: isolatedThe key settings:
enabled: trueactivates orchestrator modecontext: isolatedprevents 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:
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:
// Spawn a specialized sub-agent for code reviewconst 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:
from langgraph.graph import StateGraph, ENDfrom langchain_anthropic import ChatAnthropicfrom langchain_openai import ChatOpenAI
# Define modelsorchestrator_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 stateclass AgentState(TypedDict): task: str code: str review: str tests: str
# Orchestrator nodedef orchestrator(state: AgentState) -> AgentState: # Route to appropriate sub-agents return {"task": state["task"]}
# Specialist nodesdef 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 graphworkflow = 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:
orchestrator │ ▼ coder │ ├──────────┐ ▼ ▼ reviewer tester │ │ └────┬─────┘ ▼ ENDCommon 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 Complexity | Recommended Model |
|---|---|
| Routing, simple tasks | GPT-4o-mini, Haiku |
| Coding, planning | Sonnet |
| Security review, architecture | Opus |
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:
// WRONG: Shared contextconst context = { task, plannerNotes, coderDrafts };
// CORRECT: Isolated context per agentconst coderContext = { task, requirements };const reviewerContext = { code, standards };Mistake 4: Blocking Execution
My first implementation ran sub-agents sequentially:
// WRONG: Sequential executionconst plan = await planner(task);const code = await coder(plan);const review = await reviewer(code);
// CORRECT: Parallel execution where possibleconst [review, tests] = await Promise.all([ reviewer(code), tester(code)]);When to Use Orchestrator Mode
| Scenario | Use Orchestrator? | Why |
|---|---|---|
| Single file edit | No | Overkill |
| Multi-file refactoring | Yes | Context isolation helps |
| Code review + tests | Yes | Parallel execution |
| Simple bug fix | No | Single agent is faster |
| Complex feature | Yes | Specialization 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:
- Use a cheap model for orchestration—routing doesn’t need Claude Opus
- Match model capability to task complexity—Haiku for tests, Opus for security reviews
- Isolate context between sub-agents—prevent cross-contamination
- Parallelize independent tasks—run reviews and tests simultaneously
- 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