Master Claude Code Sub‑Agents in 10 Minutes

Prompt EngineeringAbout 4 min readJul 29, 2025Watch original
THE SUMMARYAI-generated

Key Concepts

  • Sub Agents: Specialized instances of Claude code used by a main orchestrator for specific tasks.
  • Context Management: Maintaining separate context windows for each sub agent and the main orchestrator to avoid clutter and improve efficiency.
  • Tool Selection: Assigning specific tools to each sub agent to improve the accuracy and relevance of tool usage.
  • Orchestrator: The main Claude code instance that interacts with the user and manages the sub agents.
  • System Prompt: Custom instructions that define the behavior and expertise of each sub agent.

Sub Agents in Claude Code: Addressing Context Management and Tool Selection

The video discusses Anthropic's sub agents in Claude code, which aim to solve context management and tool selection challenges in agentic systems. Sub agents are presented as specialized instances of Claude code that the main orchestrator can use on demand.

How Sub Agents Work

  1. Orchestrator: The main Claude code instance interacts with the user.
  2. Sub Agent Definition: Each sub agent has its own context window, custom system prompt, and specific set of tools.
  3. Task Execution: When a task is assigned, the orchestrator delegates it to the appropriate sub agent.
  4. Result Return: The sub agent performs the task and returns only the final results to the orchestrator, keeping the main context window clean.

Benefits of Using Sub Agents

  • Context Preservation: Separate context windows for each sub agent prevent the main context window from becoming cluttered.
  • Flexible Permissions: Sub agents can be granted specific permissions based on their roles.
  • Improved Tool Selection: By assigning specific tools to each sub agent, the probability of accurate tool selection is increased.
  • Separation of Expertise: Each sub agent specializes in a specific area, allowing for more focused and effective task execution.
  • Reusability: Sub agents can be reused at both the project and system levels.

Creating and Defining Sub Agents

  • Markdown Files: Sub agents are defined using markdown files that include the agent's name, purpose, tools, and system prompt.
  • /agents Command: The /agents command in Claude code is used to create new sub agents.
  • Project vs. User Level: Sub agents can be created at the project level or the user level.
  • Claude Code Assistance: Claude code can assist in generating descriptions and assigning tools for sub agents.

Using Sub Agents

  • Explicit Invocation: Sub agents can be explicitly invoked during a conversation with Claude code.
  • Automatic Detection: Claude code can automatically detect and select a sub agent based on its description and the task at hand.
  • Complex Orchestration: Sub agents can be chained sequentially or run in parallel to create complex workflows.

Practical Example in Claude Code

The video demonstrates how to create a "unit test writer" sub agent in Claude code.

  1. Description: The agent is described as being responsible for writing unit tests for every change made by the main agent.
  2. Tool Assignment: Relevant tools are assigned to the sub agent.
  3. System Prompt: A system prompt is defined to instruct the agent on its role and expertise.
  4. Invocation: The sub agent is invoked by asking Claude code to "write unit tests to test the current functionality."
  5. Execution: The sub agent generates the unit tests and returns the results to the main orchestrator.

Considerations

  • Token Usage: Creating and using sub agents can consume a significant number of tokens.
  • Anthropic Max Plan: The Anthropic Max plan is recommended for users who plan to use sub agents extensively.
  • Rate Limits: Anthropic is rolling out new weekly rate limits for Claude Pro and Max plans, which may affect some users.

Notable Quotes

  • "Think of sub agents as specialized instances of cloud code that your main orchestrator can use on demand."
  • "Every unnecessary change is technical debt. Every breaking change is a future bug. Every duplicate feature is wasted effort. Be the guardian of the code quality that every team needs to but few appreciate." (Example system prompt for a code quality auditor agent)

Technical Terms

  • Context Window: The amount of text that a language model can consider when generating a response.
  • Orchestrator: The main Claude code instance that manages and coordinates the sub agents.
  • System Prompt: Instructions that define the behavior and expertise of a language model or sub agent.
  • Tokens: Units of text used to measure the input and output of a language model.

Logical Connections

The video logically connects the challenges of context management and tool selection in agentic systems to the solution offered by Anthropic's sub agents. It explains how sub agents work, their benefits, how to create and use them, and provides a practical example to illustrate their application.

Synthesis/Conclusion

Sub agents in Claude code offer a powerful way to address context management and tool selection challenges in agentic systems. By creating specialized instances of Claude code with their own context windows, system prompts, and tools, developers can build more efficient, accurate, and reusable agentic workflows. While token usage and rate limits should be considered, the benefits of sub agents make them a valuable tool for building complex and sophisticated applications with Claude.

AI summaries can miss context or contain errors. Check important details against the original video.

MAKE IT YOURS

Read. Remember. Reuse.

Free tools

Go a little deeper.

Have a question about this video? Load its transcript to open the video chat.