Clipping X

A harness for every task dynamic workflows in Claude Code 为每项任务量身定制:Claude Code 中的动态工作流

by @trq212 原文 ↗ 原载于 2026-06-03
Created: 2026-07-06

图像

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 that enable Claude to solve all of those problems and more natively inside of Claude Code. You can also share and re-use these workflows with others. 工作流功能让你能够动态创建专属框架,使Claude无需借助外部工具即可在Code内部原生解决上述所有问题。你还能与他人共享并复用这些工作流。

In this article, I’ll cover my initial workflows experiences and learnings so you can take full advantage. 本文中,我将分享初期使用工作流的经验与心得,助你充分发挥其潜力。

That said, best practices are still developing! Dynamic workflows often use more tokens, so think carefully about when and how to use them. Note: this post is also available on the Claude Blog话虽如此,最佳实践仍在发展中!动态工作流通常消耗更多令牌,因此需要谨慎考虑何时以及如何使用它们。说明:本文亦发布于 Claude 博客

Example prompts 示例提示

Before diving into the technical details, I’d like to start with some 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 theories and adversarially test them in worktrees /goal don’t stop until one theory works.” “这个测试大约每 50 次运行会失败 1 次。请建立一个工作流来复现问题,提出理论并在工作树中进行对抗性测试 /goal 在找到一个可行理论之前不要停止。”
  • “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工具起个名字。使用工作流来集思广益,想出一堆选项,然后通过锦标赛选出前3个。”
  • “Use a workflow to rename our User model to Account everywhere.” “使用工作流将我们所有的User模型重命名为Account。”
  • “Go through my blog post draft and using a workflow verify every technical claim against the codebase, I don’t want to ship anything wrong.” “浏览我的博客草稿,利用工作流对照代码库验证每一条技术声明,我不想发布任何有误的内容。”

How dynamic workflows work 动态工作流的工作原理

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. 如果工作流被中断(例如用户操作或关闭终端),恢复会话后工作流将从中断处继续执行。

Why dynamic workflows 为什么需要动态工作流

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 sometimes break down over long-running, massively parallel and/or highly structured 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 在单个上下文窗口中对复杂任务处理的时间越长,就越容易陷入以下几种特定的失效模式:

  • Agentic laziness refers to when Claude stops before finishing a particularly complex, multi-part task and declares the job done after partial progress, for example addressing 20 of the 50 items in a security review.“代理式惰性”指的是 Claude 在完成一项特别复杂的多部分任务之前就停止工作,并在取得部分进展(例如在安全审查中处理了 50 个项目中的 20 个)后宣布任务完成。
  • Self-preferential bias refers to Claude’s tendency to prefer its own results or findings, especially when asked to verify or judge them against a rubric.自我偏好偏差是指Claude倾向于偏好自身的结果或发现,尤其是在被要求根据评分标准验证或评判这些结果时。
  • Goal drift refers to the gradual loss of fidelity to the original objective across many turns, especially after compaction. Each summarization step is lossy, and details like edge-case requirements or “don’t do X” constraints can get lost.目标漂移是指随着多轮交互(尤其在压缩后)逐渐偏离原始目标的现象。每次摘要步骤都会有信息损失,诸如边界案例要求或”不要做X”等约束细节可能会丢失。

Creating a workflow helps combat these by orchestrating separate Claudes with their own context windows and focused, isolated goals. 创建工作流有助于应对这些问题,通过编排具有独立上下文窗口和明确隔离目标的多个Claude实例来实现。

Dynamic vs static workflows 动态工作流与静态工作流

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现在足够智能,能够为你量身定制符合具体需求的自定义工具框架。

图像

Helpful patterns when using dynamic workflows 使用动态工作流时的实用模式

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在构建工作流时,通常会采用并组合以下几种常见模式:

图像

Classify-and-act 分类-执行模式

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. 利用分类代理判断任务类型,根据任务差异分流至不同代理或行为处理;或在流程末尾使用分类代理确定输出结果。

Fan-out-and-synthesize 分派与综合

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. 将一个任务拆解为许多更小的步骤,为每个步骤运行一个代理,然后综合这些结果。当存在大量较小步骤,或每个步骤受益于其独立的清晰上下文窗口以避免相互干扰或交叉污染时,这种方法尤为有用。综合步骤是一个屏障——它会等待所有分派代理完成,然后将它们的结构化输出合并为一个结果。

Adversarial verification 对抗性验证

For each spawned agent, run a separate spawned agent to adversarially verify its output against a rubric or criteria. 对于每个生成的代理,运行一个独立的生成代理,根据评估标准或准则对其输出进行对抗性验证。

Generate-and-filter 生成与筛选

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. 围绕某个主题生成多个想法,然后根据标准或验证结果进行筛选,去除重复项,最后仅保留质量最高且经过检验的想法。

Tournament 锦标赛式

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 个智能体,各自采用不同方法尝试完成同一任务。随后,通过提示词或模型调用评审智能体,对结果进行两两比较,最终决出胜者。

Loop until done 循环直到完成

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. 对于工作量未知的任务,采用循环生成代理的方式直到满足停止条件(未发现新内容,或日志中不再出现错误),而非固定的循环次数。

Use cases 应用场景

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创建动态工作流程。我发现工作流程有时甚至在非技术性工作中更有用。

图像

Migrations and refactors 迁移与重构

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. 关键在于将任务分解为一系列需要处理的步骤,例如调用点、失败测试、模块等。在工作树中为每个修复操作派生子代理,由另一代理进行对抗性审查,然后合并。建议指示代理避免使用资源密集型命令,以便在最大限度并行执行的同时避免本地资源耗尽。

Deep research 深度研究

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 的上下文信息中汇编状态报告,或通过深度探索代码库来研究某个功能的工作原理。

Deep verification 深度验证

图像

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. 另一方面,如果你需要核查报告中每一个事实性引用的出处,可以生成这样一个工作流:由一个智能体识别所有事实主张,再派生出子智能体逐一进行详细核查。你还可以设置验证智能体对采集信息的子智能体进行复核,以确保其信息来源的高质量。

Sorting 排序

图像

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多行数据进行排序,质量会下降,且无法容纳在上下文中。相反,可以运行一个锦标赛(torunament)、一组两两比较的智能体流水线(比较判断比绝对评分更可靠),或者并行进行桶排序后再合并。每次比较都由独立的智能体负责,因此确定性循环只保留对阵表,而运行顺序始终保持在上下文中。

Memory and rule adherence 记忆与规则遵循

图像

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 文件中。

Root-cause investigation 根因调查

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. 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. 调试时,提出多个独立假设并进行验证效果最佳。但如果只用一个上下文窗口,Claude 可能会陷入自我偏好偏差。 工作流能从结构上防止这种情况——通过启动智能体,从互不重叠的证据中生成假设。例如,分别针对日志、文件和数据的独立智能体。每个假设随后需要面对验证者和反驳者组成的小组评审。

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. 这不仅适用于代码。工作流还可用于销售(三月份销量为何下滑?)、数据工程(这条流水线为何失败?)或任何事后复盘场景。

Triaging at scale 大规模分类处理

图像

Every team has a support queue, bug reports, or some other backlog that cannot be fully processed by humans. 每个团队都有客服工单、Bug报告或其他无法由人工完全处理的积压任务。

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 持续执行此操作。

Exploration and taste 探索与品味

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 探索多种方案,并为评审代理提供评分标准,说明什么是好的解决方案。当评审代理认为已达到标准时,任务即完成。也可以根据评分标准,通过锦标赛方式对方案进行排序或筛选。

Evals 评估

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. 你可以通过在工作树中启动独立的代理来为特定任务运行轻量级评估,然后再启动比较代理,根据评估标准对特定输出进行对比和评分。例如,根据特定标准对你创建的技能进行评估,然后进行优化。

Model and intelligence routing 模型与智能路由

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. 例如,在执行“解释认证模块工作原理”这一任务时,最佳模型的选择取决于认证模块包含的文件数量以及代码库的结构。一个分类代理可以完成这项调研,然后根据任务的预期复杂度将请求路由至 Sonnet 或 Opus。

When not to use dynamic workflows 何时不使用动态工作流

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. 工作流是新事物。虽然它在许多场景下能带来卓越成效,但并非每个任务都需要使用,而且可能显著增加 Token 消耗量。

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名评审者组成的评审团。

Tips for building dynamic workflows 构建动态工作流的技巧

Prompting 提示工程

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. 工作流并非仅适用于大型任务。您可以引导模型使用”快速工作流”。例如,您可以快速对某个假设进行对抗性审查。

Combine with /goal and /loop 结合使用 /goal 和 /loop

When 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 设定严格的完成条件。

Token usage budgets Token 使用预算

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. 你可以为动态工作流设定明确的 Token 使用预算,以限制每个任务的 Token 消耗量。例如,通过提示命令如“使用 10k Token”来设置上限。

Saving and sharing dynamic workflows 保存与分享动态工作流

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 目录,或通过技能(skill)进行分发。

图像

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 将技能中的工作流视为模板,而非需要逐字执行的脚本。

图像

A whole new world 一个全新的世界

Workflows are a helpful new way to extend Claude Code. I encourage you to think of this as a starting point, there’s still much to discover in how to use them best. Let us know what you find. 工作流是扩展 Claude Code 的一种实用新方式。我鼓励大家将此视为一个起点,关于如何最好地使用它们,还有大量值得探索之处。欢迎告诉我们你的发现。

Thariq Shihipar and Sid Bidasaria (@sidbid) are members of technical staff at Anthropic, working on Claude Code.Thariq Shihipar 和 Sid Bidasaria (@sidbid) 是 Anthropic 的技术团队成员,负责 Claude Code 的开发工作。

输入关键词开始搜索