Home

Create a Subagent in Claude Code

You want to compare investment opportunities, but researching multiple companies and scoring them takes hours. Think of a subagent like hiring a financial analyst who knows exactly how to use your research tools—you give them company names, and they gather reports, score each company across key metrics, and recommend the best investment. Once you learn to build subagents, you can automate any repetitive multi-step workflow in your work. This tutorial shows you how to build that analyst.

Key Concepts

What You’ll Need

Step 1: Create a Project Folder and Start Claude Code

Windows (WSL):

Mac:

Log in with your Claude subscription following the installation tutorial (Windows Mac). After logging in, you’ll see a welcome message and the Claude Code prompt.

Step 2: Verify the Stock Report Skill Exists

Before building your subagent, confirm the skill is available. Type:

List all available skills

You should see generate-stock-reports in the output. This skill researches companies and generates reports covering product news, management updates, financial performance, and analyst insights.

If you don’t see it, the skill files should be in .claude/skills/generate-stock-reports/ (project level).

Step 3: Understand Subagent vs Skill Architecture

Here’s how subagents and skills work together:

Component Purpose Example
Skill Gathers raw data about one company “Generate report for Apple: products, financials, management, analysts”
Subagent Uses skill data to accomplish a goal “Get reports for Apple and Microsoft, score both, recommend which to invest in”

Key difference:

Your stock-picker subagent will:

  1. Invoke the stock report skill for each company (2+ times)
  2. Score companies across categories (financials, growth, management, sentiment)
  3. Compare scores and recommend the best investment

Step 4: Create the Stock Picker Subagent

Type this command:

/agents

You’ll see the Claude Code agents interface showing existing subagents (if any) and options to Create, Edit, or Delete subagents.

Now create your subagent:

Step 5: Review What You Built (Reflection Checkpoint)

To open the file in VS Code, click File > Open File… and navigate to .claude/agents/stock-picker.md.

Or you can ask Claude to:

Show me the stock-picker subagent file.

Claude will display the subagent file located at .claude/agents/stock-picker.md. You’ll see:

There is a YAML frontmatter at the top:

---
name: stock-picker
description: Compares multiple companies for investment decisions...
skills: generate-stock-reports
---

This frontmatter (the section between --- markers) tells Claude Code when to activate this subagent and which skills it can use.

There is a System prompt below the frontmatter with your scoring methodology.

Confirm these key elements:

You can edit the file directly or ask Claude to update it.

Step 6: Test the Subagent

Now test your subagent with a real comparison. Type:

Which is a better investment: Apple or Google?

The subagent will automatically activate based on your description.

Step 7: Watch the Subagent Work

As the subagent runs, you’ll see it:

  1. Invoke the skill twice - Call the generate-stock-reports skill once for Apple, then for Google
  2. Gather data - Each skill call searches the web and generates a company report
  3. Score companies - Applies the 40/30/20/10 weighting across categories
  4. Generate output - Creates comparison table and recommendation

This may take 2-3 minutes since web research is involved.

Step 8: Review the Output

The subagent returns a detailed analysis including:

The subagent may display this in the terminal or generate a markdown file with the full report. You can edit the subagent file to customize scoring weights or output format.

Next Steps

Now that you have a working stock-picker subagent, try these extensions:

Troubleshooting

Workflow Overview


Created by Steven Ge on December 14, 2025.