Skip to content

parallel

parallel - execute multiple tasks concurrently

state-name:
tool: parallel
arguments:
tasks:
- tool: <tool-name>
arguments:
<arg>: <value>
output: <destination> # optional

The parallel tool executes multiple tasks simultaneously, improving workflow performance when tasks are independent. Each task runs in its own thread with isolated output capture.

All tasks start at the same time. The parallel block completes when all tasks finish. If any task fails, the first non-zero exit code is returned after all tasks complete.

ArgumentRequiredDefaultDescription
tasksYes-Array of task definitions

Each task mirrors a state definition:

FieldRequiredDefaultDescription
toolYes-Tool to execute
argumentsYes-Tool arguments
outputNo-Output capture destination
CodeMeaning
0All tasks succeeded
Non-zeroFirst failed task’s exit code

Each task can capture output independently:

gather-data:
tool: parallel
arguments:
tasks:
- tool: bash
arguments:
command: curl https://api1.example.com
output: var(api1)
- tool: bash
arguments:
command: curl https://api2.example.com
output: file(./api2.json)

The parallel tool itself does not produce output for capture.

run-parallel:
tool: parallel
arguments:
tasks:
- tool: bash
arguments:
command: npm run lint
- tool: bash
arguments:
command: npm run typecheck
- tool: bash
arguments:
command: npm test
fetch-all:
tool: parallel
arguments:
tasks:
- tool: bash
arguments:
command: curl -s https://api.example.com/users
output: var(users_json)
- tool: bash
arguments:
command: curl -s https://api.example.com/orders
output: var(orders_json)
- tool: bash
arguments:
command: curl -s https://api.example.com/products
output: file(./data/products.json)
next: process-data
get-perspectives:
tool: parallel
arguments:
tasks:
- tool: claude
arguments:
prompt: "Review this code: {{ file(./src/main.ts) }}"
output: var(claude_review)
- tool: gemini
arguments:
prompt: "Review this code: {{ file(./src/main.ts) }}"
output: var(gemini_review)
next: compare-reviews
parallel-tasks:
tool: parallel
arguments:
tasks:
- tool: bash
arguments:
command: ./task1.sh
output: var(result1)
- tool: bash
arguments:
command: ./task2.sh
output: var(result2)
on-error:
_: handle-failure
next: all-succeeded
handle-failure:
tool: bash
arguments:
command: |
echo "One or more parallel tasks failed"
echo "Task 1 result: {{ result1 }}"
echo "Task 2 result: {{ result2 }}"
run-tests:
tool: parallel
arguments:
tasks:
- tool: bash
arguments:
command: npm test -- --shard=1/4
output: var(shard1)
- tool: bash
arguments:
command: npm test -- --shard=2/4
output: var(shard2)
- tool: bash
arguments:
command: npm test -- --shard=3/4
output: var(shard3)
- tool: bash
arguments:
command: npm test -- --shard=4/4
output: var(shard4)
next: merge-results
process-shards:
tool: parallel
arguments:
tasks:
- tool: sub-flow
arguments:
workflow: process-shard
variables:
shard_id: "1"
- tool: sub-flow
arguments:
workflow: process-shard
variables:
shard_id: "2"
- tool: sub-flow
arguments:
workflow: process-shard
variables:
shard_id: "3"

Interactive tools cannot be used in parallel:

  • claude-code - Requires terminal
  • ask-user - Requires user input

These tools will cause validation errors if included in a parallel block.

  1. All tasks start simultaneously
  2. Each task runs in isolation
  3. Output capture is independent per task
  4. All tasks run to completion (even if one fails)
  5. Exit code is the first non-zero, or 0 if all succeed

Parallel execution can significantly reduce workflow time for independent tasks:

Sequential: Task1 (5s) → Task2 (3s) → Task3 (4s) = 12s total
Parallel: Task1 (5s) + Task2 (3s) + Task3 (4s) = 5s total (limited by slowest)
  • sub-flow - For sequential workflow composition
  • bash - Common tool for parallel tasks