---
title: "Subagents"
description: "Delegate tasks to independent subagents that work in the foreground or background"
icon: "users"
---

Subagents let the main agent spawn independent workers to handle subtasks. A subagent shares tools and codebase context with the parent, but operates in its own conversation chain -- it does not inherit the parent's conversation history. This is useful for tasks that benefit from focused, independent work -- like exploring a codebase, running tests, or implementing a feature in parallel.

You can ask the agent to use subagents explicitly (e.g. "research how auth works in a subagent"), or the agent may decide to delegate on its own when it determines a task would benefit from independent work.

---

## How Subagents Work

When the agent spawns a subagent, it selects one of the available **subagent profiles** and chooses whether the subagent should run in the foreground or background. Subagents can run in two modes:

<CardGroup cols={2}>
  <Card title="Foreground" icon="display">
    Runs inline in your session. The parent agent pauses and waits for the subagent to finish before continuing. You can approve or deny tool calls as they come up.
  </Card>
  <Card title="Background" icon="clock">
    Runs in parallel while the parent agent continues working. The parent is automatically notified when the subagent completes. Unapproved tools are automatically denied.
  </Card>
</CardGroup>

<Note>
You do not see the subagent's raw output directly. When a subagent finishes, the parent agent reads the result and summarizes the key findings and actions for you.
</Note>

---

## Subagent Profiles

Each subagent runs with a specific profile that determines its capabilities:

| Profile | Description | Tool Access |
|---------|-------------|-------------|
| `subagent_explore` | Read-only codebase exploration and research | Read-only tools only (regardless of foreground or background) |
| `subagent_general` | General-purpose tasks including code changes | Full tool access (foreground) or pre-approved tools only (background) |

<Note>
The agent automatically chooses the appropriate profile based on the task. Explore subagents are ideal for research and understanding, while general subagents can make changes.
</Note>

---

## Tool Permissions

How tool permissions work depends on whether the subagent is running in the foreground or background:

- **Foreground subagents** behave like the main agent -- you are prompted to approve or deny tool calls as usual.
- **Background subagents** inherit any tool permissions you have already granted during the current session. Any tool that has not been pre-approved is automatically denied. Background subagents cannot prompt you for new permissions.

<Tip>
If a background subagent fails because a required tool was denied, you can resume it in the foreground to approve the necessary permissions. See [Resuming Subagents](#resuming-subagents) below.
</Tip>

---

## Monitoring Subagents

### Subagent Indicator

When background subagents are running, an indicator appears below the input area showing their status. You can navigate to the indicator by pressing <kbd>&darr;</kbd> from the input area, then press <kbd>Enter</kbd> to open the subagent panel.

When a foreground subagent is running, the spinner displays **"Subagent running · Ctrl+B to run in background"**.

### Subagent Panel

The subagent panel lets you view and manage all active and completed subagents. It shows each subagent's profile, title, status, elapsed time, and tool call count.

**Selector mode** (when multiple subagents exist):

| Key | Action |
|-----|--------|
| <kbd>&uarr;</kbd> / <kbd>k</kbd> / <kbd>Shift+Tab</kbd> / <kbd>Ctrl+P</kbd> | Navigate up |
| <kbd>&darr;</kbd> / <kbd>j</kbd> / <kbd>Tab</kbd> / <kbd>Ctrl+N</kbd> | Navigate down |
| <kbd>Enter</kbd> | View selected subagent |
| <kbd>f</kbd> | Move background subagent to foreground |
| <kbd>x</kbd> | Cancel a running subagent |
| <kbd>Esc</kbd> / <kbd>Ctrl+C</kbd> | Close the panel |

**View mode** (viewing a specific subagent):

| Key | Action |
|-----|--------|
| <kbd>f</kbd> | Move background subagent to foreground |
| <kbd>x</kbd> | Cancel a running subagent |
| <kbd>Esc</kbd> / <kbd>Ctrl+C</kbd> | Go back to selector (or close if only one subagent) |

Nested subagents (subagents spawned by other subagents) are displayed with indentation to show the parent-child relationship.

---

## Foreground / Background Switching

You can move subagents between foreground and background while they're running:

- **Background a foreground subagent:** Press <kbd>Ctrl</kbd>+<kbd>B</kbd> while a foreground subagent is running. The subagent continues working in the background, and the parent agent resumes.
- **Foreground a background subagent:** Open the subagent panel and press <kbd>f</kbd> on a running background subagent. The subagent's output will display inline.

<Note>
When you move a subagent to the background, the parent agent's tool call has already returned, so the parent continues independently. The subagent's result won't feed back into the parent's current pipeline, but you'll be notified when it completes.
</Note>

---

## Cancelling Subagents

You can cancel a running subagent in two ways:

1. **From the subagent panel:** Open the panel and press <kbd>x</kbd> on a running subagent.
2. **Foreground subagent:** Press <kbd>Ctrl</kbd>+<kbd>C</kbd> or <kbd>Esc</kbd> to cancel the currently running foreground subagent.

---

## Resuming Subagents

Cancelled, failed, or completed subagents can be resumed with a new prompt. You can ask the agent to resume a subagent, and it will continue where it left off. Resumed subagents always run in the **foreground**, so you can approve any tool calls that were previously denied.

This is especially useful when:

- A background subagent failed because a required tool was denied -- resume it in the foreground to grant the necessary permissions.
- A subagent completed but you want it to do additional follow-up work based on its findings.
- A subagent was cancelled prematurely and you want it to continue.

---

## Nesting Depth

Subagents can spawn their own subagents, up to a maximum depth of 3 levels. At the maximum depth, subagent tools are disabled to prevent unbounded nesting.
