Task
Launch a new agent to handle complex, multi-step tasks autonomously. Each agent type has specific capabilities and tools available to it.
This matters. Get it right.
Subagents have NO access to conversation history. They only see:
- Their agent-specific system prompt
- The
context string you provide
- The
task string you provide
Use a single Task call with multiple tasks entries when parallelizing. Multiple concurrent Task calls bypass coordination.
For code changes, have subagents write files directly with Edit/Write. Do not ask them to return patches for you to apply.
Agents with output="structured" enforce their own schema; the output parameter is ignored for those agents.
{{#list agents join="\n"}}
{{description}}
{{default (join tools ", ") "All tools"}}
{{/list}}
This matters. Be thorough.
- Plan before acting. Define the goal, acceptance criteria, and scope per task.
- Put shared constraints and decisions in
context; keep each task request short and unambiguous.
- State whether each task is research-only or should modify files.
- Provide an
output schema whenever possible. Do not repeat the schema in context; the agent does not need it there.
- Assign distinct file scopes per task to avoid conflicts.
- Trust the returned data, then verify with tools when correctness matters.
- `agent`: Agent type to use for all tasks
- `context`: Template with `\{{placeholders}}` for multi-task. Each placeholder is filled from task args. `\{{id}}` and `\{{description}}` are always available.
- `isolated`: (optional) Run each task in its own git worktree and return patches; patches are applied only if all apply cleanly.
- `tasks`: Array of `{id, description, args}` - tasks to run in parallel
- `id`: Short CamelCase identifier (max 32 chars, e.g., "SessionStore", "LspRefactor")
- `description`: Short human-readable description of what the task does
- `args`: Object with keys matching `\{{placeholders}}` in context (always include this, even if empty)
- `skills`: (optional) Array of skill names to preload into this task's system prompt. When set, the skills index section is omitted and the full SKILL.md contents are embedded.
- `output`: (optional) JTD schema for structured subagent output (used by the submit_result tool). Do not duplicate this schema in `context`.
Returns task results for each spawned agent:
- Truncated preview of agent output (use `read agent://` for full content if truncated)
- Summary with line/character counts
- For agents with `output` schema: structured JSON accessible via `agent://?q=` or `agent:///`
Results are keyed by task id (e.g., "AuthProvider", "AuthApi").
user: "Looks good, execute the plan"
assistant: I'll execute the refactoring plan.
assistant: Uses the Task tool:
{
"agent": "task",
"context": "Refactoring the auth module into separate concerns.\n\nPlan:\n1. AuthProvider - Extract React context and provider from src/auth/index.tsx\n2. AuthApi - Extract API calls to src/auth/api.ts, use existing fetchJson helper\n3. AuthTypes - Move types to types.ts, re-export from index\n\nConstraints:\n- Preserve all existing exports from src/auth/index.tsx\n- Use project's fetchJson (src/utils/http.ts), don't use raw fetch\n- No new dependencies\n\nTask: \{{step}}\n\nFiles: \{{files}}",
"output": {
"properties": {
"summary": { "type": "string" },
"decisions": { "elements": { "type": "string" } },
"concerns": { "elements": { "type": "string" } }
}
},
"tasks": [
{ "id": "AuthProvider", "description": "Extract React context", "args": { "step": "Execute step 1: Extract AuthProvider and AuthContext", "files": "src/auth/index.tsx" } },
{ "id": "AuthApi", "description": "Extract API layer", "args": { "step": "Execute step 2: Extract API calls to api.ts", "files": "src/auth/api.ts" } },
{ "id": "AuthTypes", "description": "Extract types", "args": { "step": "Execute step 3: Move types to types.ts", "files": "src/auth/types.ts" } }
]
}
- Confirmation bias: ask for factual discovery instead of yes/no exploration prompts
- Reading a specific file path → Use Read tool instead
- Finding files by pattern/name → Use Find tool instead
- Searching for a specific class/function definition → Use Grep tool instead
- Searching code within 2-3 specific files → Use Read tool instead
- Tasks unrelated to the agent descriptions above