agentleFS
sefaertuncsefaertunc/anthropic-watch/.claude/skills/subagent-usage/SKILL.md

subagent-usage

Skill1 starsChanged 7 months agoMITView on GitHub

When to use subagents, how many, context hygiene, worktree isolation patterns

1 other project uses a version of this, 1 of them edited.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

14 rules. About 0 are common, 12 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈12

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Read 10 test files to understand patterns (consumes context)

    line 43
  2. Distinctive:

    Write new tests (uses that context)

    line 44
  3. Distinctive:

    Parallel: when tasks are independent.

    line 57
  4. Distinctive:

    Run test-writer and code-simplifier on different parts of the code simultaneously

    line 59
  5. Distinctive:

    Run build-validator while continuing implementation

    line 60
  6. Distinctive:

    Sequential: when tasks depend on each other.

    line 62
  7. Distinctive:

    Run code-simplifier first, then test-writer on the simplified code

    line 64
  8. Distinctive:

    Run security-reviewer first, then fix the issues it found

    line 65
  9. Distinctive:

    Don't spawn more than 2-3 parallel subagents.

    line 67
  10. Very specific:

    Run worclaude doctor to diagnose.

    line 91
  11. Distinctive:

    If the agent breaks something, it's isolated

    line 101
  12. Very specific:

    Test all three scenarios: fresh (no .claude/), existing (.claude/ but no meta), upgrade (meta exists).

    line 115
  13. Distinctive:

    Don't use subagents for tasks that require judgment about the overall session direction.

    line 125
  14. Distinctive:

    If a subagent fails, don't automatically retry.

    line 129

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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 Usage

What Subagents Are

Subagents are separate Claude instances spawned from your main session. They have their own context window, execute independently, and return results to the main session. Your main context stays clean.

When Subagents Help

Tasks that benefit from subagents:

  • Testing: writing tests for code you just implemented (test-writer agent)
  • Code review: reviewing your own changes for quality (code-simplifier agent)
  • Research: reading many files to answer a specific question
  • Parallel work: running verification while you continue designing
  • Build validation: checking that everything compiles and passes (build-validator)
  • File generation: creating boilerplate, configs, or template files

The common thread: these tasks require context (reading files, understanding code) but that context doesn't need to persist in your main session.

When NOT to Use Subagents

  • Tasks requiring back-and-forth with the user (subagents can't interact with users)
  • Tasks where the result needs deep integration with your current reasoning
  • Very small tasks (the overhead of spawning isn't worth it)
  • Tasks that depend on conversation history the subagent doesn't have

Context Hygiene

Your main session has limited context. Every file you read, every long output you generate, consumes context. Subagents let you offload this:

Instead of:

  1. Read 10 test files to understand patterns (consumes context)
  2. Write new tests (uses that context)
  3. Continue main work (context is now polluted with test details)

Do:

  1. Spawn test-writer subagent with: "write tests for src/merger.js following patterns in tests/core/"
  2. Continue main work while subagent works
  3. Subagent returns: "wrote 3 test files, all passing"
  4. Main context stays clean

Parallel vs Sequential Subagents

Parallel: when tasks are independent.

  • Run test-writer and code-simplifier on different parts of the code simultaneously
  • Run build-validator while continuing implementation

Sequential: when tasks depend on each other.

  • Run code-simplifier first, then test-writer on the simplified code
  • Run security-reviewer first, then fix the issues it found

Don't spawn more than 2-3 parallel subagents. Each consumes resources and coordination overhead grows.

Worktree Isolation

Some agents use git worktree to make changes without affecting your working tree:

How it works:

  1. Agent creates a worktree based on origin/HEAD (see gotcha below)
  2. Makes changes in the worktree (isolated from your files)
  3. Commits changes
  4. You merge or cherry-pick the results

Agents with worktree isolation: code-simplifier, test-writer, verify-app, ci-fixer, bug-fixer, refactorer, doc-writer.

Base-branch gotcha

Both claude --worktree and the Agent isolation: "worktree" option create the worktree from origin/HEAD, not your current branch. If your working branch is ahead of whatever origin/HEAD points to (typically origin/main), the worktree will miss those commits.

Run worclaude doctor to diagnose. Fix locally with git remote set-head origin <your-branch> (reversible via --auto or main). The bundled bug-fixer, verify-app, and test-writer agents include a freshness preamble that resets their worktree to match the parent's current branch automatically; other worktree agents do not.

Benefits:

  • Agent's changes don't conflict with your uncommitted work
  • You can review agent changes before merging
  • If the agent breaks something, it's isolated

Giving Subagents Good Instructions

Subagents start with zero context. They don't know what you've been doing. Give them:

  1. The specific task: "Write unit tests for the merge function in src/core/merger.js"
  2. Where to look: "Follow patterns from tests/core/detector.test.js"
  3. Constraints: "Use Vitest, not Jest. Mock fs-extra, not the actual filesystem."
  4. Success criteria: "All tests should pass. Cover happy path, error cases, and the three-way merge edge case."

Bad instruction: "Write some tests" Good instruction: "Write unit tests for detectScenario() in src/core/detector.js. Test all three scenarios: fresh (no .claude/), existing (.claude/ but no meta), upgrade (meta exists). Mock the filesystem. Use Vitest."

Gotchas

  • Subagents don't see your uncommitted changes unless they share the same working directory. If you need them to see your changes, commit first or use the same worktree.
  • Subagent output is returned to your context. If a subagent generates a huge report, that report consumes your context. Ask for concise results.
  • Don't use subagents for tasks that require judgment about the overall session direction. They lack the conversational context to make those calls.
  • Worktree-based agents need a clean git state to create the worktree. Commit or stash before spawning them.
  • If a subagent fails, don't automatically retry. Understand why it failed first. The same instructions will produce the same failure.

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.