Task (also called the Agent tool) for launching autonomous sub-agents, and TodoWrite for maintaining a structured task list within a session.
Task (Agent tool)
Launches a specialized sub-agent to handle a complex task autonomously. The sub-agent runs independently, uses its own set of tools, and returns a single result message when it finishes.Parameters
The full task description for the agent. Since sub-agents start with no knowledge of the parent conversation, the prompt must be self-contained — include relevant file paths, line numbers, context, and any constraints. Terse command-style prompts produce shallow results.
A short (3–5 word) label describing what the agent will do. Shown in the UI.
The type of specialized agent to use (e.g.,
"code-reviewer", "test-runner"). When omitted, the general-purpose agent is used. Available agent types are listed in the system prompt.Optional model override:
"sonnet", "opus", or "haiku". Takes precedence over the agent definition’s configured model. Omit to inherit from the agent definition or parent.When
true, the agent runs in the background. Claude is notified when it completes and should not poll or sleep while waiting. Use background mode when you have genuinely independent work to continue in the meantime.Isolation mode for the agent’s filesystem context:
"worktree"— agent runs in a temporary git worktree (isolated copy of the repo). The worktree is cleaned up automatically if the agent makes no changes; otherwise the path and branch are returned.
Absolute path to use as the working directory for all filesystem and shell operations inside the agent. Mutually exclusive with
isolation: "worktree".A name for the spawned agent. Makes it addressable via
SendMessage({ to: name }) while it is running.How sub-agents work
Each agent invocation starts with zero conversation context. The agent:- Receives its own system prompt and the
promptyou provide - Has access to a tool set defined by its
subagent_type(or all tools for the general-purpose agent) - Runs autonomously until the task is complete
- Returns a single result message back to the parent
When to use the Task tool
- Good use cases
- When NOT to use it
- Open-ended research that requires multiple rounds of searching and reading
- Running a test suite and analyzing failures after code changes
- Independent code review by a fresh agent with no prior context bias
- Long-running operations that can proceed while Claude handles other requests
- Tasks that would generate noisy intermediate output you don’t need in the main context
Parallel agents
When tasks are independent, Claude launches multiple agents in a single message:Resuming agents
To send a follow-up message to a running or completed agent, useSendMessage with the agent’s name as the to field. The agent resumes with its full context preserved.
Writing effective prompts
Brief like a colleague joining mid-task
Brief like a colleague joining mid-task
The agent knows nothing about your session. Treat the prompt like a complete briefing for a smart colleague who just arrived:
- What you’re trying to accomplish and why
- What you’ve already tried or ruled out
- The specific files, functions, or systems involved
- What form the result should take (“report in under 200 words”, “make the fix directly”, etc.)
Lookups vs. investigations
Lookups vs. investigations
- Lookups: hand over the exact command or query. The agent should not need to figure out what to run.
- Investigations: hand over the question, not prescribed steps. Over-specifying steps for open-ended problems causes the agent to waste effort on a wrong path.
TodoWrite
Maintains a structured task list for the current session. Claude uses this tool proactively to track progress, organize multi-step work, and provide visibility into what it is doing.Parameters
The complete, updated todo list. Each call replaces the entire list — there is no incremental add or remove.
TodoItem schema
Each item in thetodos array has the following fields:
The task description in imperative form — what needs to be done. Example:
"Run tests", "Fix authentication bug".The present-continuous form of the task description, shown while the task is in progress. Example:
"Running tests", "Fixing authentication bug".The current state of the task. One of:
Exactly one task should be
| Value | Meaning |
|---|---|
pending | Not yet started |
in_progress | Currently being worked on |
completed | Finished successfully |
in_progress at any time.How Claude uses TodoWrite
Claude callsTodoWrite proactively when:
- A task requires 3 or more distinct steps
- Work is non-trivial and benefits from structured tracking
- The user provides a list of multiple things to do
- New sub-tasks are discovered mid-implementation
TodoWrite for:
- Single-step tasks
- Trivial operations (e.g., adding a comment, running one command)
- Purely informational or conversational responses
Task lifecycle
Starting work
Starting work
Claude marks a task
in_progress before beginning, not after. This ensures the UI reflects what is actively happening.Completing work
Completing work
Claude marks a task
completed immediately when it finishes — it does not batch completions. A task is only marked complete when:- Implementation is fully done
- No tests are failing
- No unresolved errors remain
Handling blockers
Handling blockers
If a task cannot be completed (missing file, failing test, unresolved error), Claude keeps it
in_progress and creates a new pending task describing what needs to be resolved first.Clearing the list
Clearing the list
When all tasks are marked
completed, Claude clears the list automatically. An empty list signals that all requested work is done.