✻Founding-member pricing: every lesson for $19/mo. The first 3 lessons are free. Start lesson 1 →
Unit 5 · Subagents & Parallel Work · Lesson 23 of 40

Creating a Custom Subagent

Create a custom Claude Code subagent: the markdown file format, frontmatter fields (tools, model, skills, permissionMode), locations and testing.

ACADEMY11 min+72 XP4-question quiz

🎯 By the end of this lesson you'll be able to

  • Write a subagent definition file
  • Configure tools, model and preloaded skills
  • Choose project vs. user locations
  • Test that delegation works

A subagent is a markdown file

Custom subagents live in .claude/agents/ (project, shared with the team) or ~/.claude/agents/ (personal). Each file has YAML frontmatter plus a markdown body, and the body becomes the subagent's system prompt.

.claude/agents/code-reviewer.md
---
name: code-reviewer
description: Reviews recent code changes for correctness bugs and risky patterns. Use proactively after any significant edit, or when the user asks for a review.
tools: Read, Grep, Glob, Bash
model: sonnet
---

You are a senior code reviewer. Review only the current diff (`git diff main...HEAD`).

Look for, in priority order:
1. Correctness bugs: wrong logic, missing awaits, off-by-one, null handling
2. Security issues: injection, auth gaps, secrets in code
3. Missing tests for new behavior

Do NOT comment on style or naming.

Report format:
- One finding per bullet: `file:line`, the problem, and a concrete fix
- End with "VERDICT: ship" or "VERDICT: fix first"
- If you find nothing, say so plainly. Don't invent issues.

The easiest way to create one? Ask Claude: "create a code-reviewer subagent in .claude/agents that…". Then edit the file yourself.

Frontmatter you'll use

FieldPurpose
name (required)Unique identifier
description (required)When Claude should delegate. Add "use proactively" to encourage it.
toolsAllowed tools. Omit it to inherit everything.
disallowedToolsTools to remove
modelsonnet, opus, haiku, a full model ID, or inherit
skillsSkills whose full content is preloaded into the subagent
permissionModeThe subagent's permission mode
maxTurnsCap on how many turns it can take
memoryGive it a persistent memory folder (project is recommended)
isolation: worktreeRun it in its own git worktree
✓
Cheap, fast helpers

A read-only helper with tools: Read, Grep, Glob and model: haiku is fast and inexpensive, which makes it perfect for lookups and summaries.

Where to save it

LocationScope
.claude/agents/This project. Commit it so the team shares it.
~/.claude/agents/You, across every project
Plugin agents/ folderAnyone who installs the plugin
--agents '<json>' flagJust this session

If two definitions share a name, the project one beats the user one.

Test it

⇅Create and test a subagentdrag or use arrows
  1. ⋮⋮Create .claude/agents/code-reviewer.md with name, description and tools
  2. ⋮⋮Write a focused system prompt with a clear report format
  3. ⋮⋮Make a small change with a deliberate bug
  4. ⋮⋮Ask "review my changes" and confirm Claude delegates to code-reviewer
  5. ⋮⋮Tighten the description or prompt based on what happened
⌨Type the command+15 XP

What do you type to guarantee the code-reviewer subagent handles a request? (Just the mention.)

❯

Check your understanding

?Lesson quiz10 XP per correct answer · +25 for a perfect score
QUESTION 1 OF 4

What becomes a subagent's system prompt?

Why: Everything below the frontmatter is the subagent's system prompt.
QUESTION 2 OF 4

Which two frontmatter fields are required?

Why: Only name and description are required.
QUESTION 3 OF 4

What happens if you omit tools?

Why: Omitting tools means inheriting everything, so restrict when you can.
QUESTION 4 OF 4

Where should a team-shared subagent live?

Why: Project agents in .claude/agents/ travel with the repo.
0 / 4 correct
Academy lesson

Unlock lesson 23 and the next 17

You've finished the free lessons. Join the Academy for $19/month to unlock every lesson, quiz, terminal simulation and puzzle, plus the final exam and your certificate of completion.

  • All 40 lessons across 9 units
  • 165+ quiz questions
  • Final exam + certificate
  • New lessons as Claude Code evolves
  • XP, streaks and badges
  • Cancel anytime

Already a member? Log in to continue.

Key takeaways

  • A subagent is a markdown file: frontmatter + a system-prompt body.
  • name and description are required. Restrict tools when you can.
  • Project agents (.claude/agents/) are shared; user agents (~/.claude/agents/) are personal.
  • Asking Claude to write the first draft is the fastest start.

Nice work. Lesson 23 done?

Mark it complete to earn +72 XP, keep your streak alive and unlock badges.

Written by Curtis Cornell from Anthropic's public Claude Code documentation. Last reviewed November 14, 2026. Claude Code changes fast; if something here differs from your version, the official docs win.

Start lesson 1 free →