Subagent design principles: what we learned building 30+ | Claude Code Toolkit
Deep dives

Subagent design principles: what we learned building 30+

The design rules we settled on after building thirty-plus subagents in production — scope, prompts, tool selection, and the failure modes that shaped every rule.

FA
Fatima A. August 22, 2026 · 14 min read

Every subagent starts the same way. Someone on the team notices a recurring workflow — "I keep asking Claude to do X" — and thinks: this should be a subagent. Ten minutes of prompt writing later, they have one. And then they use it three times, hit an edge case, retire it, and never use it again.

We've built more than thirty subagents at this point. About a third made it into permanent rotation. The other two-thirds died — some quickly, some after weeks of use. This post is what we learned about the difference.

Principle 1: A subagent is a role, not a task

This is the single biggest lesson. Early subagents we built were essentially slash commands in disguise — "generate tests for this file," "refactor this function," "update this README." Task-shaped. All of them died fast because the moment the task shape wasn't a perfect fit, the subagent was worse than just asking Claude directly.

The subagents that stuck were role-shaped. Not "refactor this function" but "you are a refactoring specialist who breaks big changes into small verified steps." Not "generate tests" but "you are a test-writer whose job is to expose bugs, not just cover lines." The role gives the subagent judgment about how to handle unexpected inputs. The task-shaped ones just fail.

The good subagents behave like team members: they have a job description that's specific enough to be useful but general enough to survive contact with real problems.

Principle 2: Scope by outcome, not by tool

Our second-worst pattern was scoping subagents by the tools they had access to. "The GitHub subagent" — access to the GitHub MCP, but no clear job. "The database subagent" — could run queries, but why? These sound reasonable on paper and consistently produced subagents that did nothing well.

The subagents that worked were scoped by outcomes. "The PR reviewer" — outcome: a review comment that surfaces the right issues. Tools follow from what's needed for that outcome. Sometimes that's GitHub, sometimes it's the code, sometimes it's both. But the outcome is the anchor, and it's obvious when the subagent is done.

The test

A well-scoped subagent should be describable to a new team member in one sentence: "This subagent produces X." If you can't say what X is, the scope is wrong.

Principle 3: Explicit inputs and outputs

Subagents that specify what they take in and what they produce are easier to use and easier to compose. Subagents that leave that vague get used inconsistently and produce inconsistent output.

markdown
# incident-investigator

## Purpose
Investigates a production incident by gathering context and forming
a hypothesis. Produces an incident brief for the responder.

## Inputs
- Incident identifier (Sentry event ID or Datadog alert ID)
- Optional: relevant time window (defaults to 1 hour before)
- Optional: suspected service (defaults to auto-detect from error)

## Outputs
- Summary of what happened (2-4 sentences)
- Ranked hypotheses (up to 3, most likely first)
- Suggested next steps (2-5 items, actionable)
- Related PRs merged in the last 24 hours

## Non-goals
- Does NOT auto-remediate. All actions are suggestions for humans.
- Does NOT decide severity. Reports facts; humans triage.

The "non-goals" section is easy to skip and important not to. Being explicit about what the subagent won't do prevents it from drifting into work it shouldn't attempt. Also prevents users from expecting things it doesn't deliver.

Principle 4: One good tool beats three mediocre ones

A common failure mode: giving a subagent access to too many tools. It "might need" the GitHub MCP, the Sentry MCP, the Datadog MCP, and the codebase. Result: a subagent that spends a lot of tokens exploring which tool to use for each step, does none of them especially well, and takes forever.

Better: figure out the core tool that determines whether the subagent works at all. Give it that tool. Add others only if you've verified they meaningfully improve output on real tasks. Most of our best subagents have 1-3 tools, not 8.

Principle 5: Prompt shape matters more than prompt content

The subagents that produced consistent output over months had prompts that were structured the same way. Purpose statement, then role, then constraints, then process, then output format. The content varies; the structure doesn't.

markdown
You are a [role]. Your job is [outcome].

# Constraints
- [things you must always do]
- [things you must never do]

# Process
1. [step 1]
2. [step 2]
3. [step 3]

# Output
[exact format, with example]

Why the structure matters: it gives you a template to iterate on. When the subagent produces bad output, you can identify which section of the prompt was underspecified. When someone else on the team wants to update the subagent, they know where to add their changes. Structure is documentation.

Principle 6: Test on the actual work

The subagents that died fastest were the ones we tested on toy examples and shipped without running against real work. Real work has messier data, longer context, more edge cases. A subagent that handles a clean synthetic PR review probably won't handle a 40-file PR with three days of comments and a merge conflict.

Our rule now: before a subagent gets added to the standard set, someone runs it against 5+ real tasks and shows the output to the team. If most of those runs are useful, ship it. If they're inconsistent, iterate. If they're usually wrong, kill it before it becomes muscle memory.

Failure mode: subagents that fail silently

A subagent that produces bad output but returns "success" is worse than one that fails loudly. Design against this specifically: if the subagent can't reasonably do the job, it should say so.

markdown
# If you cannot produce a useful output, respond with:
# STATUS: unable_to_complete
# REASON: [one sentence]
#
# Do NOT invent an output to satisfy the request.
# Do NOT partial-complete without flagging.

This is the single most underrated part of subagent design. Loud failures let humans catch problems fast. Silent failures create the belief that the subagent works when it doesn't.

Failure mode: prompt bloat over time

A subagent that's been in production for months tends to accumulate patches. "It missed X last week, so we added a bullet about X." Six months later, the prompt is 200 lines of edge-case bullets and the subagent produces worse output than the first version.

Fight this by treating prompt patches as debt. Every time you add a bullet to handle a specific case, add a note about why. Quarterly, review those notes: does this edge case still happen? Was the patch the right fix? Would a cleaner refactor address several bullets at once? Prune ruthlessly. A prompt is code; it deserves the same attention.

Failure mode: subagents that need too much context

Some subagents want you to describe the whole codebase before they can do anything. "Tell me about your architecture, your tech stack, your team's conventions, then I'll write the tests." That's a subagent that's outsourcing the hard part back to you.

Good subagents infer what they can from what they have access to (the files, the tools, the CLAUDE.md) and ask for specific things only when they truly can't proceed. The bar for "please tell me X" should be high — if it can be inferred from a few tool calls, the subagent should make those calls, not ask.

The subagents we retired and why

A few real ones, for reference:

The "everything" agent

An early attempt at a general-purpose coding assistant with access to every tool. It was slower and worse than just asking Claude Code directly. Retired within a week. Lesson: subagents need clearer scope than "help with code."

The "let's discuss" agent

A brainstorming subagent that would explore options with you. Sounded useful; ended up being a worse version of a normal chat. The subagent form factor works best for delegatable work, not for collaborative thinking. Retired after a month.

The over-cautious deploy agent

Designed to enforce every safety check before allowing a deployment step. Ended up blocking so many legitimate deploys that people worked around it. Retired after two months. Lesson: subagents that get in the way get bypassed; the fix is a better set of checks, not a wall.

The three-language linter agent

Tried to run linters across TypeScript, Python, and Go and produce a unified report. Too broad — output was always fine on two languages and confused on one. Retired and split into three per-language versions that each work reliably. Lesson: multi-domain subagents fail more than they help; prefer several specialists.

The subagents that stuck

For contrast — the ones still in daily rotation eight months later:

  • pr-reviewer — reviews a PR and posts specific comments
  • refactor-agent — plans and executes refactors with tests between steps
  • incident-investigator — gathers context and hypothesizes on a production incident
  • docs-agent — cross-references docs against code, flags drift
  • test-backfill — proposes tests for uncovered code, ranked by risk
  • migration-planner — for schema migrations specifically, breaks changes into safe steps

What they all share: role-shaped, outcome-scoped, structured prompts, explicit input/output, small tool count, tested on real work. None of them are technically difficult to build. They're just disciplined, in ways that ten-minutes-of-prompt-writing subagents are not.

Where this goes

Subagent design is still an immature discipline. Six months from now, the principles here will probably need updating — the underlying models get better, the tooling adds new capabilities, and patterns that don't work today might work tomorrow. But the meta-lesson probably survives: subagents are cheap to build and expensive to build well, and the difference shows up in whether they last past their first month.

When your team is about to build its fifth subagent, spend an hour on the design first. It's the difference between a subagent that dies quietly and one your team is still relying on next year.

FA

Written by

Fatima A.

Fatima covers developer experience, tooling architecture, and how MCP-native workflows change day-to-day dev.

Get cctk running in one command

85 slash commands, 12 subagents, 12 MCP integrations, 12 hooks. All the patterns from this post are shipped in cctk.

npx cctk@latest init Get cctk v1.5.2 →