spawn_subagent
Spawn an AI agent with a predefined role to complete a single task, returning a structured verdict. Use for focused work like security audits or test generation without memory between calls.
Instructions
Spawn one AI agent with a predefined role + system prompt and run it to completion on a single task. The agent runs once and returns its verdict; there is no memory between calls. Use when the work fits a clear role (security audit on one module, generate tests for one function, write docs for one API). For multi-agent TDD parallelism with quality gates, use parallel_agents. For multi-backend consensus on a question, use council. Pass file paths and acceptance criteria in task — the agent has no other context. ⚠️ DESTRUCTIVE when write_files:true: code blocks the agent emits are saved into work_directory (auto-created if missing, defaults to /tmp/subagent-<role>-<timestamp>). The default write_files:false is non-destructive — code is returned inline in the response. Returns: {success, role, task, backend_used, response (agent's full output), verdict (structured findings, depth controlled by verdict_mode), files_analyzed (paths the agent read), files_written:[paths] (only when write_files), work_directory, suggested_tools:[follow-up tool names], processing_time_ms, metrics}.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| role | Yes | Subagent role: code-reviewer (quality review), security-auditor (vulnerability detection), planner (task breakdown), refactor-specialist (code improvement), test-generator (test creation), documentation-writer (docs generation), tdd-decomposer (break task into TDD subtasks), tdd-test-writer (RED phase), tdd-implementer (GREEN phase), tdd-quality-reviewer (quality gate) | |
| task | Yes | Task description for the subagent to perform | |
| file_patterns | No | Optional glob patterns for files to analyze (e.g., ["src/**/*.js", "*.test.ts"]) | |
| context | No | Additional context object for the subagent | |
| verdict_mode | No | `summary` returns the agent's key findings + recommended actions only (faster, less for Claude to read). `full` returns the agent's complete structured verdict including reasoning trace. | summary |
| write_files | No | When true, code blocks the agent emits are saved into `work_directory` as separate files. Default false — code is returned inline in the response, which keeps disk state clean but adds tokens. | |
| work_directory | No | Destination directory when `write_files:true`. Auto-created if missing. Defaults to `/tmp/subagent-<role>-<timestamp>`. |