Mastering Claude Code Sub-Agents: A Step-by-Step Guide

rcmiskrcmisk
5 min read

Claude Code - Sub-Agents - with Examples, Tools, Workflow Integration, and Session Strategies

Claude Code’s sub-agents are like specialized teammates you can summon inside your coding environment. Instead of asking your main assistant to do everything (debugging, reviewing, writing docs, analyzing data), you can spin up focused helpers with their own roles, permissions, and context.

This guide gives you the complete playbook:

  • What sub-agents are

  • When to use them (and when not to)

  • How to create them (UI + files)

  • Copy-paste examples

  • The full tool list + cheat sheet

  • How to incorporate them into your workflow while the main agent is running

  • When to use inline orchestration vs separate sessions


What are sub-agents?

Sub-agents are scoped assistants with:

  • Their own system prompt (role + rules)

  • Their own tool permissions (what they’re allowed to do)

  • Their own context window (fresh memory separate from your main thread)

You can either:

  • Invoke them explicitly by name (use the code-reviewer subagent…)

  • Or let Claude auto-delegate if your description matches their role

This separation keeps your main chat clean and makes tasks safer, faster, and more reliable.


When (and when not) to use sub-agents

Great fits

  • Multi-step tasks (e.g., research → write → review)

  • Guardrails (a reviewer that enforces security standards)

  • Specialized expertise (SQL queries, doc writing, profiling)

  • Extensible workflows (swap in a TweetWriter without touching research logic)

Overkill

  • One-off questions

  • Tiny edits or explanations that don’t need a dedicated context


How to create sub-agents

Option A — With the /agents UI

  1. Run /agents in Claude Code

  2. Click Create New Agent

  3. Fill in:

    • Name

    • Description (when/why to use it — keep action-oriented)

    • Tools (leave blank to inherit all)

  4. Save. Edit the system prompt if needed.

Option B — Markdown files

Sub-agents live in:

  • Project scope → .claude/agents/

  • User scope → ~/.claude/agents/

Example:

---
name: code-reviewer
description: Focused code review after each commit.
tools: Read, Grep, Glob, Bash
---

You are a senior reviewer. Always inspect diffs and enforce quality, security, and style.

Example sub-agents (drop into .claude/agents/)

(…examples for Code Reviewer, Debugger, Data Scientist, Reddit Researcher — unchanged here for brevity but included in full earlier…)


Full tool list

Sub-agents can be given these tools:

  • Read → Read files

  • Write → Create/edit files

  • Grep → Search inside files

  • Glob → Match file patterns (*.py, src/**)

  • Bash → Run shell commands/tests

  • MCP tools → External integrations (DBs, APIs, cloud services)

⚠️ If you omit the tools: line, the agent inherits all tools available in your main session.


Tool cheat sheet (by agent type)

Sub-Agent TypeRecommended ToolsWhy
Code ReviewerRead, Grep, Glob, BashInspects code only
DebuggerRead, Write, Grep, Glob, BashFixes + tests
Test RunnerRead, BashRuns test suites
Doc WriterRead, WriteUpdates docs
Data ScientistRead, Bash (+MCP DB)Runs queries
ProfilerRead, Bash, GrepRuns profiling tools
Security AuditorRead, Grep, GlobScans only
Content WriterRead, WriteCreates text artifacts
ResearcherBash or MCP onlySandbox
General Assistant(no tools: field)Full inherited toolset

Incorporating sub-agents into your workflow (while main agent is running)

(…section covering inline invocation, auto-delegation, chaining, /agents, Hooks, permissions, MCP, and workflow playbooks — as written in the prior draft…)


Using sub-agents in separate sessions

By default, sub-agents run inside your main session, returning results inline. But you can also spin up dedicated sessions where a sub-agent is the “main persona.”

Inline orchestration (default)

  • Stay in one thread

  • Call code-reviewer, debugger, etc. inline

  • Results are merged into your main chat

  • Great for continuity, orchestration, and quick workflows

Separate sessions

  • Open a new Claude Code session and choose a sub-agent directly

  • That session runs only with that agent’s prompt + tool permissions

  • Benefits:

    • Focus: a long-lived debugging or research workspace without cluttering your main thread

    • Parallel work: keep multiple tabs open (e.g., data-scientist running queries while code-reviewer runs in another)

    • Isolation: huge contexts (like Reddit scraping notes) don’t pollute your main chat

Caveats

  • Separate sessions don’t share state — you’ll need to copy/paste or sync context

  • Each session enforces the agent’s tool list

  • Edits to an agent file require restarting the session

Rule of thumb:

  • Use inline for orchestration and everyday coding

  • Use separate sessions for deep, focused, or long-lived specialist tasks


Best practices

  • Small, focused agents > one giant multi-purpose agent

  • Write prompts as checklists with constraints

  • Restrict tools to enforce safety

  • Version .claude/agents/ in your repo so the team shares agents

  • Prefer explicit invocation for critical workflows


Quick starter pack

mkdir -p .claude/agents

Add these:

Run /agents to verify.


Wrap-up

Sub-agents make Claude Code modular, safer, and smarter. They let your main agent stay conversational and orchestral, while specialists do the heavy lifting exactly when needed.

Start small: add a code-reviewer and a debugger. Once you feel the speedup, extend to data analysis, doc writing, or research — and explore running some inline, some as dedicated sessions.

0
Subscribe to my newsletter

Read articles from rcmisk directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

rcmisk
rcmisk

Lover of coding, software development/engineering, indie hackers podcast/community, start-ups, music, guitar, technology, fitness, running, biking, learning new things, travel, the beach, and hiking/mountains. As a kid I had too many interests. I grew up playing soccer from an early age and played through college! Sports and being a part of a team was always part of my DNA. Not only did I value sports and competition but I loved music, art, drawing, animation, film, computers, math, and learning. Once I hit college, the decision to choose my life path was paralyzing, and ultimately led me down many different paths. I explored economics, finance, psychology, philosophy, statistics, communications, and marketing. I graduated with a finance degree and thought the data science, statistics, and the trends and patterns would be a fun career, however my first entry level job in the industry discouraged me to continue in the industry and to explore other paths. I always had an itch to build and start something on my own or with family. Growing up I started a lawn mowing business, shoveling business, lemonade stands, and small Wordpress websites. I loved the creativity of coming up with ideas on how to help people and make money at the same time. I realized I loved technology, and seeing what could be created and started with technology really urged me to start down the path of learning how to code. My brother and I had an idea for a college social network (similar to Facebook), geared solely towards education and only for students at your college. We wanted to give students the ability to meet people on campus, finding work, organize course material, share notes and materials, find extracurricular activities, sell textbooks and furniture. I took it upon myself to learn how to build something like that. Basically taking an idea and making it happen. I learned about software development, coding languages, web frameworks, startups, marketing all on my own. I took online free courses, watched videos and tutorials about Django, Python, Javascript, HTML, and databases. I absolutely loved everything about the process. Seeing my work come to life and seeing people use what I created. It satisfied everything that I enjoyed growing up. The creativity, the design, artwork, coming up with a business, learning new things at my own pace, however I learned best, and working with my brother. I did all this while working full-time at a financial institution during my nights and weekends. We finally launched StudentGrounds, however after a year and 200 user signups later it slowly died down. This experience of taking an idea and learning everything needed to make it a reality basically propelled my interest in learning how to code and do that full time. I learned all about computer science, taking a certificate course at night at a local university. I started another project idea on the side for an event management application for my father's youth soccer tournament, and started applying to every technology company I could think of. I ultimately got my first software engineer job at a small start up in Boston as an apprentice/intern and learned on the job before getting my first full-time software engineer position at a large Boston e-commerce company. My goal there was to learn as much as I could from season professionals, and learning how the corporate world works in terms of software development. My ultimate goal is to create something on my own doing something I love, as well as enjoy life, and give back to others through education. Right now I am a full-time Software Engineer with 6 years in the marketing tech space, trying to finish a SaaS boilerplate so that I can spin up any web application for any idea at the click of a button, which will then set me up for my next idea, IdeaVerify, an automated way to verify/validate you're SaaS application idea before actually starting to code and wasting many hours and years developing something that no one would use. This blog is about my journey navigating the software engineering world, without a CS degree, building in public, keeping record of what I learned, sharing my learnings and at the same time giving back to others, teaching them how to code and giving helpful hints and insights. I am also using this blog to showcase other sides of me such as art, music, writing, creative endeavors, opinions, tutorials, travel, things I recently learned and anything else that interests me. Hope you enjoy!