Modern coding isn’t just about writing lines of code anymore — it’s about working smarter. Whether you’re casually “vibe coding” or building serious production systems, agents and sub-agents in Claude Code can take a huge load off your plate.
Think of them as a small team of specialists you can call on whenever you need help. They let you break down complex work, keep your code quality high, and avoid running into the limits of large language models — all without losing your flow.
Let’s walk through how they work and how you can actually use them in real projects.
1. What Are Agents?
At a high level, agents are specialized helpers inside Claude Code. Instead of using one general-purpose assistant for everything, agents are designed to be really good at specific tasks.
Claude Code already comes with a few built-in agents you can start using right away, for example:
- Bash Agent – Great for running terminal commands, scripts, and git operations.
- Explore Agent – A fast, lightweight agent for searching through files or spotting patterns in a codebase.
- Planning Agent – A smarter agent that helps you think through requirements and plan solutions before coding.
- Claude Code Guide – An agent that knows Claude Code itself inside and out.
The big win here is focus: each agent does one thing well, so you don’t have to overload a single conversation with everything.
2. How to Use Agents in Claude Code
Using agents is surprisingly simple.
You can talk to any agent directly by tagging it with @, followed by the agent’s name. This lets you skip the “general” assistant and go straight to the specialist you need.
You can also run agents in the background by pressing Ctrl + B, which means you can keep working while the agent does its thing.
Example:
If you want help understanding a Claude Code feature, you can ask the guide directly:
@claude-code-guide how do environment variables work in projects?
No extra setup, no context switching — just ask.
3. Creating Your Own Custom Agents
This is where things get really powerful.
You can create your own agents that follow your project’s rules, design preferences, or coding standards — so you don’t have to repeat yourself every time.
How to create a custom agent:
- Run the
/agentscommand in Claude Code. - Choose whether the agent is:
- Project-level (only for this repo), or
- Personal-level (available everywhere).
- Give it a name and a clear system prompt (basically: how it should think and behave).
- Choose which tools it’s allowed to use.
- Pick a model:
- Opus for deep thinking,
- Sonnet for a good balance,
- Haiku for fast, lightweight tasks.
Example:
You might create a “API Architect” agent and instruct it to:
- design REST APIs,
- enforce consistent naming,
- and always think about versioning and error handling.
From then on, whenever you’re working on backend routes, you can ask this agent for help without restating those rules.
4. What Are Sub-Agents?
Sub-agents are where Claude Code really starts to feel like a team.
A sub-agent is simply an agent (built-in or custom) that your main assistant asks to handle a specific task — in its own separate thread.
Why does this matter?
Because conversations have a limited context window. The more you cram into one thread, the more likely the model is to compress or forget important details.
Sub-agents solve this by:
- running in their own context,
- doing the heavy lifting there,
- and sending back a short, clean summary.
Your main conversation stays focused and high quality.
5. Using Sub-Agents in Practice
You don’t “call” sub-agents directly. Instead, you tell your main agent to delegate work to them.
This is especially useful when:
- analyzing large codebases,
- running multiple tasks in parallel,
- or doing research-heavy work.
Example:
Rather than asking your main agent to review your entire frontend, you might say:
“Ask one explore agent to review the components folder and another to summarize the state management approach.”
Both sub-agents work at the same time and send back concise summaries — saving tokens and keeping your main thread easy to follow.
6. Building Workflows with Custom Sub-Agents
Here’s a nice mental shift:
“Sub-agent” isn’t a special setting — it’s a workflow choice.
You create agents the same way as before using /agents, and then decide how they work together.
Example workflow:
- Create a “Feature Builder” agent
- Focused on implementing features based on written requirements.
- Create a “QA Checker” agent
- Focused on edge cases, error states, and regressions.
- Coordinate them
- Ask your main agent: “Have the feature builder implement user authentication, then pass it to the QA checker to look for issues.”
Your main agent becomes the coordinator, while sub-agents quietly handle focused tasks in the background. This makes even large builds feel manageable.
Final Thoughts
Agents and sub-agents aren’t just a productivity trick — they change how you think about working with AI.
Once you start delegating intentionally, Claude Code stops feeling like a single assistant and starts feeling like a small, well-organized dev team that never gets tired.
If you want to go deeper and explore all the official details, best practices, and use cases, make sure to check out the official Claude Code Sub-Agents User Guide here:
👉 https://code.claude.com/docs/en/sub-agents
It’s a great companion to everything covered in this article.