Skip to main content

Overview

Subagents are specialized AI agents that can be delegated specific tasks. They operate independently from the main agent, allowing for:
  • Parallel execution of multiple tasks
  • Domain specialization with focused instructions
  • Isolated reasoning for complex problems
  • Reduced context pollution in the main conversation
Think of subagents as coworkers you delegate work to - each with their own expertise and focus.

How Subagents Work

1

Task Delegation

The main agent identifies a subtask suitable for delegation and invokes the task tool.
2

Subagent Initialization

A specialized agent is spawned with:
  • The specific task description
  • Relevant context from the main conversation
  • Access to the same tools as the main agent
  • Independent conversation history
3

Independent Execution

The subagent:
  • Reasons about the task independently
  • Calls tools as needed
  • Builds its own conversation context
  • Requests approvals separately (in default mode)
4

Result Return

When complete, the subagent returns:
  • Task results
  • Any artifacts created
  • Summary of actions taken
  • Token usage statistics
5

Main Agent Continues

The main agent receives the results and continues with the overall task.

Using Subagents

Natural Language

The AI automatically delegates when appropriate:

Explicit Delegation

You can also use the /agents command:
This opens a configuration dialog where you specify:
  • Name: Identifier for this subagent type
  • Instructions: Specialized system prompt
  • Tools: Which tools this agent can use
  • Model: Specific model for this agent (optional)

Subagent Types

Built-in Subagent Patterns

Purpose: Analyze code for issuesInstructions:
Tools: read, grep, glob, web_fetch (read-only)Usage:

Managing Subagents

Creating Custom Subagents

Configuration example:

Managing Existing Subagents

Actions available:
  • View: See subagent configuration
  • Edit: Modify instructions or settings
  • Delete: Remove a subagent
  • Duplicate: Copy and customize an existing subagent
  • Export: Save subagent to a file
  • Import: Load subagent from a file

Sharing Subagents

Subagent configurations are stored in:
Share with team:

Subagent Behavior

Independent Context

Each subagent has its own conversation history:

Tool Access

Subagents can use the same tools as the main agent:
  • read - Read files
  • write_file - Create files
  • edit - Modify files
  • glob - Find files
  • ls - List directories

Approval Modes

Subagents respect the global approval mode but can have overrides:

Nested Subagents

Subagents can delegate to other subagents:
Nesting is limited to prevent infinite recursion:

Monitoring Subagents

In Interactive Mode

Subagent activity is displayed with indentation:

Stats and Metrics

Shows:
  • Number of subagent invocations
  • Average duration per subagent
  • Token usage per subagent type
  • Success/failure rates

Use Cases

Scenario: Building multiple independent features
Scenario: Complex refactoring with multiple phases
Scenario: Comprehensive code review
Scenario: Creating comprehensive docs

Configuration

Project-Level Subagents

Global Settings

Advanced Features

Subagent Communication

Subagents can pass data between each other:

Custom Models per Subagent

Resource Limits

Troubleshooting

Problem: Main agent isn’t delegating to subagents.Solutions:
  • Make the task more complex (simple tasks don’t need delegation)
  • Explicitly mention using specialized agents
  • Check that subagents are enabled in settings
  • Ensure the task matches subagent capabilities
Problem: Everything is delegated, making things slower.Solutions:
  • Adjust delegation threshold in settings
  • Be more specific in prompts
  • Disable some subagents temporarily
  • Use simpler prompts for simple tasks
Problem: Multiple subagents editing the same files.Solutions:
  • More specific task delegation
  • Use sequential rather than parallel delegation
  • Define clear boundaries in subagent instructions
  • Let main agent coordinate conflicts
Problem: Subagents consuming too many tokens.Solutions:
  • Set maxTokens per subagent
  • Use faster models for simple subagents
  • Limit nesting depth
  • Reduce maxConcurrent subagents

Best Practices

  1. Clear boundaries: Define what each subagent should (and shouldn’t) do
  2. Specialized instructions: Make subagents experts in narrow domains
  3. Limit tools: Only give subagents the tools they need
  4. Set resource limits: Prevent runaway subagents with timeouts and token limits
  5. Test subagents: Try them with specific prompts before relying on them
  6. Monitor usage: Check stats to optimize subagent configuration
  7. Version control: Keep subagent configs in your repo for team sharing
  8. Start simple: Begin with basic subagents, add complexity as needed

Next Steps

Skills System

Combine subagents with skills for powerful workflows

Approval Modes

Configure approval for subagent actions

Session Commands

Use /agents commands to manage subagents

Configuration

Advanced subagent configuration options