AI ToolsOctober 21, 2026

How to Create a Subagent in Claude Code (2026)

If you want to know how to create a subagent in claude code, this guide walks you through the whole process in plain language. You will learn the essential background first, then follow clear steps, avoid the mistakes that catch most beginners, and finish with answers to the questions people ask most often. No specialist knowledge is assumed, and every step explains not just what to do but why it matters, so you can adapt the method to your own situation instead of following instructions blindly.

A subagent in Claude Code is a specialised assistant with its own instructions, context window, and tool permissions, which the main agent can delegate focused tasks to. You define one as a markdown file with frontmatter that names it, describes when to use it, and limits its tools.

Understanding How to create a subagent in claude code

Subagents keep the main conversation clean. A code reviewer, test runner, or research helper can churn through lots of material and report back a summary, instead of filling your main session with logs and dead ends.

It also helps to set expectations before you begin. Most people get a good result on their first attempt by working slowly and checking each stage as they go, rather than rushing to the finish. Keep your original files, accounts, or materials safe until the new result is confirmed, and treat your first run as a learning pass: the second time you do this, it will take half as long and feel far more predictable.

What You Need Before You Start

Preparation is the difference between a smooth ten-minute job and a frustrating afternoon. Gather everything the steps below mention before you start: the right device or software, any accounts or files involved, and enough uninterrupted time to finish. Working on a machine with a stable connection and up-to-date software prevents most mid-process failures.

  • Your main tool or device — ready, updated, and signed in where needed.
  • The files, content, or information the task works on, kept in one easy-to-find place.
  • A backup or copy of anything important, so a mistake never becomes a loss.
  • A little patience — a careful first attempt beats two rushed ones.

The built-in /agents interface lists existing subagents and helps create new ones with sensible defaults. Project-level agents live in the project’s agents folder and are shared with the team through version control; user-level agents live in your personal Claude folder and apply to every project.

Multiple terminal windows open on a developer monitor

Step-by-Step: How to create a subagent in claude code

Follow these steps in order the first time you try this. Each one builds on the last, and skipping ahead is the most common reason people have to start over. Once the process feels familiar, you can safely combine or reorder steps to suit your own workflow.

Step 1: Decide the subagent’s single job. Good subagents are specialists: reviewing security, writing tests, or exploring a codebase. Write down the job and its expected output before creating the file.

Step 2: Create the agent file. Use the /agents command in Claude Code to generate a file interactively, or create a markdown file in the project or user agents folder yourself.

Step 3: Fill in the frontmatter. Set a unique name, a description that states when the main agent should delegate to it, and a tools list with only what the job needs.

Step 4: Write the system prompt. In the body, give step-by-step instructions, quality rules, and the exact format for reporting results back to the main agent.

Step 5: Restrict tools deliberately. A reviewer may need read-only tools, while a test fixer needs edit and bash access. Least privilege keeps delegated work predictable.

Step 6: Test it with a real delegation. Ask Claude Code for a task matching the description and confirm the subagent is invoked and returns a useful summary. Tune the description if delegation does not happen.

A whiteboard sketch showing tasks split between team members

How to create a subagent in claude code: Tips That Make It Easier

Ask Claude itself to draft a subagent from a plain description of the job, then edit the result. Include an output contract in the prompt, such as a summary plus file paths changed. Keep a few proven subagents in your user folder so every project benefits.

Another habit worth building is checking your result the way a stranger would. Step away for a few minutes, come back, and look at the outcome with fresh eyes: small problems that were invisible while you were deep in the process become obvious. If the result will be shared, published, or relied on by someone else, this final review is not optional decoration; it is the step that protects your credibility.

A desk setup for reviewing code with notes and a monitor

Common Mistakes to Avoid

Almost every failed attempt at this task traces back to one of a handful of predictable errors. Read this list before your first attempt, and again if something goes wrong, because the fix is usually here.

  • Giving a subagent every tool by default. Unrestricted tools make behaviour harder to predict. Start narrow and add tools when a real task is blocked.
  • Writing a vague description. The main agent delegates based on the description. If it does not state the trigger tasks clearly, the subagent will be ignored.
  • Expecting shared memory with the main agent. A subagent starts with its own context and only sees what it is given. Its instructions and the delegating prompt must contain the needed background.
  • Making one subagent for everything. A general helper duplicates the main agent and gains nothing. Specialisation is the entire point.

If you have already made one of these mistakes, do not panic. In most cases you can return to the last good step, correct the problem, and continue without starting from zero. The exceptions are destructive actions, which is exactly why this guide keeps reminding you to protect originals and backups along the way.

One final piece of advice applies to almost everyone attempting this for the first time: take notes as you go. Write down the settings you chose, the options you tried, and anything that surprised you. Those few lines become your personal shortcut next time, because the details that feel unforgettable today are exactly the ones that fade within a week. Notes also make it far easier to get help from a friend, a community, or a support team, since you can describe precisely what you did and where things stopped working, instead of guessing. Good records turn a one-time fix into repeatable know-how that you actually own.

Frequently Asked Questions

Where are subagent files stored?

Project subagents live in the .claude/agents folder of the project, and personal ones in the agents folder inside your user .claude directory.

Can a subagent create other subagents?

Subagents are designed for focused delegated work in their own context; structure your workflow so the main agent coordinates the delegation.

How does Claude Code choose a subagent?

It matches your request against each subagent’s description. Clear descriptions with example tasks lead to reliable automatic delegation.

Can I call a subagent explicitly?

Yes. Name it in your request, for example asking to use the code reviewer subagent, and Claude Code will delegate to it.

Conclusion

You now know how to create a subagent in claude code from start to finish: the background that makes the steps make sense, the preparation that prevents most failures, and the checks that confirm your result is genuinely good. Work through the steps once, slowly, and keep this guide open beside you; by the second or third time, the process will feel routine. Most importantly, verify your outcome before you rely on it or share it, keep your originals safe, and improve your approach a little each time you repeat the task.

Daniel Carter
Written by Daniel Carter

Daniel tests AI tools for a living. He has reviewed 200+ AI apps and helps readers pick the right tool for their work.

Similar Posts