AI Engineer Guide

How to use Claude Code Sub Agents

Like the unix principle - Do one thing, do it well.

If an AI agent has to do only one task, it does the work really well.

But when you’re working on a large codebase, if you’re using only agent, it can potentially go rouge.

That’s where Sub agents feature in Claude Code comes in.

What are sub agents?

It is a custom agents that you can invoke to perform certain task.

You can configure it based on your needs - system prompts, tools, etc.

And the best part is it has a separate context window.

What the benefits of using it?

2025-07-28 at 23.19.57@2x.png

How to get started?

Run the following command in claude code

/agents

Now, Select Create New Agent (and choose whether you want this project level or user-level sub agent)

Then, define the sub agent.

Let claude generate the first draft for your sub agent. You can make changes on top of it.

You can use the available build in tools for your custom sub agent.

Where is the sub agents are stored?

It’s markdown file stored in the following places

TypeLocationScopePriority
Project sub agents.claude/agents/Available in current projectHighest
User sub agents~/.claude/agents/Available across all projectsLower

Example

Here is a code reviewer agent example that the Anthropic team has shared in their docs

---
name: code-reviewer
description: Expert code review specialist. Proactively reviews code for quality, security, and maintainability. Use immediately after writing or modifying code.
tools: Read, Grep, Glob, Bash
---

You are a senior code reviewer ensuring high standards of code quality and security.

When invoked:
1. Run git diff to see recent changes
2. Focus on modified files
3. Begin review immediately

Review checklist:
- Code is simple and readable
- Functions and variables are well-named
- No duplicated code
- Proper error handling
- No exposed secrets or API keys
- Input validation implemented
- Good test coverage
- Performance considerations addressed

Provide feedback organized by priority:
- Critical issues (must fix)
- Warnings (should fix)
- Suggestions (consider improving)

Include specific examples of how to fix issues.

References

Happy creating agents!

#TIL #Claude-Code

Stay Updated

Get the latest AI engineering insights delivered to your inbox.

No spam. Unsubscribe at any time.