input
{
"url": "https://code.claude.com/docs/en/sub-agents.md",
"prompt": "Show all supported frontmatter fields in agent definitions, the exact allowed values for model and tools, environment variables available to hooks, and confirm all hook event types"
}result
# Agent Definitions Reference
## Supported Frontmatter Fields
All frontmatter fields for agent definitions:
| Field | Required | Type | Description |
|-------|----------|------|-------------|
| `name` | Yes | string | Unique identifier (lowercase letters, hyphens only; no `:` or leading `-`) |
| `description` | Yes | string | When Claude should delegate to this agent |
| `tools` | No | list | Tools the agent can use; inherits all available tools if omitted |
| `disallowedTools` | No | list | Tools to deny, removed from inherited/specified list |
| `model` | No | string | Model to use: `sonnet`, `opus`, `haiku`, `fable`, full model ID, or `inherit` |
| `permissionMode` | No | string | Permission mode: `default`, `acceptEdits`, `auto`, `dontAsk`, `bypassPermissions`, `plan`, or `manual` |
| `maxTurns` | No | number | Maximum agentic turns before stopping (marked partial) |
| `skills` | No | list | Skills to preload into context at startup |
| `mcpServers` | No | list | MCP servers available to this agent |
| `hooks` | No | object | Lifecycle hooks scoped to this agent |
| `memory` | No | string | Persistent memory scope: `user`, `project`, or `local` |
| `background` | No | boolean | Set to `true` to keep agent in background even when Claude requests foreground |
| `effort` | No | string | Effort level: `low`, `medium`, `high`, `xhigh`, `max` (overrides session level) |
| `isolation` | No | string | Set to `worktree` to run in isolated git worktree |
| `color` | No | string | Display color: `red`, `blue`, `green`, `yellow`, `purple`, `orange`, `pink`, `cyan` |
| `initialPrompt` | No | string | Auto-submitted as first turn when agent runs as main session agent |
| `experimental` | No | object | Map of experimental options (e.g., `cacheTtl: "5m"` or `"1h"`) |
## Model Field Values
**Aliases:**
- `sonnet` – Latest Claude Sonnet
- `opus` – Latest Claude Opus
- `haiku` – Latest Claude Haiku
- `fable` – Claude Fable
- `inherit` – Same model as main conversation
**Full model IDs:**
- Any valid full model identifier like `claude-opus-5`, `claude-sonnet-5`
- Same values accepted by `--model` flag
**Model resolution order (for subagents):**
1. Per-invocation `model` parameter
2. Agent definition's `model` frontmatter
3. `CLAUDE_CODE_SUBAGENT_MODEL` environment variable
4. Main conversation's model
## Tools Field Values
### Available Tool Names
**Built-in tools** (subject to permission filters):
- `Read` – File reading
- `Write` – File creation
- `Edit` – File editing
- `Glob` – Pattern matching
- `Grep` – Text search
- `Bash` – Command execution
- `PowerShell` – PowerShell execution
- `WebFetch` – Fetch web content
- `WebSearch` – Search the web
- `Skill` – Invoke skills
- `NotebookEdit` – Edit notebooks
- `TodoWrite` – Manage todos
- `ToolSearch` – Search available tools
- `Monitor` – Monitor processes
- `TaskStop` – Stop tasks
- `SendMessage` – Message other agents
- `EnterWorktree` – Enter git worktree
- `ExitWorktree` – Exit git worktree
- `Artifact` – Create artifacts
**Restricted tools** (removed from all subagents):
- `Agent` – Spawn subagents (has depth limit)
- `AskUserQuestion`
- `EndConversation`
- `EnterPlanMode`
- `ExitPlanMode` (unless `permissionMode: plan`)
- `ScheduleWakeup`
- `TaskOutput`
- `WaitForMcpServers`
- `Workflow`
### Tool Syntax
**Exact tool names:**
```yaml
tools: Read, Grep, Glob, Bash
```
**Agent spawning with allowlist:**
```yaml
tools: Agent(worker, researcher), Read, Bash
```
**MCP server patterns:**
- `mcp__<server>` – All tools from named server
- `mcp__<server>__*` – All tools from named server
- `mcp__*` – All MCP tools (only in `disallowedTools`)
```yaml
disallowedTools: mcp__github, Write
```
### Background Subagent Tool Restrictions
Background subagents keep only these built-in tools (plus all MCP tools):
- `Read`, `Grep`, `Glob`, `Bash`, `PowerShell`, `Edit`, `Write`, `NotebookEdit`
- `WebFetch`, `WebSearch`, `TodoWrite`, `Skill`, `ToolSearch`
- `EnterWorktree`, `ExitWorktree`, `Monitor`, `TaskStop`, `SendMessage`, `Artifact`
## Hook Event Types
### Supported Hook Events
| Event | Matcher Input | When It Fires | Scope |
|-------|---------------|---------------|-------|
| `PreToolUse` | Tool name | Before agent uses a tool | Agent-specific or session-wide |
| `PostToolUse` | Tool name | After agent uses a tool | Agent-specific or session-wide |
| `SubagentStart` | Agent type name | When a subagent begins | Session-wide (settings.json only) |
| `SubagentStop` | Agent type name | When a subagent completes | Session-wide (settings.json only) |
| `Stop` | (none) | When agent finishes | Agent-specific (converted to `SubagentStop` at runtime) |
### Hook Configuration Example
```yaml
---
name: code-reviewer
hooks:
PreToolUse:
- matcher: "Bash"
hooks:
- type: command
command: "./scripts/validate-command.sh"
PostToolUse:
- matcher: "Edit|Write"
hooks:
- type: command
command: "./scripts/run-linter.sh"
---
```
## Environment Variables Available to Hooks
When hooks execute, these variables are available:
**Standard environment:**
- All system environment variables
- `HOME` / `USERPROFILE` – User home directory
- `PWD` – Current working directory
**Claude Code specific:**
- `CLAUDE_SESSION_ID` – Current session identifier
- `CLAUDE_AGENT_ID` – Agent ID (if running in agent context)
- `CLAUDE_AGENT_TYPE` – Agent type name from `name` frontmatter field
**Hook input (via stdin as JSON):**
Hook commands receive structured input via stdin containing:
- `type` – Hook event type
- `tool_name` – Name of tool being used (PreToolUse/PostToolUse)
- `agent_type` – Agent type (SubagentStart/SubagentStop)
- `tool_input` – Complete tool call parameters
### Hook Exit Codes
- `0` – Success; allow operation to proceed
- `1` – Error; block operation and show error to agent
- `2` – Block silently without error message
- Any other code – Treated as error (code 1 behavior)
## Model Resolution Example
```yaml
---
name: fast-researcher
description: Quick research using Haiku
model: haiku
tools: Read, Grep, Glob, WebSearch
---
```
When spawning this agent:
1. If Claude passes `model: sonnet` in the call → uses Sonnet
2. Otherwise if frontmatter has `model: haiku` → uses Haiku
3. Otherwise if `CLAUDE_CODE_SUBAGENT_MODEL=opus` is set → uses Opus
4. Otherwise → uses main conversation's model