Skip to content

Step-by-step: build a subagent (Claude Code & Cursor)

Each step has a Goal, what to Do, and how to Verify it. Track your progress with the agents checklist.

Running example: a code-reviewer subagent that reviews the current diff against team standards and returns prioritised findings, without editing anything.

To skip copying a template, use the Subagent builder. It asks for the fields this guide requires and writes a <name>.md you can copy or download. Save it in .claude/agents/ (both hosts) or .cursor/agents/ (Cursor only), then come back to these steps for location, testing, and shipping.


  • Goal: A clear contract covering what the subagent receives, does, and returns.
  • Do:
    1. Write the job in one sentence: “Review the current uncommitted diff for bugs, security issues, and standards violations; return findings grouped Critical / Warning / Suggestion with file:line references.”
    2. Define the input: what the parent must pass (the diff scope, the standards file, the focus).
    3. Define the output: its exact shape and maximum length. The parent pays for every token that comes back.
    4. Define done: when the subagent stops.
    5. Collect 3–5 real tasks you’d delegate to it.
  • Verify: Someone else could do the job from your contract alone.
  • Goal: Delegate only where isolation pays off.
  • Do: Use a subagent if at least one of these is true:
    • It reads a lot but returns a little (search, review, research).
    • It can run in parallel with other work.
    • It needs different permissions (read-only) or a different model.
    • It benefits from an independent perspective (verification).
  • Verify: You can name the specific isolation benefit. If you can’t, and it’s just a procedure, use a skill instead.
  • Goal: Least privilege and the right cost.

  • Do:

    Decision Claude Code Cursor
    Read-only tools: Read, Grep, Glob (an allowlist: the subagent has only these), or disallowedTools: Edit, Write. If you add Bash, limit what it does in the prompt, and enforce that with hooks if it matters readonly: true
    Can edit Include Edit, Write in tools readonly: false (the default)
    MCP tools Include them by name in tools, omit tools to inherit all, or declare the subagent’s own servers with mcpServers Inherited automatically
    Model model: sonnet / opus / haiku / fable / a full model ID / inherit model: inherit or a model ID
    Background (non-blocking) background: true (Claude Code runs subagents in the background by default) is_background: true
  • Rules of thumb: reviewers, researchers, and explorers are read-only. Use a fast, cheap model for search, and a strong model for review or architecture.

  • Verify: It can’t do anything its job doesn’t need.

Step 4: Write the description (the routing rule)

Section titled “Step 4: Write the description (the routing rule)”
  • Goal: The parent delegates at the right moments.

  • Do:

    description: >-
    Expert code reviewer. Use proactively immediately after writing or
    modifying code, or when the user asks for a review of a diff, PR, or branch.
    Reviews for correctness, security, and team standards; read-only.
    • Say when, and include “use proactively” if you want automatic delegation.
    • Say what it won’t do if there’s a sibling agent it could be confused with.
  • Verify: Read the descriptions of all your subagents side by side. None of them overlap.

  • Goal: A focused, self-sufficient brief. Remember that the subagent can’t see the parent’s chat.
  • Do: Use this structure (see the template):
    1. Role: one line.
    2. When invoked: the first actions to take (for example “run git diff, read changed files”).
    3. Process / checklist: what to check, in priority order.
    4. Constraints: what never to do.
    5. Output format: an exact template with a length limit.
    6. Stop condition: when to return.
  • Verify: The prompt makes sense to someone who has no idea what the parent was doing.
  • Goal: The host detects the subagent.
  • Do:
    1. Choose a location from the platform matrix:
      • Both hosts, this repo: .claude/agents/code-reviewer.md
      • Cursor only: .cursor/agents/code-reviewer.md
      • Just you: ~/.claude/agents/ or ~/.cursor/agents/
    2. Start from code-reviewer.md (cross-platform) or cursor-verifier.md (Cursor-specific fields). Download the template from the templates page, or copy it from the template page (each file has a copy button). Or fill in the Subagent builder and download a .md file that already follows this guide.
    3. Alternatively, ask Claude Code to create the subagent for you, or use /create-subagent in Cursor (at the time of writing; check Cursor’s docs). Then edit the file. In Claude Code, /agents no longer creates or lists subagents.
  • Verify: In Claude Code, type @ and check that @agent-code-reviewer appears in the typeahead. In Cursor, check that it’s listed in the Subagents section.
  • Goal: It’s used when it should be, and not otherwise.
  • Do:
    1. Explicit: @agent-code-reviewer review my changes in Claude Code, or /code-reviewer in Cursor. Confirm it runs. A plain-language request (“use the code-reviewer subagent”) doesn’t guarantee delegation in Claude Code, so use the @agent- form for this test.
    2. Automatic: make a code change, then ask “is this ready to commit?” Does the parent delegate?
    3. Negative: ask an unrelated question. It should not delegate.
  • Verify: The results are recorded in your eval sheet (template).
  • Goal: Correct, well-shaped results.
  • Do:
    1. Seed a diff with known issues (a hard-coded secret, an off-by-one, and a missing null check).
    2. Delegate a review. Did it find each one? Were there false positives?
    3. Check the output against your template: length, grouping, and file:line references.
    4. Check that the constraints held. For a read-only agent, confirm no files changed (git status).
  • Verify: It catches the seeded issues, the format is exact, and there were no forbidden actions.
  • Goal: Fix observed failures, not imagined ones.

  • Do:

    Symptom Fix
    Never delegated automatically Add “use proactively” plus concrete trigger situations to the description
    Delegated too often Narrow the description; say when not to use it
    Returns an essay Tighten the output template; add a hard length limit
    Misses context Tell it which files to read first, or make the parent pass more in the task
    Does forbidden things Restrict tools / disallowedTools / readonly; add a hook for hard enforcement
    Slow or expensive Use a cheaper model; narrow the scope
  • Verify: Re-run Steps 7–8. All the checks pass.

  • Goal: The team uses it.
  • Do: Commit it to .claude/agents/ (so both hosts pick it up) or package it in a plugin. Document it in the README with example invocations, and log it in DECISIONS.md.
  • Verify: A colleague’s session delegates to it without being told how.

Next: Build an SDK agent · Design patterns · Checklist