Claude Code can now write and orchestrate its own multi-agent harness on the fly. Here's how dynamic workflows work, and the patterns that get the most out of them.
Claude Code can now write and orchestrate its own multi-agent harness on the fly. Here's how dynamic workflows work, and the patterns that get the most out of them.
Last week, we released dynamic workflows in Claude Code. Claude can now write its own harness on the fly, custom-built for the task at hand.上周,我们在Claude Code中发布了动态工作流。Claude现在可以即时编写自己的定制化工具,专为手头任务量身打造。
While the default Claude Code harness is built for coding, it is also useful for many other types of tasks because, as it turns out, many tasks resemble coding tasks. But there are certain classes of tasks where we have had to build custom harnesses on top of Claude Code to achieve peak performance such as Research, security analysis, agent teams, or Code Review.虽然默认的Claude Code工具是为编码设计的,但它也适用于许多其他类型的任务,因为事实证明,许多任务与编码任务相似。但有一类任务,我们不得不在Claude Code之上构建自定义工具以达到最佳性能,例如研究、安全分析、代理团队或代码审查。
Workflows allow you to dynamically create harnesses built on top of Claude Code that enable Claude to solve all of those problems more natively. You can also share and reuse these workflows with others.工作流允许你动态创建基于Claude Code的工具,使Claude能够更原生地解决所有这些问题。你还可以与他人共享和重用这些工作流。
In this article, I’ll cover my initial workflows experiences and learnings so you can best take full advantage. Keep in mind, best practices are still developing: dynamic workflows often use more tokens and are best suited for complex, high value tasks.在本文中,我将介绍我最初的工作流经验和学习心得,以便你能够充分利用。请记住,最佳实践仍在发展中:动态工作流通常使用更多令牌,最适合复杂、高价值的任务。
Before diving into the technical details, I’d like to start with several example prompts to get you thinking about the possibilities with workflows:在深入技术细节之前,我想先提供几个示例提示,让你思考工作流的可能性:
"This test fails maybe 1 in 50 runs. Set up a workflow to reproduce it. Form competing theories about the race, and don't stop until one theory survives the evidence." “这个测试大约每50次运行失败1次。设置一个工作流来重现它。形成关于竞态条件的竞争性理论,直到一个理论在证据中胜出为止。”
"Using a workflow, go through my last 50 sessions and mine them for corrections I keep making and turn the recurring ones into CLAUDE.md rules"“使用工作流,浏览我最近的50个会话,挖掘我反复犯的错误,并将重复出现的错误转化为CLAUDE.md规则。”
“Use a workflow to dig through #incidents in Slack for the past six months and find recurring root causes where nobody has filed a ticket." “使用工作流,挖掘Slack中过去六个月的#incidents频道,找出没有人提交工单的重复根本原因。”
"Take my business plan and run a workflow where different agents tear it apart from an investor's, a customer's, and a competitor's perspective." “拿我的商业计划书,运行一个工作流,让不同的代理从投资者、客户和竞争对手的角度将其拆解。”
"Here's a folder of 80 resumes, use a workflow to rank them for the backend role and double-check the top ten. Interview me using the AskUserQuestion tool for a rubric."“这里有80份简历的文件夹,使用工作流为后端职位排序,并仔细检查前十名。使用AskUserQuestion工具对我进行面试,制定评分标准。”
"I need a name for this CLI tool. Use a workflow to brainstorm a bunch of options and run a tournament to pick the top 3." “我需要为这个CLI工具起个名字。使用工作流 brainstorm 一堆选项,然后运行一个锦标赛选出前三名。”
"Use a workflow to rename our User model to Account everywhere." “使用工作流,将我们的User模型在所有地方重命名为Account。”
“Go through my blog post draft and verify every technical claim against the codebase using a workflow, I don't want to ship anything wrong."“使用工作流,检查我的博客文章草稿,验证每一个技术声明是否与代码库一致,我不想发布任何错误信息。”
Dynamic workflows execute a javascript file with a few special functions that help spawn and coordinate subagents:动态工作流执行一个JavaScript文件,其中包含一些特殊函数,用于生成和协调子代理:

Dynamic workflows also include standard JavaScript functions like JSON, Math, and Array, to help process data.动态工作流还包括标准JavaScript函数,如JSON、Math和Array,以帮助处理数据。
It’s particularly useful to know that dynamic workflows can decide which models an agent uses and whether subagents are run in their own worktree, allowing Claude to choose the intelligence level and isolation needed.特别有用的是,动态工作流可以决定代理使用哪些模型,以及子代理是否在自己的工作树中运行,从而让Claude选择所需的智能级别和隔离程度。
If a workflow is interrupted, for example by user action or quitting the terminal, resuming the session will allow the workflow to pick up where it left off.如果工作流被中断,例如由于用户操作或退出终端,恢复会话将允许工作流从中断处继续。
When you ask the default Claude Code harness to do a task, it needs to both plan and execute in the same context window. For many coding tasks, this is highly effective, but it can break down over long-running, massively parallel, highly structured and/or adversarial tasks.当你要求默认的Claude Code工具执行任务时,它需要在同一个上下文窗口中同时进行规划和执行。对于许多编码任务,这非常有效,但对于长时间运行、大规模并行、高度结构化和/或对抗性任务,它可能会失效。
This is because the longer Claude works on a complex task in a single context window, the more it becomes susceptible to a few specific failure modes:这是因为Claude在单个上下文窗口中处理复杂任务的时间越长,就越容易受到几种特定故障模式的影响:
Creating a workflow helps combat these by orchestrating separate Claude subagents with their own context windows and focused, isolated goals.创建工作流有助于对抗这些问题,通过编排具有各自上下文窗口和专注、隔离目标的独立Claude子代理。
You may have previously created a static workflow using the Claude Agent SDK or claude -p to coordinate multiple instances of Claude Code together. 你可能之前使用Claude Agent SDK或claude -p创建过静态工作流,以协调多个Claude Code实例。
But because static workflows need to work for all edge cases, they are usually more generic. With Claude Opus 4.8 and dynamic workflows, Claude is now intelligent enough to write a custom harness tailor-made for your use case.但由于静态工作流需要适用于所有边缘情况,它们通常更通用。借助Claude Opus 4.8和动态工作流,Claude现在足够智能,可以为你的用例编写定制化的工具。

You can start using dynamic workflows just by asking Claude to make one, or by using the trigger word “ultracode” to ensure that Claude Code creates a workflow. 你可以通过要求Claude创建一个工作流来开始使用动态工作流,或者使用触发词“ultracode”来确保Claude Code创建一个工作流。
But building a mental model for how dynamic workflows work will help you understand when to use them and how you might nudge Claude via prompts.但建立对动态工作流工作原理的心智模型将帮助你理解何时使用它们,以及如何通过提示引导Claude。
There are a few common patterns that Claude might use and compose together when building workflows:Claude在构建工作流时可能会使用和组合几种常见模式:

Use a classifier agent to decide on the type of task, and then route to different agents or behavior based on the task. Or, use a classifier at the end to determine output.使用分类器代理决定任务类型,然后根据任务路由到不同的代理或行为。或者,在最后使用分类器确定输出。
Split up a task into many smaller steps, run an agent on each step and then synthesize those results. This is particularly useful for when there are a large number of smaller steps, or when each step benefits from its own clean context window so they don't interfere or cross-contaminate. The synthesize step is a barrier—it waits for all the fan-out agents, then merges their structured outputs into one result.将任务分解为许多小步骤,在每个步骤上运行一个代理,然后综合这些结果。当有大量小步骤,或者每个步骤受益于自己干净的上下文窗口以避免干扰或交叉污染时,这特别有用。综合步骤是一个屏障——它等待所有扇出代理,然后将它们的结构化输出合并为一个结果。
For each spawned agent, run a separate spawned agent to adversarially verify its output against a rubric or criteria. 对于每个生成的代理,运行一个单独的生成代理,根据评分标准或标准对其输出进行对抗性验证。
Generate a number of ideas on a topic and then filter them by a rubric or by verification, dedupe duplicates and return only the highest quality, tested ideas.生成关于某个主题的多个想法,然后通过评分标准或验证进行过滤,去重,只返回最高质量、经过测试的想法。
Instead of dividing the work, have agents compete on it. Spawn N agents that each attempt the same task using different approaches. Prompts or models then judge the results in a pairwise fashion using a judging agent until you have a winner.不是分工,而是让代理竞争。生成N个代理,每个代理使用不同的方法尝试相同的任务。然后使用评判代理以成对方式评判结果,直到产生胜者。
For tasks with an unknown amount of work, loop spawning agents until a stop condition is met (no new findings, or no more errors in the logs) instead of a fixed number of passes.对于工作量未知的任务,循环生成代理,直到满足停止条件(没有新发现,或日志中没有更多错误),而不是固定次数的通过。
Think creatively of when and how to ask Claude Code to make dynamic workflows. I’ve found that workflows are sometimes even more useful for non-technical work.创造性地思考何时以及如何要求Claude Code创建动态工作流。我发现工作流有时对非技术工作甚至更有用。
Bun was rewritten from Zig to Rust using workflows. You can read more about how that was done in Jarred’s X thread. Bun使用工作流从Zig重写为Rust。你可以在Jarred的X线程中阅读更多关于如何完成的信息。
The key is to break down the task into a series of steps that need to be operated on for example callsites, failing tests, modules, etc. Spin off a subagent for every fix in a worktree to make the fix, then have another agent adversarially review, and merge them. Consider telling the agent not to use resource intensive commands so that you can maximally parallelize without running out of resources on your machine.关键是将任务分解为一系列需要操作的步骤,例如调用点、失败的测试、模块等。为每个修复在工作树中生成一个子代理进行修复,然后让另一个代理进行对抗性审查并合并。考虑告诉代理不要使用资源密集型命令,以便在最大化并行化的同时避免机器资源耗尽。
We published a deep research skill (/deep-research) inside Claude Code that uses dynamic workflows. Specifically, it fans-out web searches, fetches sources, adversarially verifies their claims, and synthesizes a cited report.我们在Claude Code中发布了一个深度研究技能(/deep-research),它使用动态工作流。具体来说,它扇出网络搜索、获取来源、对抗性验证其声明,并综合出一份带引用的报告。
But you may do this sort of research for more than just web searches. For example, asking Claude to compile a status report from context in Slack or to research how a feature works by exploring a codebase in-depth.但你可能不仅仅为网络搜索进行这种研究。例如,要求Claude从Slack中的上下文编译状态报告,或通过深入探索代码库来研究某个功能的工作原理。

On the other hand, if you have a report where you want to check and source every factual claim that it references you may want to generate a workflow which has one agent identify all of the factual claims and then spin off a subagent to check each one in-detail. You could also have a verification agent check the source subagent to make sure its source is high quality. 另一方面,如果你有一份报告,想要检查并溯源其中引用的每个事实声明,你可能希望生成一个工作流,其中一个代理识别所有事实声明,然后生成一个子代理详细检查每个声明。你还可以有一个验证代理检查来源子代理,确保其来源质量高。

You may have a list of items that you want to sort by some qualitative measurement that you believe that Claude Code is good at evaluating, for example: support tickets sorted by severity of the bug. But if you try to sort 1000+ rows in one prompt, quality degrades and it won't fit in context. Instead run a tournament, a pipeline of pairwise-comparison agents (comparative judgment is more reliable than absolute scoring), or bucket-rank in parallel then merge. Each comparison is its own agent, so the deterministic loop holds the bracket and only the running order stays in context.你可能有一个项目列表,希望根据某种定性度量进行排序,你认为Claude Code擅长评估,例如:按错误严重性排序的支持工单。但如果你尝试在一个提示中对1000多行进行排序,质量会下降,并且无法放入上下文。相反,运行一个锦标赛、一个成对比较代理的管道(比较判断比绝对评分更可靠),或并行分桶排序然后合并。每个比较都是自己的代理,因此确定性循环保存括号,只有运行顺序保留在上下文中。

If you have a particular set of rules that you find Claude misses or struggles with, even when put into the CLAUDE.mds, create a workflow with a list of rules that must be checked by verifier agents—one verifier per rule. Creating a skeptic persona subagent to review the rules to make sure they are in line will help avoid too many false positives.如果你有一组特定的规则,发现Claude即使放在CLAUDE.md中也会遗漏或难以遵守,创建一个工作流,其中包含必须由验证代理检查的规则列表——每个规则一个验证代理。创建一个怀疑论者角色子代理来审查规则,确保它们符合要求,这将有助于避免过多的误报。
The reverse direction works too: mine your recent sessions and code review comments for corrections you keep making, cluster them with parallel agents, adversarially verify each candidate (would this rule have prevented a real mistake?), and then distill the survivors back into a CLAUDE.md.反向方向也有效:挖掘你最近的会话和代码审查评论,找出你反复犯的错误,用并行代理进行聚类,对抗性验证每个候选规则(这条规则本可以防止一个真正的错误吗?),然后将幸存者提炼回CLAUDE.md。
Debugging works best when you come up with several independent hypotheses and test them, but if you’re only using one context window, Claude can run into self-preferential bias调试的最佳方式是提出几个独立的假设并测试它们,但如果你只使用一个上下文窗口,Claude可能会遇到自我偏好偏差。
A workflow can structurally prevent this by spinning up agents to generate hypotheses from disjoint evidence. For example, separate agents for logs, files, and data. Each hypothesis can then face a panel of verifiers and refuters.工作流可以通过从不相交的证据中生成假设的代理来从结构上防止这种情况。例如,为日志、文件和数据的代理分开。每个假设然后可以面对一组验证者和反驳者。
This isn't just for code. Workflows can be used for sales (why did sales drop in March?), data engineering (why did this pipeline fail?), or any post-mortem exercise.这不仅适用于代码。工作流可用于销售(为什么三月份销售额下降?)、数据工程(为什么这个管道失败?)或任何事后分析练习。

Every team has a support queue, bug reports, or some other backlog that cannot be fully processed by humans. 每个团队都有支持队列、错误报告或其他无法完全由人类处理的积压工作。
A triage workflow classifies each item, dedupes against what's already tracked, and takes action. This could mean attempting the fix or escalating to a human user.分类工作流对每个项目进行分类,与已跟踪的项目去重,并采取行动。这可能意味着尝试修复或升级到人类用户。
A useful pattern for triage workflows is quarantine. This involves barring the agents that read untrusted public content from taking high-privilege actions, which are instead done by the agents in charge of acting on the information.分类工作流的一个有用模式是隔离。这涉及禁止读取不受信任的公共内容的代理采取高权限操作,这些操作由负责处理信息的代理执行。
Pair triage workflows with /loop to have Claude do this continuously.将分类工作流与/loop配对,让Claude持续执行此操作。
Workflows can be useful when exploring different approaches to a solution, especially when it is taste based, like design or naming, and would benefit from a rubric.工作流在探索不同解决方案时很有用,尤其是当基于品味时,如设计或命名,并且受益于评分标准。
Try asking Claude to explore a bunch of solutions, and give a review agent a rubric for what a good solution looks like. The task is complete when the review agent feels like it has met the criteria. Solutions can also be ordered or selected via a tournament based on the rubric.尝试要求Claude探索一系列解决方案,并为审查代理提供一个评分标准,说明好的解决方案是什么样的。当审查代理认为满足标准时,任务完成。解决方案也可以通过基于评分标准的锦标赛进行排序或选择。
You can run lightweight evals for particular tasks by spinning off separate agents in a worktree and then spinning off comparison agents to compare and grade the specific outputs against a rubric. For example, evaluating and then refining a skill you’ve created against a particular criteria.你可以通过在工作树中生成单独的代理,然后生成比较代理来比较和评分特定输出与评分标准,从而为特定任务运行轻量级评估。例如,评估然后根据特定标准完善你创建的技能。
Create a classifier agent tuned to your tasks that decides which model to use. This can be helpful when your task will involve many tool calls and conducting research prior to execution can identify the best model for the job. 创建一个针对你的任务调整的分类器代理,决定使用哪个模型。当你的任务涉及许多工具调用,并且在执行之前进行研究可以确定最适合工作的模型时,这很有帮助。
For example, the best model for the task “explain how the auth module works” depends on how many files in the auth module there are and the shape of the codebase. A classifier agent can do this research and then route to Sonnet or Opus based on the expected complexity of the task.例如,对于任务“解释auth模块如何工作”,最佳模型取决于auth模块中的文件数量和代码库的形状。分类器代理可以进行这项研究,然后根据任务的预期复杂度路由到Sonnet或Opus。
Workflows are new. While there are many use cases where it will create outsized results, they are not needed for every task and may end up using significantly more tokens.工作流是新的。虽然有许多用例会产生超常的结果,但并非每个任务都需要它们,并且它们可能会使用显著更多的令牌。
It’s best to use workflows creatively to push Claude Code in ways that you haven’t previously. For regular coding tasks, try and ask yourself: does it really need more compute? For example, most traditional coding tasks do not need a panel of 5 reviewers.最好创造性地使用工作流,以你以前没有的方式推动Claude Code。对于常规编码任务,尝试问自己:它真的需要更多计算吗?例如,大多数传统编码任务不需要5个审查员的评审团。
Detailed prompting, using the specific techniques we described above, for dynamic workflows creates the best results.使用我们上面描述的特定技术进行详细提示,可以为动态工作流创造最佳结果。
Workflows are not just for large tasks. You can prompt the model to use a “quick workflow.” For example, you can create a quick adversarial review of an assumption.工作流不仅适用于大型任务。你可以提示模型使用“快速工作流”。例如,你可以创建一个对假设的快速对抗性审查。
/goal and /loop结合/goal和/loopWhen using workflows that can be repeated, for example triage, research, or verification, pair them with /loop to be run at regular intervals, and /goal to set a hard completion requirement.当使用可以重复的工作流时,例如分类、研究或验证,将它们与/loop配对以定期运行,并与/goal配对以设置硬性完成要求。
You can set explicit token usage budgets for dynamic workflows to limit how many tokens a task uses. You can prompt it with a budget like: “use 10k tokens,” which will set the cap.你可以为动态工作流设置明确的令牌使用预算,以限制任务使用的令牌数量。你可以用预算提示它,例如:“使用10k令牌”,这将设置上限。
You can save workflows by pressing “s” in the workflow menu. You can check these into ~/.claude/workflows or distribute them via a skill. 你可以通过在工作流菜单中按“s”来保存工作流。你可以将这些文件检入~/.claude/workflows或通过技能分发。

To share them via a skill, put your JavaScript workflow files in the skill and folder and reference them in the SKILL.MD. To allow for more flexibility, you may want to prompt Claude to think of the workflows in the skill as a template instead of a script that needs to be run verbatim.要通过技能共享它们,将你的JavaScript工作流文件放入技能文件夹,并在SKILL.MD中引用它们。为了提供更多灵活性,你可能希望提示Claude将技能中的工作流视为模板,而不是需要逐字运行的脚本。

Workflows are a helpful new way to extend Claude Code. I encourage you to think of them as a starting point to explore new ways to use Claude to help accomplish your tasks. There is still much to discover in how to use them best. Let me know what you find. 工作流是扩展Claude Code的一种有用的新方式。我鼓励你将它们视为探索使用Claude帮助完成任务的新方法的起点。关于如何最好地使用它们,还有很多有待发现。请告诉我你的发现。
This article was written by Thariq Shihipar and Sid Bidasaria, members of technical staff at Anthropic working on Claude Code. 本文由Thariq Shihipar和Sid Bidasaria撰写,他们是Anthropic的技术人员,致力于Claude Code的工作。
Get the developer newsletter
Product updates, how-tos, community spotlights, and more. Delivered monthly to your inbox.