--- name: open-dynamic-workflows description: > Write and run dynamic workflows: short JavaScript scripts in Claude Code's workflow dialect, run with the `odw` CLI outside the host agent's context, fanning subtasks out to coding-agent CLIs (Codex, Claude Code, Gemini, Qwen, Kimi, or your own) in a background process and handing back only the final result. Use this skill when a task is bigger than a single call — parallel draft fan-out, multi-stage review pipelines, adversarial verification of findings, or discovery loops that run until nothing new turns up — or when the user mentions odw, dynamic workflows, multi-agent orchestration, or fanning out subagents. license: MIT --- # Open Dynamic Workflows A dynamic workflow is a short JavaScript script: the orchestration plan is ordinary code, executed by `odw` in a detached background process, dispatching each subtask to a real coding-agent CLI process. Intermediate output never enters your context; all that comes back is the script's final `return` value. The flow is always three steps: **write the script → `odw run` → inspect the result, then act**. Don't use this for work that fits in a single call — just do it directly. ## Write the workflow script - The file starts with `export const meta = {…}` — a **pure literal** (no variables, function calls, or template interpolation). `meta.name` and `meta.description` are required; `whenToUse`, `phases`, and `model` are optional. A `phases` entry is `{ title, detail? }` (or just the title); its `adapter` and `model` are the defaults of the phase's agents (**ODW extension** — see [per-phase routing](#per-phase-adapters-model-tiers-and-fallback-chains-odw-extension)). - The body runs in an async context: use top-level `await` directly; the top-level `return` value is the workflow's result. - The primitives are **injected globals** — never import them. Any top-level `import` / `export` other than `export const meta` is rejected by the loader. - Ordinary control flow (loops, `if`, dedup) lives in the script. The primitives only **dispatch and wait**; what to do with results is the script's decision. - To run on Claude Code's Workflow tool as well, keep to the dialect: no ODW extension, and no behaviour the conformance suite marks `unspecified`. Scripts that pass conformance run on both — `odw conformance` runs the suite (`conformance/` in the ODW repository; [primitives](references/primitives.md#odw-conformance)). ```js // fan-out-reduce.js export const meta = { name: 'fan-out-reduce', description: 'Draft in parallel, then synthesize.', phases: [{ title: 'Draft' }, { title: 'Synthesize' }], } const question = (args && args.question) || 'Design a cache.' phase('Draft') const drafts = await parallel( [1, 2, 3].map((i) => () => agent(`Draft #${i}: ${question}`, { phase: 'Draft' })), ) phase('Synthesize') return await agent( 'Synthesize the best answer from:\n' + drafts.filter(Boolean).join('\n---\n'), { phase: 'Synthesize' }, ) ``` Input passed with `--args` is injected as the global `args` (parsed JSON, or a raw string — input that *looks like* JSON but fails to parse is rejected outright, never silently passed through as a string). ## Primitives at a glance | Primitive | What it does | | --- | --- | | `agent(prompt, opts?)` | Run one coding agent on a subtask; returns its reply text, or a validated object when `opts.schema` is set. The only verb that does real work. | | `parallel(thunks)` | Run zero-arg thunks concurrently and **wait for all** (barrier). Order preserved; a failed slot is `null`. `parallel(thunks, { notes: true })` gives its agents the run's notes board (**ODW extension**; below). | | `pipeline(items, ...stages)` | Stream each item through the stages independently (**no barrier**). Each stage receives `(prev, item, index)`. | | `phase(title, opts?)` / `log(msg)` | Label the following work for progress / emit one progress line. `opts` (`{ adapter, model }`, **ODW extension**) gives the phase's agents a CLI and a model. | | `args` | The workflow input (injected). | | `budget` | `{ total, spent(), remaining() }` — scale depth to a token target. | | `workflow(ref, args?)` | Run another workflow inline (one level deep). `ref` is a managed-directory name or `{ scriptPath }`; the child shares this run's concurrency cap, agent counter, and budget. | | `validate(source)` | Parse and compile-check source without running its workflow body; `meta` is parsed as a pure literal, never evaluated. Returns `{ ok, meta?, errors, warnings }`. **ODW extension** — not part of Claude Code's dialect. | | `exec(command, opts?)` | Run a command (tests, a build, a linter) without a model; resolves to `{ stdout, stderr, exitCode, signal, timedOut, truncated, durationMs }`. A string runs through the shell, an array as argv. **ODW extension** — not part of Claude Code's dialect. | | `checkpoint(title, opts?)` | Pause the run until a person approves (perhaps with an edited payload) or rejects; resolves to `{ approved, note, by, payload, edited }`. **ODW extension** — not part of Claude Code's dialect. | `opts` for `agent`: `{ adapter?, schema?, label?, phase?, model?, agentType?, isolation?, keep?, permissions?, expect?, expectRetries?, allowEmpty?, notes?, handoff?, scope?, scopePolicy?, questions?, stallMs?, repo? }`. `stallMs` (Claude Code dialect) is that one agent's stall window in milliseconds (`{ stallMs: 1800000 }` = 30 minutes), in place of the `stallTimeout` setting. `adapter` picks the CLI — or, as a list (`['codex', 'claude']`, **ODW extension**), a fallback chain; `model: '@fast'` picks a tier's model for whichever CLI runs it (**ODW extension**); `schema` is a raw JSON Schema object (an option, not a global); `agentType` names a subagent definition (`.claude/agents/.md`, `.odw/agents/`, `~/.claude/agents/`, `:`) — its body is the persona, its `model`/`tools`/`isolation`/`effort` map per CLI, tools only lower the tier (**ODW extension**; `odw agents types` shows the mapping); with no definition it is a one-line persona, and it is never an adapter name. `keep: true` (**ODW extension**) also commits an isolated agent's change to a branch `odw//-