Gemini CLI Subagents
Subagents bring parallel task delegation to Gemini CLI, letting you split complex work across multiple independent agents that run simultaneously. Introduced in Gemini CLI v0.36, subagents dramatically reduce the time it takes to complete multi-part tasks by executing them concurrently instead of sequentially.
What Are Subagents?
Subagents are lightweight, independent Gemini CLI instances that handle specific subtasks in parallel. When you give Gemini CLI a complex task, the parent agent analyzes the work, identifies components that can run independently, spawns focused subagents for each component, and aggregates the results into a unified output.
Each subagent operates in its own context window and has full access to Gemini CLI tools. A subagent can read files, write files, run shell commands, and use any tool that the parent agent can use. The key difference is scope: each subagent focuses exclusively on its assigned subtask, which means it uses its context window more efficiently and completes its work faster than a single agent handling everything sequentially.
Subagents are not simply threads or background processes. They are full Gemini CLI instances with their own reasoning capabilities. The parent agent acts as an orchestrator, deciding how to decompose the task, what instructions to give each subagent, and how to merge the results. This architecture mirrors how experienced engineering teams work: a lead breaks down a project, assigns pieces to team members, and integrates the deliverables.
The practical impact is significant. Tasks that previously took five to ten minutes of sequential processing can often complete in one to two minutes with subagents. This is especially true for tasks that involve processing multiple files, running independent analyses, or performing repetitive operations across different parts of a codebase.
How Subagents Work
The subagent architecture follows a straightforward decompose-delegate-merge pattern. Understanding this flow helps you write prompts that take full advantage of parallelism.
Architecture Flow
When the parent agent receives a complex task, it follows this sequence: first, it analyzes the task to identify independent subtasks. Then it spawns one subagent per subtask, each with its own context window, tool access, and specific instructions. The subagents work in parallel without communicating with each other. When all subagents finish, the parent collects their outputs and merges them into a coherent result.
# Subagent architecture diagram
Parent Agent
├── Subagent A: Run tests
├── Subagent B: Fix linting
└── Subagent C: Update docs
→ Merged Result
Each subagent is isolated. Subagent A does not know what Subagent B is doing, and vice versa. This isolation is intentional: it prevents subagents from conflicting with each other and ensures that each subagent can reason independently about its subtask. The parent agent is responsible for resolving any conflicts during the merge phase.
Launching Subagents
There are three ways to launch subagents, ranging from fully automatic to explicitly configured. Choose the method that gives you the right balance of convenience and control.
Automatic Detection
Gemini CLI automatically detects when a task can be parallelized and spawns subagents without any special syntax. This is the default behavior when the parent agent identifies independent components in your request.
# Gemini CLI auto-detects parallel opportunities
gemini "Run tests and lint in parallel, fix any issues found"
# Output:
Spawning 2 subagents...
[A] Running test suite...
[B] Running linter and fixing issues...
Both subagents completed. Merging results...
Manual Launch
In interactive mode, use the @subagent directive to explicitly spawn a subagent for a specific task. This gives you precise control over what each subagent does.
# Manually spawn a subagent in interactive mode
> @subagent "Write unit tests for the auth module"
# Spawn multiple subagents at once
> @subagent "Write unit tests for auth"
> @subagent "Write unit tests for payments"
> @subagent "Write unit tests for notifications"
Configuration
Control the maximum number of concurrent subagents through Gemini CLI configuration. This is useful for managing resource usage on machines with limited memory or API rate limits.
# Set maximum concurrent subagents
gemini config set maxSubagents 4
# View current configuration
gemini config get maxSubagents
# Override for a single session
gemini --max-subagents 6 "Process all modules"
Practical Examples
Subagents excel in real-world scenarios where multiple independent tasks need to happen simultaneously. Here are three common patterns that demonstrate how subagents accelerate everyday development workflows.
Parallel Test and Lint
Running your test suite and fixing lint errors are completely independent tasks. Subagents let you do both at the same time, cutting your CI feedback loop in half.
gemini "Run the full test suite and fix all ESLint errors"
# Gemini CLI spawns 2 subagents:
[Subagent 1] Running npm test...
[Subagent 2] Running eslint --fix on src/...
# Results merged:
Tests: 142 passed, 3 failed
Lint: 17 issues fixed automatically
Time: 45s (vs ~90s sequential)
Multi-File Refactoring
When renaming a symbol across a large codebase, Gemini CLI can assign one subagent per directory or module. Each subagent handles its portion of the rename independently, and the parent merges all changes together.
gemini "Rename userId to accountId across all files"
# Subagent-per-directory approach:
[Subagent 1] Renaming in src/auth/ (4 files)
[Subagent 2] Renaming in src/api/ (7 files)
[Subagent 3] Renaming in src/models/ (3 files)
[Subagent 4] Renaming in tests/ (12 files)
# All 26 files updated in parallel
Renamed 89 occurrences across 26 files
Time: 30s (vs ~2min sequential)
Parallel Code Review
Reviewing multiple pull requests is a naturally parallel task. Each PR is independent, so Gemini CLI spawns one subagent per PR to analyze the changes and produce a summary simultaneously.
gemini "Review these 5 PRs and summarize"
# 5 parallel subagents, one per PR:
[Subagent 1] Reviewing PR #201: Add user avatars
[Subagent 2] Reviewing PR #203: Fix payment rounding
[Subagent 3] Reviewing PR #205: Upgrade React to v19
[Subagent 4] Reviewing PR #207: Add rate limiting
[Subagent 5] Reviewing PR #209: Refactor auth flow
# Aggregated summary from parent agent:
5 PRs reviewed. 2 approved, 3 need changes.
Subagent Communication
Subagents do not communicate directly with each other during execution. Instead, all communication flows through the parent agent in a structured pattern. Each subagent returns a summary of its work, including any files it created or modified, any errors it encountered, and a natural-language description of what it accomplished.
The parent agent receives these summaries and synthesizes them into a coherent result. If two subagents modified the same file, the parent detects the conflict and resolves it intelligently, typically by applying changes sequentially or asking you to choose between conflicting edits. All file changes from all subagents are staged together as a single logical unit, so you can review the complete set of changes before committing.
This one-way communication model keeps the architecture simple and predictable. You never have to worry about subagents interfering with each other or creating race conditions. The parent agent handles all coordination, conflict resolution, and final output assembly.
Resource Management
Running multiple subagents consumes more tokens and system resources than a single agent. Gemini CLI provides several controls to help you manage resource usage effectively.
Token Budgets
Each subagent receives a token budget from the parent. By default, the parent divides its remaining budget equally among subagents. You can override this to give more tokens to complex subtasks.
# Set per-subagent token limit
gemini --subagent-tokens 8000 "Analyze all modules"
# View token usage after execution
gemini usage --last-session
Parent agent: 2,400 tokens
Subagent A: 6,200 tokens
Subagent B: 5,800 tokens
Total: 14,400 tokens
Concurrency Limits
Use the --max-subagents flag to cap the number of subagents running simultaneously. This prevents overwhelming your API rate limits or local system resources.
# Limit to 3 concurrent subagents
gemini --max-subagents 3 "Process all 10 modules"
# Gemini CLI queues the remaining 7:
[1/10] [2/10] [3/10] running...
[4/10] queued, waiting for slot...
Timeout Handling
Set timeouts to prevent subagents from running indefinitely. If a subagent exceeds its timeout, the parent agent cancels it and reports a partial result.
# Set 60-second timeout per subagent
gemini --subagent-timeout 60 "Review all files"
# If a subagent times out:
[Subagent 3] Timed out after 60s. Partial result saved.
Parent agent continuing with 2/3 complete results.
Subagent vs Plan Mode
Subagents and Plan Mode solve different problems. Understanding when to use each feature, and when to combine them, helps you choose the most efficient approach for any task.
Subagents
- • Independent parallel tasks
- • Tasks that do not depend on each other
- • Speed is the primary goal
- • Multiple files or modules processed simultaneously
- • Results merged after all subagents finish
Plan Mode
- • Sequential dependent steps
- • Each step depends on the previous one
- • Safety and review are the primary goals
- • Preview changes before execution
- • Steps executed one at a time with checkpoints
Combined: The Best of Both
The most powerful workflow combines Plan Mode and subagents. Plan Mode creates a structured sequence of steps, and subagents execute independent steps in parallel. The parent agent identifies which steps can run concurrently and which must run sequentially, giving you both safety and speed.
gemini plan "Migrate the codebase from Express to Fastify"
# Plan Mode creates the steps:
Step 1: Update package.json dependencies (sequential)
Step 2: Convert route handlers (parallel via subagents)
├── Subagent A: Convert src/routes/users.js
├── Subagent B: Convert src/routes/auth.js
└── Subagent C: Convert src/routes/products.js
Step 3: Update middleware (sequential)
Step 4: Update tests (parallel via subagents)
├── Subagent D: Update tests/routes/users.test.js
├── Subagent E: Update tests/routes/auth.test.js
└── Subagent F: Update tests/routes/products.test.js
Related Questions
Speed Up Your Workflow
Start using subagents to parallelize your development tasks and experience faster results: