πŸ€– AI Tools
Β· 5 min read

Gemini CLI Subagents: Parallel Task Delegation Guide (2026)


Gemini CLI now supports subagents β€” specialized AI agents that run in their own context window, with their own tools and system prompts. Instead of cramming everything into one conversation, you delegate specific tasks to focused specialists.

This shipped in April 2026 and mirrors what Claude Code has had with its subagent feature. The key difference: Gemini CLI subagents are fully customizable via Markdown files and support parallel execution out of the box.

What subagents solve

Without subagents, a long coding session accumulates context: file reads, tool outputs, debugging attempts. Eventually the context window fills up and quality degrades β€” what Anthropic calls β€œcontext rot.”

Subagents fix this by running tasks in isolated context windows. The main agent delegates a task, the subagent does the work in its own context, and only the result comes back to the main conversation. All the intermediate steps (file reads, failed attempts, debugging) stay in the subagent’s context and don’t pollute yours.

How to use subagents

Automatic delegation

Gemini CLI automatically delegates to built-in subagents when it recognizes a task that matches a specialist. You don’t need to do anything β€” the main agent decides when to delegate.

Manual delegation with @ syntax

Force delegation to a specific subagent:

@codebase-investigator What authentication patterns does this project use?

@cli-help How do I configure custom subagents?

@browser-agent Check the Stripe API docs for webhook signature verification

The @agent-name syntax tells Gemini CLI to route the task directly to that subagent instead of handling it in the main context.

Built-in subagents

Gemini CLI ships with four built-in subagents:

SubagentPurposeBest for
Codebase InvestigatorDeep code analysis”How does auth work in this project?”
CLI Help AgentGemini CLI documentation”How do I configure settings?”
Generalist AgentGeneral-purpose tasksOverflow tasks that don’t fit a specialist
Browser Agent (experimental)Web browsing and research”Check the docs for this API endpoint”

The Codebase Investigator is the most useful. It reads through your project files in its own context window, builds understanding, and returns a summary. Your main context stays clean.

Creating custom subagents

Custom subagents are defined as Markdown files in .gemini/agents/:

<!-- .gemini/agents/security-reviewer.md -->
---
name: security-reviewer
description: Reviews code for security vulnerabilities
tools:
  - read_file
  - search_files
  - web_search
---

You are a security expert. When given code to review:

1. Check for SQL injection, XSS, CSRF, and authentication issues
2. Check for hardcoded secrets and credentials
3. Check dependency versions for known CVEs
4. Provide specific fix recommendations with code examples

Be thorough but concise. Prioritize critical issues first.

Then use it:

@security-reviewer Review the authentication middleware in src/auth/

Configuration schema

The frontmatter supports:

name: agent-name           # How you invoke it with @
description: What it does  # Shown in /agents list
tools:                     # Restrict available tools
  - read_file
  - edit_file
  - shell
model: gemini-2.5-pro      # Override the model (optional)

Tool wildcards

Use * to give a subagent access to all tools, or restrict to specific ones for security:

# Full access
tools:
  - "*"

# Read-only (safe for analysis tasks)
tools:
  - read_file
  - search_files
  - list_directory

Restricting tools is important for agent security. A code review subagent shouldn’t need shell access.

Parallel execution

Gemini CLI can run multiple subagents simultaneously. When the main agent identifies independent tasks, it delegates them in parallel:

Refactor the auth module and update the API docs at the same time.

Gemini CLI might spawn:

  1. A subagent to refactor src/auth/
  2. A subagent to update docs/api.md

Both run concurrently. Results merge back into the main context when both complete.

You can also force parallel execution:

@codebase-investigator Analyze the database schema
@security-reviewer Check the API endpoints for auth issues

Both subagents start immediately in their own context windows.

Managing subagents

Interactive management

Use /agents in Gemini CLI to see all available subagents, their status, and configuration.

Persistent configuration

Configure subagent behavior in settings.json:

{
  "subagents": {
    "enabled": true,
    "auto_delegate": true,
    "max_parallel": 3,
    "custom_agents_dir": ".gemini/agents"
  }
}

Disabling subagents

If you prefer single-agent mode:

{
  "subagents": {
    "enabled": false
  }
}

Gemini CLI vs Claude Code subagents

FeatureGemini CLIClaude Code
Custom agentsβœ… Markdown files❌ Built-in only
Parallel executionβœ… Nativeβœ… Native
Tool restrictionβœ… Per-agent❌ Same tools as main
@ syntaxβœ… @agent-name❌ Natural language delegation
Agent-to-Agent (A2A)βœ… Remote subagents❌ Not supported
Model overrideβœ… Per-agent❌ Same model
Context isolationβœ… Fullβœ… Full

Gemini CLI’s advantage is customization. You can create domain-specific agents with restricted tools and even different models. Claude Code’s advantage is simplicity β€” you just tell it to β€œspin up a subagent” in natural language.

Practical subagent setups

For a full-stack project

.gemini/agents/
β”œβ”€β”€ frontend-expert.md      # React, CSS, browser APIs
β”œβ”€β”€ backend-expert.md       # API design, database, auth
β”œβ”€β”€ test-writer.md          # Writes and runs tests
└── security-reviewer.md    # Security analysis (read-only tools)

For a monorepo

.gemini/agents/
β”œβ”€β”€ service-a-expert.md     # Knows service A's codebase
β”œβ”€β”€ service-b-expert.md     # Knows service B's codebase
β”œβ”€β”€ infra-expert.md         # Terraform, Docker, CI/CD
└── api-contract-checker.md # Validates API contracts between services

For code review

.gemini/agents/
β”œβ”€β”€ style-checker.md        # Code style and conventions
β”œβ”€β”€ perf-analyzer.md        # Performance analysis
β”œβ”€β”€ security-scanner.md     # Vulnerability detection
└── doc-checker.md          # Documentation completeness

Run all four in parallel on a PR: @style-checker @perf-analyzer @security-scanner @doc-checker Review the changes in this PR.

When to use subagents vs a single agent

Use subagents when:

  • Tasks are independent and can run in parallel
  • You need domain expertise (security, performance, specific service)
  • Your main context is getting long and quality is degrading
  • You want tool restrictions for safety

Use a single agent when:

  • Tasks are sequential and depend on each other
  • The context is short and focused
  • You need the agent to see the full picture at once

For most real projects, a mix works best. Start in single-agent mode, delegate to subagents when the context gets heavy or when you need parallel work.

Related: Claude Code vs Codex CLI vs Gemini CLI Β· How to Build Multi-Agent Systems Β· Agent Orchestration Patterns Β· How to Debug AI Agents Β· AI Agent Security Β· OpenAI Agents SDK Guide Β· Kimi CLI vs Gemini CLI