✦ Updated April 14, 2026

Subagents
in Gemini CLI

Specialized agents that operate within your main Gemini CLI session — each with its own system prompt, toolset, and independent context window.

🔍 codebase_investigator 📖 cli_help ⚡ generalist 🌐 browser_agent 🔗 Agent2Agent (A2A)
Source: geminicli.com · 4 Built-in Agents · Custom Agents Supported
What are subagents?

Subagents — Specialists Your Main Agent Can Hire

🔗

Subagents handle specific, complex tasks without cluttering the main agent's context or toolset. The main agent exposes each subagent as a callable tool. It delegates, the subagent runs in its own loop, then reports back with findings.

🎯
Each subagent has its own system prompt and persona, running in a separate context loop. The subagent's history never bleeds into the primary agent — token usage in your main conversation stays lean.
🔧
Tool isolation ensures each agent only accesses its explicitly granted tools. Use wildcards like mcp_* to grant groups of tools with precision.
🤝
Delegation Model
Delegation happens automatically when a task matches a subagent's description, or explicitly via the @ syntax. Results are returned to the main agent on completion.
Explicit Invocation

Forcing a Subagent with the @ Syntax

🔗

Prefix any prompt with @subagent_name to bypass the main agent's routing and go straight to a specialist.

@codebase_investigator Map out the relationship between AgentRegistry and LocalAgentExecutor.

How it works

The @ prefix injects a system note nudging the primary model to invoke that specific subagent tool immediately. Use it when you know exactly which specialist to call — no routing decision, no ambiguity.

Built-in Subagents

Four Specialists, Ready Out of the Box

🔗

Three are enabled by default. The browser_agent is experimental and must be explicitly enabled via agents.overrides in settings.json.

🔍
Codebase Investigator codebase_investigator
Analyzes codebases, reverse engineers code, maps complex dependencies. Default enabled. Override model and maxTurns via agents.overrides.
  • How does the auth system work?
  • Map AgentRegistry dependencies
📖
Expert knowledge on Gemini CLI — commands, configuration, and documentation. Default enabled.
  • How do I configure a proxy?
  • What does /rewind do?
Generalist Agent generalist
Inherits full tool access from the main agent. Ideal for multi-file refactors, high-volume terminal output, and action-oriented research in isolated context.
  • Multi-file modifications
  • Extensive execution tasks
🌐
Browser Agent Experimental
Automates browser tasks via Chrome accessibility tree. Requires Chrome 144+. Disabled by default — enable via agents.overrides.
  • Fill forms, click buttons
  • Extract page data
Browser Agent Deep Dive

Session Modes & Security

🔗

The browser agent supports three Chrome session modes and enforces domain restrictions, blocked URL schemes, and action rate limiting.

persistent Default

Launches Chrome with a profile at ~/.gemini/cli-browser-profile/. Cookies, history, and settings preserved between sessions.

isolated

Temporary profile deleted after each session. Use for clean-state automation and testing scenarios.

existing

Attaches to an already-running Chrome instance with remote debugging enabled. Required for Docker/container sandbox environments.

🛡 Domain Restrictions

Set allowedDomains to restrict navigation. Disallowed domains throw fatal errors. Proxy bypass attempts via query parameters are detected and blocked.

🚫 Blocked URL Schemes

Always blocked: file://, javascript:, data:text/html, chrome://extensions, chrome://settings/passwords.

⏱ Action Rate Limiting

maxActionsPerTask (default: 100) limits total tool calls per task. The browser agent terminates when the limit is reached, preventing runaway execution.

👁 Visual Agent Mode

Set visualModel to enable screenshot-based interaction via analyze_screenshot. Requires API key or Vertex AI authentication. Not available with Sign in with Google.

Creating Custom Subagents

Agent Definition Files

🔗

Custom subagents are .md files with YAML frontmatter. Place in .gemini/agents/ (project, team-shared) or ~/.gemini/agents/ (user-level, personal).

--- name: security-auditor description: Finds security vulnerabilities. Use for SQL injection, XSS, hardcoded credentials, unsafe file ops. kind: local # or 'remote' for A2A tools: - read_file - grep_search model: gemini-3-flash-preview temperature: 0.2 max_turns: 10 --- You are a ruthless Security Auditor. Analyze code for vulnerabilities. Focus on: SQL Injection, XSS, hardcoded credentials, unsafe file operations. Report findings clearly with suggested fixes. Do not fix — only report.
FieldRequiredDescription
nameYesUnique slug — lowercase, hyphens, underscores. Becomes the tool name exposed to the main agent.
descriptionYesVisible to main agent. Write clearly — this determines when automatic delegation triggers.
kindNolocal (default) or remote for A2A remote delegation.
toolsNoTool access list. Wildcards: * (all), mcp_* (all MCP), mcp_server_*. Omit to inherit all parent tools.
mcpServersNoInline MCP server definitions isolated to this agent only.
modelNoSpecific Gemini model. Defaults to inherit (main session model).
temperatureNo0.0–2.0. Defaults to 1.
max_turnsNoMax conversation turns before the agent must return. Defaults to 30.
timeout_minsNoMax execution time in minutes. Defaults to 10.
Security & Isolation

Tool Isolation & Recursion Protection

🔗

Each subagent runs in its own isolated context loop. Subagents cannot call other subagents — even with * (all tools) granted.

🔒 Tool Isolation

Define exactly which tools an agent can access. Prevents unintended side effects and state contamination across the global tool registry. Enables fine-grained permission control per agent.

🔁 Recursion Guard

Framework-level protection: even with * granted, a subagent cannot see or invoke other subagents. Stops infinite delegation loops and runaway token usage.

🧩 Inline MCP Servers

Configure MCP servers in the agent's frontmatter under mcpServers. These are isolated to that agent only — not shared with the main session or other agents.

📋 Policy Engine

TOML [[rules]] blocks with a subagent property target specific agents. Grant or deny tool access and commands per agent without affecting the rest of your session.

Managing Subagents

Interactive & Persistent Configuration

🔗

Use /agents for on-the-fly changes; use agents.overrides in settings.json for persistent global overrides.

🖥️
/agents Command
Interactively manage subagents without editing config files. Enable, disable, or reconfigure on the fly. The recommended approach for quick session-level changes.
⚙️
Persistently enable/disable agents and override maxTurns, maxTimeMinutes, and model configuration across all sessions via settings.json.
🛡️
TOML policy files in ~/.gemini/policies/. Subagents are treated as virtual tool names — deny specific agents for specific sessions using the policy engine.
Getting Started

Create Your First Custom Subagent

🔗

Seven steps from idea to a working specialist agent.

1
Create a .md file in .gemini/agents/ (project-level, shared with team) or ~/.gemini/agents/ (user-level, personal). The filename is your natural identifier.
2
Add YAML frontmatter
Open with triple-dashed --- frontmatter. Required fields: name (slug — lowercase, hyphens, underscores only) and description. The main agent reads the description to decide when to delegate.
3
Write the system prompt
The Markdown body below the frontmatter becomes the agent's system prompt and persona. Be specific about role, focus areas, and constraints — this determines the quality of your specialist.
4
Configure tool access
Add a tools array listing exactly which tools the agent can use. Use wildcards (*, mcp_*, mcp_server_*) for flexible grants. Omit to inherit all parent tools.
5
Add optional tuning
Optionally set model, temperature (0.0–2.0), max_turns (default 30), timeout_mins (default 10), and mcpServers for inline MCP server definitions isolated to this agent.
6
Create a TOML file in ~/.gemini/policies/ with [[rules]] blocks. Add a subagent property to target your agent by name for fine-grained allow/deny control.
7
Manage via /agents or settings.json
Use /agents interactively for on-the-fly changes. Use agents.overrides for persistent model and run configuration. Tune the description for better automatic delegation reliability.
FAQ

Frequently Asked Questions

🔗
What are subagents in Gemini CLI?

Subagents are specialized agents operating within the main Gemini CLI session. Each has its own system prompt, persona, and toolset, running in an independent context window so they don't bloat the main conversation history.

How do I force a specific subagent?

Use the @ syntax at the start of your prompt — for example, @codebase_investigator explain the auth module. This bypasses automatic delegation and routes directly to the named subagent.

What built-in subagents are included?

Four: codebase_investigator (code analysis), cli_help (CLI docs), generalist (all-purpose), and browser_agent (experimental, disabled by default).

What is codebase_investigator best for?

Deep code analysis — understanding how systems work, tracing dependencies, reverse engineering complex modules. Use it for "How does the authentication system work?" or "Map out the AgentRegistry class dependencies."

What makes the generalist different from the main agent?

The generalist inherits the same full tool access but runs in an isolated context loop. Multi-step tasks with large outputs don't clutter the main conversation — only the final result is returned.

How do I enable the browser agent?

Add "browser_agent": {"enabled": true} under agents.overrides in settings.json. Also requires Chrome 144+. Choose a session mode: persistent (default), isolated, or existing.

Can subagents call other subagents?

No. Recursion protection prevents this even with the * wildcard granted. This stops infinite delegation loops and runaway token usage at the framework level.

Where do I place custom agent definition files?

In .gemini/agents/ at the project root (shared with your team) or ~/.gemini/agents/ at user level (personal, available across all projects).

What is tool isolation and why does it matter?

Tool isolation ensures subagents only access explicitly listed tools, preventing cross-agent state contamination and unauthorized actions. It enables fine-grained permission control per agent.

How do I restrict which tools a subagent can use?

Add a tools array in the YAML frontmatter. Use wildcards like mcp_* for all MCP tools, or omit the list entirely to inherit all parent session tools.

A2A enables Gemini CLI to delegate tasks to remote subagents running on external machines or services. Declare remote agents with kind: remote in their definition file.

How do I disable all subagents?

Set "enableAgents": false under experimental in settings.json. Individual agents can also be disabled with enabled: false under agents.overrides.

Glossary

Key Terms

🔗
A specialized AI agent operating inside the main Gemini CLI session with its own system prompt, toolset, and isolated context window.
The @subagent_name prefix forcing a prompt to be handled by a specific subagent, bypassing the main agent's automatic routing decision.
Security feature restricting each subagent to only explicitly listed tools, preventing cross-agent state contamination.
Framework-level guard preventing subagents from invoking other subagents, stopping infinite delegation loops and excessive token usage.
Protocol enabling Gemini CLI to delegate tasks to remote subagents running on external machines or services.
Standardized protocol for connecting AI models to external tools and data. MCP servers can be inlined in subagent definitions for isolated access.
Gemini CLI's TOML rule system for governing tool access. Rules can target specific subagents with the subagent property.
The separate conversation history maintained by each subagent, preventing subagent interactions from inflating the main agent's token usage.
Pattern-based tool grant: * (all), mcp_* (all MCP), mcp_server_* (all tools from a named MCP server).
A .md file with YAML frontmatter defining a custom subagent's name, description, tools, model, and system prompt. Placed in .gemini/agents/.