Lesson 43.2 · 2 of 5 · 6 min read · Reviewed 24 Nov 2026
The Task tool and allowedTools
By the end, you can
- Define a subagent with a description, a prompt and a restricted tool list.
- Explain how the parent agent calls a subagent through the Task tool.
In Claude Code and the Agent SDKClaude Agent SDK: Anthropic’s library for building agents on the same loop that powers Claude Code, with tools, hooks, subagents and MCP., a parent agent starts subagentsSubagent: A separate agent instance, with its own context and instructions, that a main agent delegates a task to. with a tool called Task.
Defining one
In the AgentAgent: A system where a model decides its own next steps, calling tools in a loop until the task is done. SDK, pass agents in the options:
options: {
allowedTools: ['Read', 'Grep', 'Glob', 'Task'], // Task lets the parent delegate
agents: {
'code-reviewer': {
description: 'Reviews a diff for bugs and security issues. Use after code changes.',
prompt: 'You are a careful reviewer. Report issues with file, line and a fix.',
tools: ['Read', 'Grep', 'Glob'], // read-only
},
},
}
In Claude CodeClaude Code: Anthropic’s agentic coding tool that works in your terminal, IDE and CI, reading and editing code and running commands., the same definition lives in a Markdown file in .claude/agents/, with the name, description and tools in its front matter and the prompt as the body.
How the parent picks one
The parent sees each subagent’s description much like a tool description. Say what it does and when to use it. A vague description means the parent never delegates, or delegates the wrong work.
Tools are the guardrail
A subagent can only use its own tool list. Give reviewers and researchers read-only tools. Keep write access for the agent that is accountable for the change.
Key points
- The parent starts subagents through the Task tool; the subagent's description tells the parent when to use it.
- Each subagent can have its own tools list, so a reviewer can be read-only.
- The parent must be allowed to use the Task tool, or it cannot start subagents at all.
Define a read-only reviewer subagent
Create a code-reviewer subagent in Claude Code with read-only tools, and confirm the parent delegates to it and that it cannot edit files.
You will have: A committed .claude/agents/code-reviewer.md file and a short note showing one delegated review and one refused edit.
Steps
- In a test repository, create .claude/agents/code-reviewer.md with front matter for name, a description that says what it does and when to use it, and tools: Read, Grep, Glob.
- Write the body as the reviewer's prompt: report each issue with file, line and a suggested fix.
- Make a small change with an obvious bug, then ask Claude Code to review your recent changes and watch it delegate to code-reviewer.
- Ask the reviewer directly to fix the bug itself and confirm it cannot, because Edit is not in its tools.
- Run /agents to see the subagent listed, and note how its description reads to the parent.
- Optional: define the same reviewer in the Agent SDK options under agents, with Task in the parent's allowed tools.
Done when
- The parent delegates the review to code-reviewer without being told its name.
- The reviewer reports at least the planted bug with a file and line.
- The reviewer has no way to edit files: its tools list is Read, Grep and Glob only.
Docs: Subagents (Claude Code docs) · Agent SDK overview (Claude docs)