agentleFS
VersoXBTVersoXBT/claude-initial-setup/skills/agent-orchestration/subagent-patterns/SKILL.md

subagent-patterns

Skill4 starsChanged 9 months agoMITView on GitHub

Patterns for when and how to use Claude Code subagents via the Agent tool. Use when the user needs to delegate research, run parallel investigations, protect the main context window, or asks about subagent types like Explore or Plan.

The file

We split this skill into the rules it gives an agent

8 rules. About 0 are common, 8 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈8

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use direct tools (Glob, Grep, Read) when:

    line 30
  2. Distinctive:

    Use Explore when you need to understand how a system works before modifying it.

    line 48
  3. Distinctive:

    All three run in parallel.

    line 105
  4. Distinctive:

    Use subagents as a firewall when reading large codebases:

    line 125
  5. Distinctive:

    Using subagents for simple lookups: If you know the file path, use Read directly.

    line 140
  6. Distinctive:

    Duplicating subagent work: If you delegate research to a subagent, do not also perform the same searches yourself.

    line 141
  7. Distinctive:

    Excessive subagent use: Not every task needs a subagent.

    line 143
  8. Distinctive:

    Ignoring subagent findings: If a subagent reports an issue (security flaw, missing error handling), act on it.

    line 144

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Subagent Patterns

Subagents are independent Claude instances launched via the Agent tool. They run in isolation, protecting the main context window from excessive results while enabling parallel work.

When to Use

  • User needs deep research into a codebase area without polluting main context
  • Multiple independent investigations can run in parallel
  • User asks about the Agent tool or subagent types
  • Task requires exploring unfamiliar code before making changes
  • User wants to delegate a subtask to a focused agent

Core Patterns

When to Use Subagents vs Direct Tools

Use subagents when:

  • The search may require multiple rounds of exploration (3+ queries)
  • Results would be too large for the main context
  • Multiple independent tasks can run in parallel
  • You need focused analysis that should not clutter the conversation

Use direct tools (Glob, Grep, Read) when:

  • You know exactly what file or function to find
  • A single search query will suffice
  • The result is small and immediately actionable

Subagent Types

Explore — For broad codebase exploration and deep research:

Agent tool call:
  subagent_type: "Explore"
  prompt: "Find all authentication middleware in this project.
           Identify where JWT tokens are validated, what claims
           are checked, and how unauthorized requests are handled.
           Report file paths and key function signatures."

Use Explore when you need to understand how a system works before modifying it.

Plan — For generating structured implementation plans:

Agent tool call:
  subagent_type: "Plan"
  prompt: "Create a plan for adding rate limiting to all API endpoints.
           Consider existing middleware, database requirements,
           and configuration needs. Output a step-by-step plan
           with file paths and code changes needed."

General-purpose (default) — For executing focused subtasks:

Agent tool call:
  prompt: "Read the file src/utils/validation.ts and extract
           all exported function signatures with their parameter
           types and return types. Format as a markdown table."

Result Handling

Subagents return their findings as text. Structure your prompts to get actionable output:

Agent tool call:
  prompt: "Analyze src/api/routes/ for error handling patterns.
           For each route file, report:
           1. File path
           2. Whether it uses try/catch
           3. Whether errors are logged
           4. Whether error responses include status codes
           Format as a checklist with pass/fail for each item."

The main agent receives a summary and acts on it — the subagent's full exploration context is discarded, keeping the main window clean.

Parallel Subagent Launches

Launch multiple Agent calls in a single response for independent tasks:

# Call 1 - Agent tool:
  prompt: "Find all database query functions in src/db/ and check
           if they use parameterized queries for SQL injection prevention."

# Call 2 - Agent tool:
  prompt: "List all API endpoints in src/routes/ and check which ones
           have authentication middleware applied."

# Call 3 - Agent tool:
  prompt: "Find all environment variable usages across the codebase
           and verify each has a fallback or validation check."

All three run in parallel. Results arrive independently and can be synthesized by the main agent.

Scoping Subagent Work

Give subagents clear boundaries to prevent unbounded exploration:

# GOOD: Scoped prompt
Agent tool call:
  prompt: "In the directory src/components/forms/, find all form
           components that handle file uploads. Report the component
           name, accepted file types, and max size limits."

# BAD: Unbounded prompt
Agent tool call:
  prompt: "Look at all the components and tell me about them."

Protecting Context Window

Use subagents as a firewall when reading large codebases:

# Instead of reading 20 files directly:
Agent tool call:
  subagent_type: "Explore"
  prompt: "Read all files in src/services/ (there are ~20 files).
           Summarize each service: name, purpose, dependencies,
           and exported functions. Return a concise summary table."

The subagent reads all 20 files in its own context. The main agent receives only the summary.

Anti-Patterns

  • Using subagents for simple lookups: If you know the file path, use Read directly. Launching a subagent to read one file wastes resources.
  • Duplicating subagent work: If you delegate research to a subagent, do not also perform the same searches yourself. Trust the subagent result.
  • Vague prompts: "Look into the auth system" produces unfocused results. Be specific about what information you need and what format to return it in.
  • Excessive subagent use: Not every task needs a subagent. Direct tool calls are faster for simple, directed operations. Only use subagents when the task genuinely benefits from isolation or parallelism.
  • Ignoring subagent findings: If a subagent reports an issue (security flaw, missing error handling), act on it. Do not discard the result.

Quick Reference

ScenarioApproach
Know the exact fileRead directly
Single grep/globGrep/Glob directly
Multi-file explorationSubagent (Explore)
Implementation planningSubagent (Plan)
Parallel investigationsMultiple Agent calls
Large result expectedSubagent (context protection)

Prompt structure: State the scope, what to find, and desired output format. Parallelism: Independent Agent calls in the same response run concurrently. Context protection: Subagent results are summarized; raw exploration stays isolated.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.