Sub Agents in Claude Code: Why You Should Try Them Now
Claude Code's sub agents are like specialized functions for development. Instead of cramming everything into one conversation, delegate specific tasks to focused agents. My 6-agent workflow covers analysis, planning, validation, and cleanup.

Not too long ago, Anthropic added a feature to Claude Code that flew relatively under the radar: sub agents. You can access this feature through the agents command in Claude Code, where you'll see both the built-in agents that come with Claude Code and any custom agents you've defined for your user or project.
I took time to really think about what problem they're trying to solve, and it took me even longer to give them serious thought and real experimentation. Just this week, it finally clicked for me. There are two related concepts worth discussing: functions and focus.
One of the simplest yet most powerful principles in programming is breaking code into functions. When I write code, I love the mental clarity that function decomposition gives me. Given a complex task, I know I can write the high-level functionality I want using function names that clearly express what I want them to do. This way, I can organize a sequence of operations using function names and then easily implement the well-defined functionality behind them. Within each function, I can apply the same approach recursively.
This approach separates organization from implementation, allows us to focus on developing well-defined functionality, and enables us to modify and edit functionality as long as it maintains the same interface.
Focus is an obvious concept, but it's still not obvious in language models. We have a very limited resource when working with agents: the context window. No matter how much we advance in the future, the context window will always be limited, just like our CPU memory is limited, and we as engineers invest significant resources in what goes into memory.
With agents and language models, the problem is even more complex. Every piece of information we feed into the context window receives attention, and language models don't have the ability to give more or less attention based on what the user actually wants. Language models' behavior regarding what to pay attention to within the context window can greatly affect their behavior.
For example: suppose we asked at the beginning of a conversation to implement a function that involves API calls. Along the way, the model struggled to find the right approach to work with the API and dedicated, say, 30% of the context to solving this problem. Now we have a session where 30% of the tokens are "dedicated" to solving this problem, creating a significant bias that might cause the model to think the main problem to solve is API access, while it forgets or pays less attention to the original request.
These two elements lead us to using sub agents. In this approach, we can at any point in time during a session extract a task or request to a separate agent with its own context window, and get back only the relevant information or a summary of the agent's actions.
Here's how I've structured my development workflow using specialized sub agents to maintain focus while ensuring comprehensive task completion:
Every complex task starts with understanding. Before diving into implementation, I use the codebase-context-analyzer to map out all relevant code sections, architectural patterns, and dependencies. This agent examines the existing implementation, identifies integration points, and provides the complete picture needed for informed decision-making. It's like having a senior developer conduct a thorough code walkthrough before you start working.
Once I understand the context, the task-decomposer breaks down complex requirements into manageable, well-defined subtasks with clear completion criteria. This agent transforms vague objectives into concrete work items, organizing them into logical phases with testable outcomes. It prevents scope creep and ensures nothing gets overlooked.
With a clear task structure, the tech-lead-architect researches best practices, analyzes the current implementation, and proposes lean solutions. This agent searches the web for current approaches, applies software engineering principles, and creates a comprehensive technical workplan. It considers trade-offs, scalability, and long-term maintenance while recommending the most elegant solution.
After implementation, the task-completion-verifier provides an unbiased assessment of whether tasks were actually completed correctly. This agent tests functionality, validates that requirements were met, and adds comprehensive tests to the repository. It's like having a senior QA engineer review your work with fresh eyes.
Once functionality is confirmed, the code-cleanup-optimizer removes intermediate files, eliminates redundant code, and cleans up outdated comments. After cleanup, I run the task-completion-verifier again to ensure nothing was broken during optimization. This maintains a lean, maintainable codebase.
When I need to improve developer experience, set up deployments, or configure local environments, the devops-experience-architect handles all aspects of development infrastructure. This agent optimizes build processes, manages environment configurations, and ensures smooth development workflows.
The Real Power: This workflow creates a systematic approach where each agent contributes specialized expertise while maintaining the overall context and quality of the work. Instead of asking the main session agent to handle DevOps setup (which would pollute the context with Docker configurations and environment variables), I delegate that to a specialized agent and get back only the essential information - how to run the services and what was changed.
Each agent maintains focus on their domain expertise, preventing the context window bias problem I described earlier. The key insight is that complex development tasks benefit from this division of labor - analysis, planning, implementation, validation, optimization, and infrastructure - each handled by a focused specialist.
Sub agents represent a fundamental shift in how we can structure our interactions with AI coding assistants. Instead of cramming everything into one increasingly complex conversation, we can:
- Maintain clarity in our main development session
- Delegate specific tasks to specialized agents
- Preserve context for what matters most
- Reduce cognitive overhead by not having to manage multiple complex threads simultaneously
This approach allows you to work more efficiently by treating sub agents as specialized functions you can call when you need focused expertise without polluting your main context.
Try creating agents for:
- DevOps and environment management
- Code review and refactoring
- Documentation generation
- Testing and debugging specific issues
The key is to think of sub agents not as a replacement for your main Claude Code session, but as specialized functions you can call when you need focused expertise without losing the thread of your main work.
For those curious about the technical implementation, Claude Code's agent generation system demonstrates sophisticated prompt engineering principles that align with Anthropic's guidance on writing tools for agents.
When you use Claude Code's AI-assisted agent creation, it leverages a carefully crafted system prompt that enforces structure and quality:
The system uses multiple strategies to ensure reliable JSON generation:
- Primary Parser: Direct JSON parsing from Claude's response
- Fallback Parser: Regex extraction when the response contains additional text
- Validation Layer: Comprehensive field validation and error recovery
This multi-layered approach demonstrates how to build robust AI-assisted configuration tools that handle the non-deterministic nature of LLM outputs while maintaining reliability.
Claude Code's implementation embodies several key principles from Anthropic's tool design guidelines:
Clear Role Definition: The system prompt establishes Claude as an "expert at creating specialized AI agent configurations," setting clear expectations.
Structured Constraints: Identifier naming rules are explicitly defined with validation patterns, ensuring consistency across generated agents.
Context Optimization: The system includes conflict prevention by checking existing agent identifiers and warning Claude against duplicates.
Quality Guidelines: The prompt includes comprehensive best practices for each field, essentially teaching Claude how to write effective agent configurations.
The generation process dynamically constructs prompts based on context:
This approach demonstrates how to build adaptive prompt engineering that responds to the current system state.
The system uses specific API parameters optimized for reliable generation:
- Temperature: 0.3 - Low temperature for consistent, structured output
- No tool forcing - Allows Claude to focus purely on text generation
- Prompt category tagging - "agent_creation" for potential future optimizations
Beyond generation, Claude Code implements multi-layer validation:
- Identifier validation: Regex patterns ensuring proper formatting
- Content validation: Minimum length requirements for descriptions
- Tool compatibility: Checking that selected tools work with chosen models
- Scope validation: Ensuring agents can be stored in the intended scope
This systematic approach to AI-assisted configuration creation provides a blueprint for building reliable tools that leverage LLM capabilities while maintaining deterministic outcomes where needed.
For those interested in implementing similar workflows, here are the complete configurations for all the agents mentioned in my workflow: