Module 9

Subagents & Power Moves

Subagents are specialized AI assistants that work alongside Claude — like hiring extra team members for specific jobs. Combined with parallel sessions and batch processing, they unlock a whole new level of productivity.

📖 12 min 🌱 Advanced ✎ 1 exercises
Clawd

What Are Subagents?

Until now, you’ve been working with Claude as a single assistant — one conversation, one task at a time. But some jobs are too big or too specialized for one agent to handle alone.

Subagents are specialized AI assistants that Claude can delegate work to. Think of it like a manager who hires specialists: instead of doing everything themselves, they assign the security review to a security expert, the documentation to a technical writer, and the testing to a QA engineer.

Claude Code comes with built-in subagents and lets you create your own custom ones.

🔑 Key Concept

Subagents are focused experts. Each subagent has a specific role, specific tools, and specific instructions. Claude can spin up multiple subagents at once, each working on a different part of a problem, then combine their results. It’s teamwork — with AI.

Built-In Subagents

Claude Code ships with two powerful built-in subagents:

Explore — A research agent that reads files, searches codebases, and gathers information without modifying anything. It’s read-only, which makes it safe for investigation.

Plan — A planning agent that analyzes a problem, considers trade-offs, and creates a step-by-step implementation plan. It doesn’t write code — it strategizes.

You can invoke them directly:

Terminal

> Use the Explore agent to figure out how authentication works in this project. I want to know which files handle login, what library is used, and where tokens are stored.

Delegating to Explore agent… Reading src/auth/login.ts Reading src/middleware/auth.ts Reading src/utils/tokens.ts Searching for JWT references… Explore agent report: Authentication uses NextAuth.js with JWT tokens…
research without modifying anything
Use the Explore agent to map out every API endpoint in this project. List each endpoint, its HTTP method, what it does, and which file it's defined in.
get a strategic plan before coding
Use the Plan agent to design how we should add multi-language support to this app. Consider the file structure, translation approach, and which parts of the UI need changes. Don't write any code yet.

Custom Agents

The real power comes from creating your own agents. Custom agents live in the .claude/agents/ directory of your project. Each one is a Markdown file with a name, description, and detailed instructions.

Here’s what a custom agent looks like:

.claude/agents/security-reviewer.md
--- name: security-reviewer description: Reviews code for security vulnerabilities allowed-tools: Read, Grep, Glob, WebSearch --- You are a security review specialist. When given code to review: 1. Check for OWASP Top 10 vulnerabilities 2. Look for hardcoded secrets or API keys 3. Check for SQL injection and XSS risks 4. Verify authentication and authorization checks 5. Flag any use of deprecated or insecure libraries Rate each finding as Critical, High, Medium, or Low severity. Provide a specific fix for each issue found.

Now you can use this agent anytime:

run a security review with your custom agent
Ask the security-reviewer agent to review the src/auth/ directory and all API routes for vulnerabilities.
Clawd
Pro Tip

Notice that the security reviewer only has Read, Grep, Glob, WebSearch as allowed tools — it cannot edit files. This is by design. A reviewer should find problems, not fix them. You decide what to fix.

Parallel Sessions with Worktrees

Here’s where things get really interesting. Normally, Claude works on one thing at a time. But what if you need to build three features simultaneously?

Git worktrees let Claude run multiple sessions in parallel, each working on a separate copy of your code. Think of it like having three desks in your office — each one has a different project spread out, and you can work on any of them without shuffling papers.

Terminal

$ claude —worktree feature-auth Created worktree: feature-auth Working in: ~/project/.worktrees/feature-auth

> Build the authentication system with email/password login and OAuth support.

While that session works on authentication, you can open another terminal and start a parallel session:

Terminal

$ claude —worktree feature-dashboard Created worktree: feature-dashboard Working in: ~/project/.worktrees/feature-dashboard

> Build the admin dashboard with user management and analytics charts.

Both sessions run at the same time, working on separate branches. When they’re done, you merge the results. It’s like having two developers working in parallel — except both of them are Claude.

🔑 Key Concept

Worktrees create isolated copies of your project. Each copy has its own branch, so changes don’t interfere with each other. Claude can work on feature A in one worktree and feature B in another, simultaneously. When both are done, you merge them together.

Batch Processing with /batch

What if you need to make the same change across dozens of files? The /batch command processes multiple items in sequence or parallel:

update many files at once
/batch For each React component in src/components/, add TypeScript prop types and convert any class components to functional components with hooks.

This is the “mass operation” tool. Instead of asking Claude to update files one by one, you describe the pattern once, and Claude applies it everywhere.

Other examples:

generate tests for every file
/batch For each utility function in src/utils/, generate a comprehensive test file with at least 5 test cases covering edge cases. Save tests to src/__tests__/.

Non-Interactive Mode

Sometimes you want Claude to run a task without any conversation — just execute and report back. That’s what non-interactive mode is for:

Terminal

$ claude -p “Read the README.md and list all the dependencies mentioned in it”

Dependencies found in README.md: - React 18.2 - Next.js 14 - Tailwind CSS 3.4 - PostgreSQL 15

The -p flag stands for “prompt.” Claude runs the task, prints the result, and exits. No interactive session, no back-and-forth. This is essential for automation — you can use it in scripts, cron jobs, and CI/CD pipelines.

Clawd
Pro Tip

Combine non-interactive mode with scheduled tasks for powerful automation. For example: claude -p "Check for security vulnerabilities and email me a report" running every night at midnight via cron.

The Fan-Out Pattern

The most advanced technique combines everything you’ve learned: fan-out. This is when you split a large task into subtasks, assign each to a subagent or worktree, run them in parallel, then combine the results.

Here’s the pattern:

Fan-Out Pattern
1. PLAN → Use the Plan agent to break the task into subtasks 2. FAN OUT → Spawn a worktree or subagent for each subtask 3. EXECUTE → All subtasks run in parallel 4. MERGE → Combine all results into the main branch 5. REVIEW → Use a review agent to check the combined work
full fan-out workflow
I need to add a complete user settings page with: profile editing, notification preferences, billing management, and theme customization. Use the Plan agent to create a plan, then spin up separate worktrees for each section. When all are done, merge them and run a review.
⚠ Heads Up

Parallel worktrees use more system resources (memory and CPU). Running 2-3 in parallel is usually fine. Running 10+ might slow your computer down significantly. Start small and scale up as you learn your machine’s limits.


Try It Yourself

✎ Exercise 1

Use a Subagent for Research

  1. Open Claude Code in any project that has code in it
  2. Ask Claude: “Use the Explore agent to give me a complete overview of this project — what it does, what technologies it uses, how it’s organized, and what the main entry point is.”
  3. Read the Explore agent’s report — notice how it searched multiple files without changing anything
  4. Now ask Claude: “Use the Plan agent to suggest 3 improvements to this project, ranked by impact. For each one, outline the specific files that would need to change.”
  5. Bonus: Create a custom agent at .claude/agents/code-reviewer.md that reviews code for readability and naming conventions. Ask Claude to help you write the file, then test it on one of your source files.
Clawd

Ready for Module 10?

Putting It Together is up next.

Continue →