How to Configure Claude Code's Sub-Agent Orchestration for Parallel, Sequential, and Background Work

How to Configure Claude Code's Sub-Agent Orchestration for Parallel, Sequential, and Background Work

Add routing rules to your CLAUDE.md to make your central AI delegate tasks intelligently—parallel for independent domains, sequential for dependencies, background for research.

4h ago·3 min read·1 views·via medium_agentic
Share:

The Technique: Teaching Your Central AI to Delegate

Your main Claude Code chat session isn't just one AI—it's an orchestration system. This "central AI" coordinates specialist sub-agents, and the quality of your work depends entirely on how well you've taught it to delegate. Without explicit routing rules in your CLAUDE.md, it defaults to conservative sequential execution—safe but slow.

Why It Works: Matching Execution Patterns to Task Dependencies

Claude Code's Task tool supports three execution modes, each serving different needs:

Parallel Execution works when tasks span independent domains. The central AI should dispatch parallel sub-agents when work touches different files or unrelated code sections. Without domain-based routing rules, it won't recognize these boundaries.

Sequential Execution is necessary when output from one step feeds the next. Common chains include: refactoring → testing, API design → implementation, or data model changes → migration scripts. Without chain definitions, your central AI might parallelize work that must be serial.

Background Execution keeps your main session responsive during research tasks. When the central AI spawns documentation lookups, codebase exploration, or performance profiling, it should background them automatically so you can continue working.

How To Apply It: CLAUDE.md Routing Framework

Add this decision framework to your project's CLAUDE.md:

## Sub-Agent Execution Rules

### Parallel Execution (Domain-Based Splitting)
Run in parallel when tasks involve:
- Different files or modules
- Independent features/components
- Separate API endpoints
- Unrelated bug fixes

Example: "Add user authentication and implement payment processing" → spawn two parallel agents.

### Sequential Execution (Dependency Chains)
Run sequentially when tasks depend on:
- Refactoring → testing
- API design → implementation
- Data model changes → migration scripts
- Core logic → UI integration

Example: "Redesign database schema and update all queries" → single agent completes both steps.

### Background Execution Rules
Run in background automatically:
- Web research and documentation lookups
- Codebase exploration and analysis
- Security audits and performance profiling
- Any task where results aren't immediately needed

Press Ctrl+B during any sub-agent execution to force background mode.
Check `/tasks` anytime to see background agent progress.

Advanced Configuration: Model Selection and Persistent Agents

Beyond routing rules, you have direct control over sub-agent behavior:

Choose the Sub-Agent Model by setting CLAUDE_CODE_SUBAGENT_MODEL in your environment. This is one of the most impactful optimizations for cost and speed:

# Run main session on Opus, sub-agents on Sonnet
export CLAUDE_CODE_SUBAGENT_MODEL=claude-3-5-sonnet-20241022

This pattern cuts costs significantly without sacrificing quality on well-scoped sub-agent work.

Define Persistent Agents in .claude/agents/ as Markdown files with YAML frontmatter. These specialist agents are available to Claude's orchestrator automatically:

---
name: security-auditor
description: Specializes in security vulnerability scanning
model: claude-3-5-sonnet-20241022
auto_background: true
---

I am a security specialist who examines code for vulnerabilities...

Project agents (.claude/agents/) are specific to your repository and shareable with your team. User agents (~/.claude/agents/) are available across all your projects.

The Result: Smarter, Faster Development

With these routing rules configured, your central AI makes delegation decisions based on your project's actual structure and dependencies. Parallel execution accelerates independent work, sequential chains maintain integrity for dependent tasks, and background research keeps your main session responsive.

Check /tasks regularly to monitor sub-agent progress, and remember that Ctrl+B is always available to manually background any task that's blocking your workflow.

AI Analysis

Claude Code users should immediately add execution routing rules to their CLAUDE.md files. This isn't just about speed—it's about teaching your central AI to understand your project's architecture and dependencies. Start with the parallel/sequential/background framework in your main CLAUDE.md. Then, for complex projects, create persistent agents in `.claude/agents/` for specialized tasks like security auditing or performance profiling. Set `CLAUDE_CODE_SUBAGENT_MODEL=claude-3-5-sonnet-20241022` to run sub-agents on Sonnet while keeping your main session on Opus—this cuts costs by 60-80% for sub-agent work. Remember to use Ctrl+B liberally during research tasks. If you're waiting for documentation lookup or code analysis, background it and continue working. The `/tasks` command shows all active sub-agents, so you can monitor progress without interrupting your flow.
Original sourcemedium.com

Trending Now

More in Products & Launches

Browse more AI articles