Best Practices for Writing Subagent Descriptions and System Prompts

Published 8 min read

A good subagent has one job, a description that says when to use it, a system prompt that says how to do it, and only the tools it needs. The description decides whether Claude delegates. The system prompt decides how well the subagent works once it starts.

This article is part of our Claude Code subagents guide. It assumes you know the basics from how to create a custom subagent.

The two parts and what each one does

A subagent file is Markdown with YAML frontmatter. The frontmatter configures the agent. The body is its system prompt.

---
name: code-reviewer
description: Reviews code for quality and best practices
tools: Read, Glob, Grep
model: sonnet
---

You are a code reviewer. When invoked, analyze the code and provide
specific, actionable feedback on quality, security, and best practices.

Only name and description are required. The difference between the two text areas matters:

descriptionSystem prompt (body)
Read byThe main Claude, to choose a subagentThe subagent, after it starts
LoadedInto context for every sessionOnly when the subagent runs
JobRoute the right work to this agentTell the agent how to do the work
StyleShort, trigger-focusedAs detailed as the task needs

The docs say it directly: descriptions take up context, so keep them short, and move detail into each subagent's system prompt, "which only loads when that subagent runs."

Writing the description

Claude "uses each subagent's description to decide when to delegate tasks." Treat it as a routing rule.

Say what it does and when to use it

Use two parts: the capability, then the trigger.

WeakStrong
Helps with codeExpert code review specialist. Proactively reviews code for quality, security, and maintainability. Use immediately after writing or modifying code.
Database agentExecute read-only database queries. Use when analyzing data or generating reports.
DebuggingDebugging specialist for errors, test failures, and unexpected behavior. Use proactively when encountering any issues.

The strong examples come from the official docs. Notice the pattern: a role, the work it covers, and a clear "use when" sentence.

Add "use proactively" when you want automatic use

The docs say: "To encourage proactive delegation, include phrases like 'use proactively' in your subagent's description field." Without such a phrase, Claude may wait to be asked. Add it for agents you want to run without a prompt, like a reviewer or a test runner. Leave it out for agents you only want on request.

Make each description different from the others

If two agents both say "reviews code", Claude has no reason to choose either. The docs advise writing descriptions that single out one subagent, so Claude routes to the right one. Name the unique angle: "security review of auth and input handling" versus "style and readability review".

Stay inside the description budget

When the combined descriptions of your non-built-in subagents pass 15,000 tokens, Claude Code shows a warning at startup with the total. It still loads every subagent. A library of 40 agents with long descriptions is the usual cause.

Writing the system prompt

The body is the agent's whole briefing. It starts with a fresh, isolated context window and does not see your conversation history. Write the prompt so a new colleague with no background could follow it.

Use single responsibility

The official best practice is to "design focused subagents: each subagent should excel at one specific task." A reviewer reviews. A debugger fixes bugs. A researcher reads and reports. If you catch yourself writing "and also" in the prompt, split the agent.

Give it a start routine

Tell the agent what to do first. The docs' code reviewer does this:

When invoked:
1. Run git diff to see recent changes
2. Focus on modified files
3. Begin review immediately

A start routine saves the subagent from asking questions it cannot ask or exploring the whole repository.

Add a checklist

A short checklist keeps the quality steady between runs. Examples: "No exposed secrets or API keys", "Proper error handling", "Good test coverage". Keep it to the points that matter for this one job.

Define the output format

Only the subagent's final result returns to the main conversation. Tell it what that result looks like. A format that works for reviews:

Provide feedback organized by priority:
- Critical issues (must fix)
- Warnings (should fix)
- Suggestions (consider improving)

Include specific examples of how to fix issues.

For research agents, ask for sources and file paths with line numbers. For test runners, ask for the failing test names and the root cause, not the full log.

State the limits

Say what the agent must not do, even if the tools allow it. The docs' db-reader example tells the agent: "You cannot modify data. If asked to INSERT, UPDATE, DELETE, or modify schema, explain that you only have read access." The docs also pair that sentence with a PreToolUse hook, because the prompt is a request and the hook is enforcement.

Choose tools and model with the job

Both fields are part of good design. Short rules:

  • Tools: grant only what is needed. The docs' code reviewer uses Read, Grep, Glob, Bash and has no Edit or Write. The docs note it can still change files through Bash, so a prompt rule or a hook is needed if that matters. The debugger adds Edit because fixing bugs requires modifying code.
  • Model: by default a subagent runs on the same model as the conversation that starts it. Set model to sonnet, opus, haiku, fable, a full model ID, or inherit when a job needs something different.

The full rules, including the model resolution order and permission modes, are in subagent tool permissions and model selection.

A reusable template

Copy this into .claude/agents/<role>.md and fill in the brackets.

---
name: [role-name]
description: [What it does in one sentence]. Use [when/trigger]. [Use proactively, if wanted.]
tools: [Only the tools it needs]
model: [sonnet | haiku | opus | inherit]
---

You are a [role] working on [kind of tasks].

When invoked:
1. [First action]
2. [Second action]
3. [Stop condition]

Checklist:
- [Check 1]
- [Check 2]

Report format:
- [Section 1]
- [Section 2]

Do not [limit 1]. If asked to [out-of-scope task], say so and stop.

Test the prompt before you trust it

  1. Call it by name. Say Use the [role-name] subagent on [a real task]. This tests the system prompt alone.
  2. Check the output against your format. If the shape is wrong, fix the prompt, not the task.
  3. Trigger it by description. Ask in plain words, without naming the agent. If Claude does not delegate, rework the description. The troubleshooting checklist covers every failure case.
  4. Check the transcript. A delegation shows as a tool-call row with the subagent name and a short task description.
  5. Edit and retry. Claude Code detects file changes within a few seconds, so a restart is normally not needed.

If your subagents ship as a plugin, claude plugin eval runs each prompt with and without the plugin and scores how reliably Claude delegates.

Keep subagents in version control

Project subagents in .claude/agents/ are "ideal for subagents specific to a codebase." Check them into git so the team can use and improve them together. Personal agents that apply to every project belong in ~/.claude/agents/. When names clash, the project version wins.

Treat prompt changes like code changes: small commits, a message that says what behaviour changed, and a retest by name.

See how your agents behave in practice

Once you have several agents, you want to know which ones actually get used and how long they take. Agent Office shows your agents and skills on a live map and lists recent handoffs with status and token counts. It reads local session data, not message text. Install it with the setup guide. It is optional; the practices above work without it.

Checklist before you ship a subagent

  • [ ] One job, named by role
  • [ ] Description states the capability and the trigger
  • [ ] "Use proactively" only if you want automatic use
  • [ ] Description differs from every other agent's
  • [ ] System prompt has a start routine, checklist and output format
  • [ ] Limits are written down; enforcement uses tools or a hook
  • [ ] tools lists only what is needed
  • [ ] Tested by name and by plain request
  • [ ] Committed to git

Sources

Claude and Claude Code are trademarks of Anthropic. Claud Agency is an independent tool by ECOMHUTSY and is not affiliated with Anthropic.

FAQ

How specific should a subagent description be?

Specific enough that Claude can tell when to use this agent and not a neighbour. State the job and the trigger in one or two sentences, for example "Reviews code for quality and security. Use immediately after writing or modifying code." Put everything else in the system prompt.

Should one subagent do many jobs?

No. The official guidance is to design focused subagents so each one excels at one specific task. Two small agents with clear descriptions route better than one agent that tries to do everything.

How do I limit what a subagent can do?

Use the tools field as an allowlist, or disallowedTools as a denylist. If you omit tools, the subagent inherits the tools available to subagents. Grant only what the job needs.

What should a subagent return?

Only its final result comes back to the parent conversation, so tell the agent exactly what to report: a short summary, a prioritized list, file paths and line numbers. A fixed output format makes the result easy to use.

How do I test a subagent prompt?

Call it by name first ("Use the code-reviewer subagent on this diff") to test the prompt on its own. Then give Claude a normal request that should trigger it and check that the delegation appears in the transcript.

Should I put examples inside the system prompt?

Yes, when the output format matters. A short example of the expected report, kept inside the body, costs tokens only when the subagent runs. Examples in the description are loaded all the time, so keep those out.

How long can a description be?

The docs set a budget for the whole set rather than for one file: the combined descriptions of your non-built-in subagents are budgeted at 15,000 tokens. Past that, Claude Code shows a startup warning. Keep descriptions short and move detail into the system prompt.

Frequently asked questions

How specific should a subagent description be?

Specific enough that Claude can tell when to use this agent and not a neighbour. State the job and the trigger in one or two sentences, for example "Reviews code for quality and security. Use immediately after writing or modifying code." Put everything else in the system prompt.

Should one subagent do many jobs?

No. The official guidance is to design focused subagents so each one excels at one specific task. Two small agents with clear descriptions route better than one agent that tries to do everything.

How do I limit what a subagent can do?

Use the tools field as an allowlist, or disallowedTools as a denylist. If you omit tools, the subagent inherits the tools available to subagents. Grant only what the job needs.

What should a subagent return?

Only its final result comes back to the parent conversation, so tell the agent exactly what to report: a short summary, a prioritized list, file paths and line numbers. A fixed output format makes the result easy to use.

How do I test a subagent prompt?

Call it by name first ("Use the code-reviewer subagent on this diff") to test the prompt on its own. Then give Claude a normal request that should trigger it and check that the delegation appears in the transcript.

Should I put examples inside the system prompt?

Yes, when the output format matters. A short example of the expected report, kept inside the body, costs tokens only when the subagent runs. Examples in the description are loaded all the time, so keep those out.

How long can a description be?

The docs set a budget for the whole set rather than for one file: the combined descriptions of your non-built-in subagents are budgeted at 15,000 tokens. Past that, Claude Code shows a startup warning. Keep descriptions short and move detail into the system prompt.