Skip to main content

What are subagents?

                        (Show All)_ · **Lesson 1/4** · [🌐 Vietnamese](../../vi/01-what-are-subagents/vi.md)

Previous: — · 📋 Course TOC · Next →

What are subagents?

👨‍💻 Track: Developer Track · 📚 Course: Introduction to Subagents · 🧭 Path C

📖 Lesson content

Subagents are specialized assistants that Claude Code can delegate tasks to. Think of them as focused helpers: each one runs in its own conversation context window, does its work, and returns a summary to the main thread. The intermediate steps -- all the file reads, searches, and tool calls -- stay isolated and never clutter your main conversation.

Why Subagents Matter

Every time you chat with Claude Code, you're adding to the main context window. Every tool call, every file read, every search result gets stored there. That space is finite, and once it fills up, Claude starts losing track of earlier parts of the conversation.

Subagents solve this by spinning up a separate context window. The subagent receives two things:

  • A custom system prompt from your configuration file that defines the subagent's role and behavior
  • A task description written by the parent agent based on what you asked for

The subagent then works on its own. It reads files, runs searches, edits code -- whatever it needs to do. When it's done, only a summary comes back to your main conversation. The entire subagent conversation is then discarded.

This means your main context stays clean. You get the answer without all the noise of the journey it took to find it. The tradeoff is that you lose visibility into how the subagent reached its conclusions.

A Practical Example

Say you're exploring an unfamiliar codebase and you want to know which service handles refunds. Without a subagent, Claude might read 15 files, run several searches, and trace through multiple function calls. All of that fills your context window, even though you only needed one fact.

With a subagent, the experience is much cleaner. You ask the question, the Explore subagent spins up, does all that digging in its own context, and hands back a focused answer.

Your main context window only records the question and the summary -- not the 15 files that were read along the way.

Built-in Subagents

Claude Code ships with several built-in subagents you can use right away:

  • General purpose subagent -- for multi-step tasks that require both exploration and action
  • Explore -- for fast searching and navigation of codebases
  • Plan -- used during plan mode for research and analysis of your codebase before presenting a plan

Custom Subagents

Beyond the built-in options, you can create your own subagents with custom system prompts and tool access. This lets you define specialized agents tailored to your workflow -- a code reviewer, a test writer, a documentation generator, or anything else you need.

Takeaways

Subagents give you three main benefits:

  • They break work into focused pieces, letting each subagent concentrate on a specific task
  • They keep your main context window clean by isolating all the intermediate work
  • They bring back just the information you need as a concise summary

Whether you're using the built-in subagents or creating your own, they're a practical way to get more out of longer Claude Code sessions. The less noise in your main context, the longer and more effectively you can work.

🎬 Video transcript

Source video: jKErNxuxPXg

📜 Click to expand transcript (cleaned + AI-translated)

Introduction to Subagents in Claude Code

Subagents are specialized assistants that Claude Code can delegate tasks to. Each subagent runs in its own conversation context window with a custom system prompt that you define. When finished, it returns a summary to the main thread while all the intermediate work stays isolated.

How Subagents Work

The subagent receives two primary inputs: a custom system prompt from your configuration file and a task description written by the parent agent based on your request. Once activated, the subagent works autonomously. When it reads files, edits files, or uses tools, none of these actions appear in the main conversation; only a summary is returned. After the task is completed, the entire subagent conversation is completely discarded.

Managing Context Window Usage

One of the main advantages of subagents is that they help manage context window usage. When you chat with Claude Code, every interaction adds context to the main window. Every tool call and its results are stored there.

By using a subagent, a separate window is started. This prevents the main context window from being cluttered with intermediate steps. This is crucial for maintaining performance and efficiency during long sessions.

Practical Example: Codebase Investigation

Consider a task like investigating how the payment system works in an unfamiliar codebase. You might use Claude Code to figure out which service handles refunds.

  • Without a subagent: Claude might read 15 files, run several searches, and trace through multiple function calls. All of that context fills your main context window, even if you only needed one single fact: which service handles refunds.
  • With a subagent: You get the answer without the "journey." The subagent explores, discovers the answer, and returns a focused summary, keeping your main context clean.

However, it is important to note that the main window loses visibility into how the subagent reached its conclusions and what it discovered along the way.

Built-in and Custom Subagents

Claude Code includes several built-in subagents that you can use immediately:

  • General Purpose Subagent: Used for multi-step tasks that require both exploration and action.
  • Explore Subagent: Used for fast searching of codebases.
  • Plan Subagent: Used during "plan mode" for research and analysis of your codebase before presenting a plan.

Beyond these, you can also create your own subagents with custom system prompts and specific tool access. Subagents allow Claude Code to break work into focused pieces, keeping your main context window clean and bringing back exactly what you need. Whether you are using the built-in options or creating your own, they are a practical way to get more out of longer Claude Code sessions.

🔁 Related lessons

📚 Source & attribution

Was this lesson helpful?

Feedback / ReportSpotted an issue or have an improvement idea?