How to write your first custom subagent in Claude Code

Day 3, 25 minutes · advanced

Goal of this lessonWrite a subagent file with a name, a description and its own instructions, validate it, call it with an @-mention and commit it.

Why it matters

The built-in subagents are general helpers. Ottoline has one check she wants done the same way every time: every price in a draft email must match the price list, and she wants only the mistakes back, with file and line. Typing that brief again for every email gets old fast, and one day she will forget a part of it.

A custom subagent saves the brief once. It is one small Markdown file with a name, a description that tells Claude when to use it, and instructions that become the helper's own system prompt. Today you write price-checker, check that Claude Code picked it up, call it by name and commit it so it lives with the project.

What goes in a subagent file

A subagent is a Markdown file with a header of settings between two --- lines (the frontmatter), followed by the instructions. The subagents page says only two fields are required:

  • name: a unique name, such as price-checker. It may not contain a colon. The file name does not have to match, but keeping them the same makes the folder easy to read.
  • description: when Claude should hand work to this subagent. Claude reads it to decide, so write it as a clear "use when". The page adds that a phrase like "use proactively" makes Claude more likely to delegate on its own.

Everything after the closing --- is the system prompt. The subagent gets this prompt plus basic details such as the working folder, not the full Claude Code system prompt. Write it the way you would brief a new helper: what the job is, which file is the truth, what to report and what never to do.

Optional fields such as tools and model come in lesson 4. Field names must match the page exactly: Claude Code ignores a field it does not recognise, without an error.

Where the file lives

Folder Who can use it
.claude/agents/ in the project everyone who works in this project; commit it to git
~/.claude/agents/ you, in all your projects on this machine

When two subagents share a name, the one from the higher place wins. The order on the page is: managed settings from an organisation, then a subagent passed when Claude Code starts, then the project folder, then your personal folder, then plugins. For Ottoline's studio the project folder is the right place, because the check belongs to the studio, not to her laptop.

How to create it

The page names two ways: ask Claude to write the file, or write it yourself. The /agents command used to open a menu for this; on current versions it only prints a reminder of those two ways.

Claude Code watches both folders. A new or changed file is picked up within a few seconds, with no restart. If Claude still cannot find it, the page says to restart Claude Code.

Claude Code skips a file without telling you in the chat when:

  • the name is missing;
  • the first --- is not the very first line;
  • there is a name but no description;
  • the frontmatter is not valid YAML.

claude plugin validate .claude/agents checks the folder for frontmatter that does not parse. It does not flag a file that parses but has no name, so read the header yourself too.

Three ways to call it

  • By name in your prompt: "Use the price-checker subagent to ..." Claude typically delegates.
  • With an @-mention: type @, pick price-checker (agent) from the list, then type the task. That tells Claude to run this subagent for this one task.
  • Automatically: when your request matches the description, Claude may delegate without being asked.

The transcript then shows a row with the subagent's name and a short task, such as price-checker(Check prices in Wieke reply).

The steps

  1. Start Claude Code in Manual mode in the practice folder.
  2. Ask Claude to create .claude/agents/price-checker.md with a name, a description and short instructions. Approve the write to the protected .claude folder.
  3. Validate the folder with claude plugin validate.
  4. Call the subagent with an @-mention on the draft email and read its report.
  5. Commit the file, so the subagent is part of the project.

Follow the steps for Claude Code below.

Common mistakes

  • A blank line above the first ---. The file then counts as plain documentation and never loads.
  • A description that only says what it is. "Price checker" tells Claude nothing about when to use it. Say when: "Use when a draft email or class note mentions a price."
  • Instructions that ask for everything. A helper told to "check the email" returns an essay. Ask for mismatches only, one line each.

Today's actions

Ticks are not saved without an account

Do it in Claude Code

Claude Code

  1. Start Claude Code in Manual mode in the practice folder.
    cd fenwick-studio
    claude --permission-mode manual
  2. Paste this prompt and press Enter. Claude Code asks before it writes in the protected .claude folder: read the file in the prompt and choose Yes.
    Create .claude/agents/price-checker.md with exactly this content:
    ---
    name: price-checker
    description: Checks prices in Fenwick Pottery Studio emails and class notes against prices.txt. Use when a draft email or class note mentions a price.
    ---
    
    You check prices for Fenwick Pottery Studio. prices.txt is the only source for prices.
    
    1. Read prices.txt.
    2. Find every EUR amount in the files you are given.
    3. Compare each amount with prices.txt.
    4. Report only the mismatches, one line each: file:line, the amount you found, the amount in prices.txt.
    5. If every amount matches, say only: All prices match.
    
    Keep the report under 8 lines. Do not change any file.
  3. Check the folder for frontmatter that does not parse. The ! runs the command in your shell. It should end with Validation passed.
    ! claude plugin validate .claude/agents
  4. Type @ and then price, pick price-checker (agent) from the list, then type the task after it and press Enter.
    check emails/reply-to-wieke.txt
  5. Find the row price-checker(...) in the transcript and wait for the report: one line per wrong price, with file and line.
  6. Ask Claude to commit the file and approve the commit.
    Commit .claude/agents/price-checker.md with the message: Add the price-checker subagent.

Note: If price-checker (agent) is not in the list, check that --- is the very first line of the file and that both name and description are there, then restart Claude Code. /agents only prints a reminder on current versions. Works the same on Windows, macOS and Linux.

Paid planNeeds a paid Claude plan (Pro, Max, Ultra, Team or Enterprise) or a Claude Console account. The free Claude plan does not include Claude Code.

Checked on 4 December 2026 · Source: Claude Code docs: Create custom subagents (opens in a new tab)

Create a free account to save your progress. Sign in or sign up