Mastering Claude Code Dynamic Workflows: 6 Patterns & 14 Steps Used by Anthropic Engineers
Most Claude Code users still manually chain prompts, yet the newly released dynamic workflow feature—explained through six core patterns and a fourteen‑step roadmap—offers isolated agents, model selection, token budgeting, and reusable skills to replace dozens of prompts with a single automated workflow.
Most Claude Code users still manually chain prompts, copying outputs and repeating corrections; despite dynamic workflows being available for two weeks, about 90% of developers have never tried them.
1. Core Thinking Model
Claude's default framework executes planning and execution in a single context, which works well for most coding tasks but degrades on long‑running, parallel, or adversarial scenarios. Dynamic workflows generate a custom JavaScript execution framework with special functions, creating isolated sub‑agents and handling data flow between them.
2. Failure Modes Solved by Workflows
Anthropic documentation lists three failure modes that appear when a single context is stretched: agent laziness, self‑preference bias, and goal drift. Workflows mitigate these by splitting work into independent contexts, dedicated goals, and isolated agents.
3. Static vs Dynamic Workflows
Static workflows (via Claude Agent SDK or claude -p) are generic and conservative. Dynamic workflows are tailored to the current task, allowing per‑agent model selection (Opus for complex reasoning, Haiku for low‑cost exploration, Sonnet for routine tasks) and context‑aware actions such as reading code or validating against documentation.
4. Core API Functions
The three primitives agent(), parallel(), and pipeline() compose any workflow. parallel() blocks until all sub‑tasks finish; pipeline() streams tasks one after another. Choose parallel when later steps need all results, otherwise pipeline for lower cost.
5. Classification Execution
A classification agent determines task type and routes it to appropriate sub‑agents. Example: explaining an authentication module—simple files are handled by Sonnet, large complex files by Opus.
6. Distribution & Aggregation
Tasks are broken into many tiny sub‑tasks, run in parallel, and their structured results are aggregated. The following code shows assigning each file to a review agent (model “haiku”) via parallel, then merging with an Opus agent.
// Distribute: assign each file to a review agent, block until all finish
const reviews = await parallel(
files.map(file => () => agent(`Review security issues of ${file}`, { model: "haiku", schema: IssueList }))
);
// Aggregate: Opus agent merges all results
const report = await agent(`Merge these review results into a priority report:
${JSON.stringify(reviews)}`, { model: "opus" });7. Adversarial Validation
Separate validation agents, isolated from the producing agents, verify outputs against standards, eliminating self‑preference bias. Use cases include fact‑checking and code review.
8. Generation‑Filter Pattern
Generate multiple solutions, then filter and deduplicate based on criteria, keeping only vetted high‑quality results. Suitable for brainstorming, hypothesis generation, and design proposals.
9. Competition Mode
Multiple agents solve the same task; pairwise comparisons decide the winner, providing more reliable ranking for subjective tasks than absolute scoring.
10. Loop‑Until‑Done
For tasks with unknown workload, loop creation of agents until a /goal condition is met (e.g., no new findings, no errors). Combined with /loop for scheduled execution.
11. Combining Modes for Real Scenarios
Typical workflows combine 2‑4 patterns. Example combos: migration & refactor (distribution → adversarial → loop), deep research (distribution → adversarial → result aggregation), root‑cause analysis, large‑scale triage, creative design, etc.
12. Token Budget & Cost Controls
Dynamic workflows consume more tokens. Use /goal to enforce hard completion, /loop for periodic repeats, and explicit token budgets (e.g., “use 10 000 tokens”) to avoid 5‑10× overruns.
13. Isolation for Untrusted Input
When ingesting public or user‑generated content, isolate agents that read the data from those that perform privileged actions, preventing prompt‑injection risks.
14. Saving & Publishing Workflows
After debugging, press s to save the JavaScript file under ~/.claude/workflows. Reuse locally or package as a skill by placing the file in a skill folder and referencing it in SKILL.md. When published, Claude treats it as a template that can adapt to new tasks.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
AI Architecture Hub
Focused on sharing high-quality AI content and practical implementation, helping people learn with fewer missteps and become stronger through AI.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
