Execute — Orchestrated Task Engine
Decompose a goal into atomic tasks, plan dependencies, select optimal tools, and execute with maximum parallelism.
Pre-Flight Gate
Activation is decided by the frontmatter description alone — this file is read only AFTER the skill
has been selected. Nothing here can prevent over-triggering, so this gate is a post-selection
redirect, not a filter.
Before proceeding, check the ABORT condition below. If it holds, STOP, say in one line that it
fired, and just do the task. Being invoked — including a literal /execute or "orchestrate this"
— does NOT override an ABORT: the phrasing that selected this skill is not evidence the goal is
multi-step.
- Run the 6-phase protocol only when the goal is genuinely multi-step — ≥3 atomic tasks, spans multiple files/tools, or benefits from parallel batches.
- ABORT (do it directly): a single edit, a one-file change, a question, or anything one tool call resolves.
Protocol
Process every /execute invocation through these 6 phases in strict order. Never skip a phase. Gate each phase: do not advance until the current phase is complete.
Phase 1: ANALYZE
Understand the goal before decomposing it.
- Parse
$ARGUMENTS as the goal statement
- Identify the goal type (feature, bugfix, refactor, research, migration, infrastructure, other)
- Explore the codebase to understand current state — use Glob, Grep, Read, or the Explore agent for broad searches
- Check existing skills, memory files, and CLAUDE.md for relevant patterns
- If the goal is ambiguous, use AskUserQuestion to clarify scope — do NOT guess
Gate: Proceed only when the goal, scope, and current state are clearly understood.
Phase 2: DECOMPOSE
Break the goal into small, atomic tasks. Each task must be completable in a single focused action (< 30 minutes of work). If a task feels too large, split it further.
For each task, create it with TaskCreate using this specification:
Subject: <imperative verb phrase — "Add retry logic to Bedrock calls">
Description: |
**Input:** <what this task needs — files, data, outputs from prior tasks>
**Tool:** <specific agent, skill, MCP server, or direct tool — see references/agent-selection.md>
**Steps:**
1. <concrete step>
2. <concrete step>
3. <concrete step>
**Success:** <checkable acceptance criteria — the exact test/command/observable that must pass; Phase 5's independent verifier checks the produced artifact against THIS>
**Output:** <what this task produces — modified files, data, artifacts>
ActiveForm: <present continuous — "Adding retry logic to Bedrock calls">
Decomposition rules:
- One responsibility per task — if a task has "and" in it, split it
- Research tasks are separate from implementation tasks
- Test-writing is a separate task from code-writing
- File creation is separate from file modification
- Each task targets ≤ 3 files
- For monitoring/polling tasks, use CronCreate instead of manual loops
- For risky or experimental tasks, record the isolation mechanism in the Tool: field as the
Agent tool's isolation: "worktree" parameter. Do NOT plan an EnterWorktree step: that tool is explicit-instruction-only and switches the whole session's working directory, so it cannot isolate one task among many
Gate: All tasks created via TaskCreate. Minimum 3 tasks for any non-trivial goal.
Phase 3: PLAN
Establish execution order by setting dependencies and identifying parallel batches.
- For each task, set
addBlockedBy via TaskUpdate to declare which tasks must complete first
- Identify batches — groups of tasks with all dependencies satisfied:
- Batch 1: Tasks with zero dependencies (launch all in parallel)
- Batch 2: Tasks whose dependencies are all in Batch 1
- Batch N: Tasks whose dependencies are all in Batches 1..N-1
- Display the execution plan as a table:
Batch 1 (parallel): #1 Research API docs, #2 Read existing code
Batch 2 (parallel): #3 Implement service [blocked by #1, #2], #4 Write types [blocked by #1]
Batch 3 (sequential): #5 Write tests [blocked by #3], #6 Integration test [blocked by #3, #4]
Batch 4: #7 Review and polish [blocked by #5, #6]
Gate: All dependencies set. Execution plan displayed. No circular dependencies.
Phase 4: EXECUTE
Process batches in order. Within each batch, maximize parallelism.
For each batch:
- Call
TaskUpdate to set all batch tasks to in_progress
- Launch all tasks in the batch simultaneously:
- Agent tasks → use the
Agent tool with the appropriate subagent_type (see references/agent-selection.md)
- Direct tool tasks → use Read, Write, Edit, Grep, Glob, Bash directly
- MCP tasks → use the appropriate MCP server tool
- Web research → use WebSearch, WebFetch
- Skill tasks → invoke via Skill tool
- Collect results from all tasks in the batch
- Mark completed tasks via
TaskUpdate with status: completed
- If a task fails:
- Log the failure in the task description via
TaskUpdate
- Assess: is this recoverable? Create a fix task if yes
- Assess: are downstream tasks blocked? Flag them
- Continue with non-blocked tasks — do NOT stop the entire pipeline
- Proceed to next batch only when ALL tasks in current batch are resolved (completed or failed-and-handled)
Execution rules:
- Send a single message with multiple
Agent tool calls for parallel agent launches
- Agent tasks run in the background by DEFAULT — omit
run_in_background for concurrent launches; writing true is a documented no-op. Pass run_in_background: false only when you must block on a result before continuing
- For direct edits (Write/Edit), execute sequentially if they touch the same file
- Fork subagents — set
subagent_type: "fork" explicitly when a worker needs your conversation context; it shares the prompt cache and is much cheaper. Omitting subagent_type does NOT fork: it starts a general-purpose agent with a fresh context and never errors, so the context you assumed was shared is silently absent. Put what the worker needs in its prompt, or continue an already-spawned agent with SendMessage (which resumes it with its context intact)
- Coordinator synthesis: After research agents complete, READ and SYNTHESIZE all findings before launching implementation agents — never pass raw research output
- For risky/experimental implementation tasks, pass the
Agent tool's own isolation: "worktree" parameter — it gives that agent a temporary git worktree so it works on an isolated copy of the repo. This is a parameter of the Agent launcher, not EnterWorktree: EnterWorktree is explicit-instruction-only, session-scoped, and cannot be entered twice, so it is never the isolation mechanism for a batch
- For long-running monitoring, use CronCreate instead of manual polling loops
- Always read a file before editing it
- After code changes, run relevant tests if a test suite exists
Phase 5: VERIFY
After all batches complete, verify the overall goal with an INDEPENDENT check — not just self-assessment.
- Call
TaskList to confirm all tasks are completed
- For code changes: run the build or test command if applicable
- Independent acceptance check (blocking): spawn ONE isolated verifier sub-agent via
Agent with an explicit subagent_type — NOT a fork (a fork shares this context and would merely re-confirm your own reasoning). Give it ONLY: (a) the original goal + each task's Phase-2 Success: criteria, and (b) the produced diff/artifacts (git diff, new files, command output). It must NOT see your TaskList self-assessment or reasoning. It returns PASS/FAIL per criterion, anchored on objective oracles (build/test output) where one exists.
- For research: verify all questions in the original goal are answered
- If any criterion is FAIL (or build/tests fail): create remediation tasks and loop back to Phase 4. Do NOT advance to Phase 6 REPORT while any acceptance criterion is unmet.
- Run the
code-quality agent on modified files if substantial code was written
Gate: All tasks completed, build/tests pass (if applicable), AND the independent verifier returns PASS on every Phase-2 Success: criterion. Only then proceed to REPORT.
Phase 6: REPORT
Summarize execution results.
## Execution Report
**Goal:** <original goal>
**Tasks:** <completed>/<total> completed
**Batches:** <N> batches, <M> parallel launches
### Completed
- #1 ✓ <subject> — <key output>
- #2 ✓ <subject> — <key output>
### Failed (if any)
- #X ✗ <subject> — <reason>
### Files Modified
- path/to/file.swift — <what changed>
### Next Steps (if any)
- <remaining work or follow-ups>
Agent & Tool Selection
See references/agent-selection.md for the complete selection matrix.
Quick reference:
| Task Type |
Tool/Agent |
| Find files by pattern |
Glob (direct) |
| Search code content |
Grep (direct) |
| Read specific files |
Read (direct) |
| Broad codebase exploration |
Explore agent |
| Architecture/design decisions |
architecture-planner agent + deep-analysis skill |
| Write/modify code |
Write/Edit (direct) or api-backend/frontend-specialist agent |
| Code review |
code-quality agent |
| Write tests |
test-automation agent |
| Database work |
database-architect agent |
| Performance analysis |
performance-optimizer agent |
| Security audit / auth / OWASP |
security-auditor agent (Opus) — the security-scan skill is a scanner, not a substitute |
| Library documentation |
library-docs skill (context7 MCP) |
| Complex reasoning |
deep-analysis skill (sequential-thinking MCP) |
| Web research |
WebSearch + WebFetch |
| GitHub operations |
Bash (gh CLI) or GitHub MCP |
| Git operations |
Bash (git CLI) |
| Build/run commands |
Bash |
| Browser testing |
Playwright MCP |
Error Recovery
When a task fails:
- Transient failure (network, timeout) → retry once
- Validation failure (wrong format, missing input) → fix input, create fix task
- Dependency failure (upstream task produced bad output) → fix upstream first
- Unrecoverable (missing access, unsupported operation) → mark failed, skip dependents, notify user
- Ambiguity discovered (unclear requirements mid-execution) → pause, AskUserQuestion, resume
Never silently skip a failed task. Always log what happened and why.
1---2name: execute3description: Orchestrated task execution engine. Decomposes a large goal into atomic tasks, plans their dependencies, selects an agent, tool, or MCP server per task, runs them in parallel batches, tracks progress, and reports what changed. Warranted only for genuinely multi-step work — roughly three or more atomic tasks spanning multiple files, agents, or tools that benefit from dependency planning and parallelism, such as execute this, orchestrate this, decompose this goal, or build a feature end to end. Because it plans and batches before acting, it is not for a single edit, a one-file change, a question, a lookup, or anything one or two tool calls already resolve — do those directly.4---56# Execute — Orchestrated Task Engine78Decompose a goal into atomic tasks, plan dependencies, select optimal tools, and execute with maximum parallelism.910## Pre-Flight Gate1112Activation is decided by the frontmatter description alone — this file is read only AFTER the skill13has been selected. Nothing here can prevent over-triggering, so this gate is a **post-selection14redirect**, not a filter.1516**Before proceeding, check the ABORT condition below. If it holds, STOP, say in one line that it17fired, and just do the task.** Being invoked — including a literal `/execute` or "orchestrate this"18— does NOT override an ABORT: the phrasing that selected this skill is not evidence the goal is19multi-step.2021- Run the 6-phase protocol only when the goal is genuinely multi-step — ≥3 atomic tasks, spans multiple files/tools, or benefits from parallel batches.22- ABORT (do it directly): a single edit, a one-file change, a question, or anything one tool call resolves.2324## Protocol2526Process every `/execute` invocation through these 6 phases in strict order. Never skip a phase. Gate each phase: do not advance until the current phase is complete.2728### Phase 1: ANALYZE2930Understand the goal before decomposing it.31321. Parse `$ARGUMENTS` as the goal statement332. Identify the goal type (feature, bugfix, refactor, research, migration, infrastructure, other)343. Explore the codebase to understand current state — use Glob, Grep, Read, or the Explore agent for broad searches354. Check existing skills, memory files, and CLAUDE.md for relevant patterns365. If the goal is ambiguous, use AskUserQuestion to clarify scope — do NOT guess3738**Gate:** Proceed only when the goal, scope, and current state are clearly understood.3940### Phase 2: DECOMPOSE4142Break the goal into small, atomic tasks. Each task must be completable in a single focused action (< 30 minutes of work). If a task feels too large, split it further.4344For each task, create it with `TaskCreate` using this specification:4546```47Subject: <imperative verb phrase — "Add retry logic to Bedrock calls">48Description: |49 **Input:** <what this task needs — files, data, outputs from prior tasks>50 **Tool:** <specific agent, skill, MCP server, or direct tool — see references/agent-selection.md>51 **Steps:**52 1. <concrete step>53 2. <concrete step>54 3. <concrete step>55 **Success:** <checkable acceptance criteria — the exact test/command/observable that must pass; Phase 5's independent verifier checks the produced artifact against THIS>56 **Output:** <what this task produces — modified files, data, artifacts>57ActiveForm: <present continuous — "Adding retry logic to Bedrock calls">58```5960**Decomposition rules:**61- One responsibility per task — if a task has "and" in it, split it62- Research tasks are separate from implementation tasks63- Test-writing is a separate task from code-writing64- File creation is separate from file modification65- Each task targets ≤ 3 files66- For monitoring/polling tasks, use CronCreate instead of manual loops67- For risky or experimental tasks, record the isolation mechanism in the **Tool:** field as the `Agent` tool's `isolation: "worktree"` parameter. Do NOT plan an `EnterWorktree` step: that tool is explicit-instruction-only and switches the whole session's working directory, so it cannot isolate one task among many6869**Gate:** All tasks created via TaskCreate. Minimum 3 tasks for any non-trivial goal.7071### Phase 3: PLAN7273Establish execution order by setting dependencies and identifying parallel batches.74751. For each task, set `addBlockedBy` via `TaskUpdate` to declare which tasks must complete first762. Identify **batches** — groups of tasks with all dependencies satisfied:77 - **Batch 1:** Tasks with zero dependencies (launch all in parallel)78 - **Batch 2:** Tasks whose dependencies are all in Batch 179 - **Batch N:** Tasks whose dependencies are all in Batches 1..N-1803. Display the execution plan as a table:8182```83Batch 1 (parallel): #1 Research API docs, #2 Read existing code84Batch 2 (parallel): #3 Implement service [blocked by #1, #2], #4 Write types [blocked by #1]85Batch 3 (sequential): #5 Write tests [blocked by #3], #6 Integration test [blocked by #3, #4]86Batch 4: #7 Review and polish [blocked by #5, #6]87```8889**Gate:** All dependencies set. Execution plan displayed. No circular dependencies.9091### Phase 4: EXECUTE9293Process batches in order. Within each batch, maximize parallelism.9495**For each batch:**96971. Call `TaskUpdate` to set all batch tasks to `in_progress`982. Launch all tasks in the batch simultaneously:99 - **Agent tasks** → use the `Agent` tool with the appropriate `subagent_type` (see references/agent-selection.md)100 - **Direct tool tasks** → use Read, Write, Edit, Grep, Glob, Bash directly101 - **MCP tasks** → use the appropriate MCP server tool102 - **Web research** → use WebSearch, WebFetch103 - **Skill tasks** → invoke via Skill tool1043. Collect results from all tasks in the batch1054. Mark completed tasks via `TaskUpdate` with `status: completed`1065. If a task fails:107 - Log the failure in the task description via `TaskUpdate`108 - Assess: is this recoverable? Create a fix task if yes109 - Assess: are downstream tasks blocked? Flag them110 - Continue with non-blocked tasks — do NOT stop the entire pipeline1116. Proceed to next batch only when ALL tasks in current batch are resolved (completed or failed-and-handled)112113**Execution rules:**114- Send a single message with multiple `Agent` tool calls for parallel agent launches115- Agent tasks run in the background by DEFAULT — omit `run_in_background` for concurrent launches; writing `true` is a documented no-op. Pass `run_in_background: false` only when you must block on a result before continuing116- For direct edits (Write/Edit), execute sequentially if they touch the same file117- **Fork subagents** — set `subagent_type: "fork"` explicitly when a worker needs your conversation context; it shares the prompt cache and is much cheaper. **Omitting `subagent_type` does NOT fork**: it starts a general-purpose agent with a *fresh* context and never errors, so the context you assumed was shared is silently absent. Put what the worker needs in its `prompt`, or continue an already-spawned agent with `SendMessage` (which resumes it with its context intact)118- **Coordinator synthesis**: After research agents complete, READ and SYNTHESIZE all findings before launching implementation agents — never pass raw research output119- For risky/experimental implementation tasks, pass the `Agent` tool's own `isolation: "worktree"` parameter — it gives that agent a temporary git worktree so it works on an isolated copy of the repo. This is a parameter of the `Agent` launcher, **not** `EnterWorktree`: `EnterWorktree` is explicit-instruction-only, session-scoped, and cannot be entered twice, so it is never the isolation mechanism for a batch120- For long-running monitoring, use CronCreate instead of manual polling loops121- Always read a file before editing it122- After code changes, run relevant tests if a test suite exists123124### Phase 5: VERIFY125126After all batches complete, verify the overall goal with an INDEPENDENT check — not just self-assessment.1271281. Call `TaskList` to confirm all tasks are `completed`1292. For code changes: run the build or test command if applicable1303. **Independent acceptance check (blocking):** spawn ONE isolated verifier sub-agent via `Agent` with an explicit `subagent_type` — NOT a fork (a fork shares this context and would merely re-confirm your own reasoning). Give it ONLY: (a) the original goal + each task's Phase-2 `Success:` criteria, and (b) the produced diff/artifacts (`git diff`, new files, command output). It must NOT see your TaskList self-assessment or reasoning. It returns PASS/FAIL per criterion, anchored on objective oracles (build/test output) where one exists.1314. For research: verify all questions in the original goal are answered1325. If any criterion is FAIL (or build/tests fail): create remediation tasks and loop back to Phase 4. Do NOT advance to Phase 6 REPORT while any acceptance criterion is unmet.1336. Run the `code-quality` agent on modified files if substantial code was written134135**Gate:** All tasks completed, build/tests pass (if applicable), AND the independent verifier returns PASS on every Phase-2 `Success:` criterion. Only then proceed to REPORT.136137### Phase 6: REPORT138139Summarize execution results.140141```142## Execution Report143144**Goal:** <original goal>145**Tasks:** <completed>/<total> completed146**Batches:** <N> batches, <M> parallel launches147148### Completed149- #1 ✓ <subject> — <key output>150- #2 ✓ <subject> — <key output>151152### Failed (if any)153- #X ✗ <subject> — <reason>154155### Files Modified156- path/to/file.swift — <what changed>157158### Next Steps (if any)159- <remaining work or follow-ups>160```161162## Agent & Tool Selection163164See [references/agent-selection.md](references/agent-selection.md) for the complete selection matrix.165166**Quick reference:**167| Task Type | Tool/Agent |168|-----------|-----------|169| Find files by pattern | Glob (direct) |170| Search code content | Grep (direct) |171| Read specific files | Read (direct) |172| Broad codebase exploration | Explore agent |173| Architecture/design decisions | architecture-planner agent + deep-analysis skill |174| Write/modify code | Write/Edit (direct) or api-backend/frontend-specialist agent |175| Code review | code-quality agent |176| Write tests | test-automation agent |177| Database work | database-architect agent |178| Performance analysis | performance-optimizer agent |179| Security audit / auth / OWASP | security-auditor agent (Opus) — the security-scan skill is a scanner, not a substitute |180| Library documentation | library-docs skill (context7 MCP) |181| Complex reasoning | deep-analysis skill (sequential-thinking MCP) |182| Web research | WebSearch + WebFetch |183| GitHub operations | Bash (gh CLI) or GitHub MCP |184| Git operations | Bash (git CLI) |185| Build/run commands | Bash |186| Browser testing | Playwright MCP |187188## Error Recovery189190When a task fails:1911921. **Transient failure** (network, timeout) → retry once1932. **Validation failure** (wrong format, missing input) → fix input, create fix task1943. **Dependency failure** (upstream task produced bad output) → fix upstream first1954. **Unrecoverable** (missing access, unsupported operation) → mark failed, skip dependents, notify user1965. **Ambiguity discovered** (unclear requirements mid-execution) → pause, AskUserQuestion, resume197198Never silently skip a failed task. Always log what happened and why.