Claude Code Dynamic Workflows: From Solo Tasks to Building a Team of Agents
Claude Code's new dynamic workflow feature lets the model generate custom harnesses and coordinate multiple sub‑agents, addressing context limits, laziness, bias and goal drift, while offering six orchestration patterns and practical use‑cases for complex AI tasks.
Dynamic Workflows Overview
Claude Code now supports dynamic workflows , allowing the model to generate, customize, and execute a harness on‑the‑fly. Each workflow runs a JavaScript file that calls a set of special functions to create and coordinate Subagents . Standard JavaScript built‑ins such as JSON, Math, and Array are available for data handling.
Each Subagent can be assigned a specific model and can run inside its own Worktree , which determines compute tier and isolation level. If a workflow is interrupted, it resumes from the last breakpoint without restarting.
Why Dynamic Workflows
The default Claude Code harness uses a single shared context window for planning and execution. This works for many coding tasks but exhibits three failure modes on long‑running, highly structured, or adversarial‑verification tasks:
Agent Laziness – the model stops early and declares completion while only part of the work is done.
Self‑preferential Bias – the model favours its own results, especially when asked to self‑evaluate.
Goal Drift – after many dialogue turns the model’s fidelity to the original goal degrades, amplified by context compression.
Dynamic workflows mitigate these issues by spawning independent Subagents, each with its own context window and isolated goal. Laziness of one Subagent does not affect others; bias can be challenged by a dedicated verifier Subagent; predefined goals at launch limit drift.
Static vs. Dynamic Workflows
Static workflows are pre‑written pipelines that must anticipate every edge case, making them generic but inflexible. Dynamic workflows are generated at runtime by Claude based on the specific task, offering dramatically higher flexibility.
Six Orchestration Modes
Claude typically combines the following patterns when constructing a workflow:
Classify‑and‑act : a classification Subagent determines task type, then routes to appropriate Subagents or actions.
Fan‑out‑and‑synthesize : split a large task into many small steps, run a Subagent for each step, then synchronize results into a single structured output.
Adversarial Verification : for each generating Subagent, launch a separate verifier Subagent to check its output against standards.
Generate‑and‑filter : produce many ideas, then filter, validate, and deduplicate to keep only high‑quality results.
Tournament : multiple Subagents solve the same problem independently; a judging Subagent compares them pairwise to select the best.
Loop‑until‑done : repeatedly launch Subagents until a stopping condition (e.g., no new findings) is met.
These modes are independent yet often combined into composite orchestration schemes.
Concrete Prompt Examples
Typical user prompts that trigger dynamic workflows include:
“这个测试大概50次才失败1次,设一个工作流来复现。提出多个竞猜理论,一个理论被证据推翻才能停。”
“用工作流跑我最近50个会话,挖出我反复做的修正,把反复出现的变成 CLAUDE.md 规则。”
“用工作流翻 Slack #incidents 频道过去6个月的记录,找没人提过工单的反复出现的根因。”
“拿我的商业计划书跑一个工作流,让不同的 Agent 分别从投资人、客户和竞争对手的视角来撕。”
“这里有80份简历,用工作流给后端岗位排序,前10名做二次校验,用 AskUserQuestion 工具面试我,确定评分标准。”
“给这个 CLI 工具起名,用工作流头脑风暴一堆候选,跑锦标赛选出前3。”
“用工作流把 User 模型重命名为 Account,全项目范围替换。”
“用工作流逐条验证我博客草稿里的技术声明,一条都不许错。”
Practical Scenarios
Migration & Refactoring : Rewrite a project (e.g., Bun from Zig to Rust) by breaking the rewrite into steps, assigning each step to a Subagent in its own Worktree, launching an adversarial verifier Subagent for each change, then merging the results.
Deep Research : The built‑in /deep‑research skill uses a fan‑out pattern to search the web, extract sources, perform adversarial verification, and synthesize a cited report. Each stage runs in a clean Subagent context.
Deep Verification : Given a report, spawn a Subagent to identify every factual claim, then launch a dedicated verifier Subagent for each claim; optionally add a second‑level verifier to assess source quality.
Sorting / Ranking : For large datasets (e.g., bug tickets), use a tournament of pairwise comparison Subagents to produce a reliable ranking without exceeding context limits.
Memory & Rule Compliance : Encode recurring rules as separate verification Subagents to ensure consistent enforcement across runs.
Root‑Cause Investigation : Generate multiple independent hypotheses via separate Subagents, then validate each with dedicated verifier Subagents. Applicable to debugging, sales analysis, or data pipeline failures.
Large‑Scale Triage : Classify and de‑duplicate incoming items, route them to automated fix Subagents or human escalation, and isolate high‑privilege actions in separate Worktrees.
Exploration & Tasting : Brainstorm design or naming options, then have a scoring Subagent apply objective criteria; optionally run a tournament to rank the top candidates.
Evaluation : Run lightweight evals in a Worktree, then compare results with a judging Subagent to assess skill performance.
Model & Compute Routing : A classification Subagent decides which model (e.g., Sonnet vs. Opus) to use based on task complexity and required tool calls.
Boundaries & Tips
Dynamic workflows are powerful but can consume large token budgets; assess whether a task truly benefits from multiple Subagents before enabling them.
Prompt quality directly impacts results—use detailed, specific prompts that reference the desired orchestration modes.
For lightweight verification, prepend prompts with “fast workflow” to create a minimal harness.
Combine /goal and /loop to set hard completion criteria and enable periodic execution for repeatable tasks.
Set explicit token budgets in the prompt (e.g., “use up to 10 000 tokens”) to control consumption.
Workflows can be saved with the s key in the workflow menu and are stored under ~/.claude/workflows. They can be shared via skill distribution by placing the JavaScript file in a skill folder and referencing it in SKILL.MD.
Reference: https://claude.com/blog/a-harness-for-every-task-dynamic-workflows-in-claude-code
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.
SuanNi
A community for AI developers that aggregates large-model development services, models, and compute power.
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.
