# Plan-then-act with explicit sub-task scaffolding — Claude XML example

> Two-turn pattern: first turn produces a numbered plan; second turn executes each sub-task and returns structured results.
>
> Source: https://claudexml.com/examples/plan-then-act/ · Last updated 2026-05-25

Home / Examples / Plan-then-act with explicit sub-task scaffolding
    Complex · advanced

# Plan-then-act with explicit sub-task scaffolding

    Two-turn pattern: first turn produces a numbered plan; second turn executes each sub-task and returns structured results.

    Tasks that decompose into several independent sub-tasks (research, writing, analysis pipelines). Separating plan from execution makes the work auditable and parallelizable.


## The prompt

    Copy this verbatim. Replace the `{{ … }}` placeholders with your values.


```xml
<!-- TURN 1 (plan) -->
<instructions>
You will receive a complex task. Decompose it into 3–7 sub-tasks. Return JSON inside <plan> tags:

{
  "summary": "one-sentence restatement of the goal",
  "subtasks": [
    { "id": "S1", "title": "string", "depends_on": [], "deliverable": "string" }
  ]
}

Rules:
- Each subtask must have a single, concrete deliverable (an artifact, a list, a number).
- depends_on references other subtask IDs that must complete first; empty list means parallelizable.
- Do not execute any subtask in this turn. Plan only.
</instructions>

<task>{{ task_description }}</task>

Return inside <plan> tags.

<!-- TURN 2 (execute) — re-injects the plan as context -->
<instructions>
The plan from turn 1 is in <plan>. Execute every subtask whose dependencies are satisfied
by what's already in <results>. For each, append a new <result> tag:

<result subtask_id="S1">
  ... your output for this subtask ...
</result>

After processing all currently-executable subtasks, output <status>done</status> if every
subtask in the plan now has a <result>, or <status>continue</status> if more turns are needed.
</instructions>

<plan>{{ plan_from_turn_1 }}</plan>

<results>
{{ results_from_prior_turns }}
</results>
```


## Sample input


```xml
Task: Produce a Q3 board update for our SaaS startup covering financials, product, hiring, and risks.
```


## Expected output


```xml
<plan>
{
  "summary": "Produce a Q3 board update with financials, product, hiring, and risks sections.",
  "subtasks": [
    {"id": "S1", "title": "Financials section", "depends_on": [], "deliverable": "MRR, ARR, burn, runway with QoQ deltas"},
    {"id": "S2", "title": "Product highlights", "depends_on": [], "deliverable": "3 shipped features with adoption metrics"},
    {"id": "S3", "title": "Hiring update", "depends_on": [], "deliverable": "headcount delta + open roles"},
    {"id": "S4", "title": "Risks & asks", "depends_on": ["S1","S2","S3"], "deliverable": "3 risks + 1 specific board ask"},
    {"id": "S5", "title": "Executive summary", "depends_on": ["S1","S2","S3","S4"], "deliverable": "150-word TL;DR"}
  ]
}
</plan>

[Turn 2 then executes S1, S2, S3 in parallel; turn 3 executes S4; turn 4 executes S5.]
```


## Notes & tuning tips


- The dependency graph lets you parallelize: any subtask whose `depends_on` is empty (or all-completed) can run concurrently.
- Force structured plans — free-prose plans don't drive execution reliably.
- Hard-cap turns (max 4–5) and treat continue with no progress as a stop signal.
- For agent-style execution where each subtask may need tools, combine with the API's tool use feature.


## What this example uses

    Tags: <instructions> <format>

    Patterns: agentic tool use structured output


## More like this


      complex
### Map-reduce summarization over many chunks
Summarize each chunk independently, then synthesize a single coherent summary — two prompts, structured handoff.

      complex
### Generate → self-critique → revise in one call
Three-stage prompt where Claude drafts, scores its own draft against a rubric, then revises.

      complex
### Tree-of-thought reasoning with branch scoring
Explore three reasoning paths, score each against criteria, pick the winner — all in one prompt.

      complex
### Extract → validate → transform pipeline in one call
Four-stage data pipeline: extract raw fields, validate against rules, transform to target shape, emit errors.




Cite this page

`Plan-then-act with explicit sub-task scaffolding. claudexml.com. https://claudexml.com/examples/plan-then-act/`
