YouMind
Sign in

Claude Code Dynamic Workflows: Every Task Can Have Its Own Harness

@MinLiBuilds
SIMPLIFIED CHINESEJun 03, 2026
205K
297
57
7
716

TL;DR

Claude Code now features dynamic workflows, enabling the AI to generate custom orchestration scripts for complex tasks. This system uses parallel subagents to overcome limitations like agent laziness and bias in research and coding.

Claude Code can now instantly write its own harness, tailored to the task at hand. This capability is called dynamic workflow: it dynamically writes orchestration scripts, runs dozens to hundreds of parallel subagents in a single session, and checks itself before any results are presented to you.

The default Claude Code harness is great for writing code, but more specialized tasks like research, security analysis, agent teams, and code reviews previously required building a custom harness on top of Claude Code to achieve optimal performance.

Workflows allow you to dynamically create these custom harnesses, which are reusable, shareable, and allow Claude to solve problems in a more native way than the default approach.

In this article, I will share my initial experiences and insights using workflows. Note that workflows consume more tokens and are better suited for complex, high-value tasks.

0. Introduction

The introduction section contains notes from Practice Brother.

A great read; workflows might be the best invention since skills. They are an enhanced version of goals and are well worth learning. This article explains various application scenarios for workflows in simple terms.

The original author is Thariq @trq212, a core Anthropic employee who frequently shares Claude Code tips.

The content is long; feel free to skip to sections of interest. To get a direct feel for what it can do, see Section 1;

To understand why it's needed, see Sections 3 to 5

; to copy implementation solutions directly, jump to Section 6.

1. Example Prompts

These examples demonstrate what workflows can do. You can directly ask Claude for similar requests:

  • Have multiple competing theories try to reproduce flaky tests.
  • Mine recurring corrections from past sessions.
  • Locate root causes in Slack incident channels.
  • Get multiple perspectives of criticism for a business plan.
  • Rank resumes and validate them.
  • Use a tournament-style selection to name a CLI tool.
  • Perform a refactor across the entire codebase.
  • Verify technical claims in a blog draft against actual code.

2. How Workflows Work

Workflows execute JavaScript files containing special functions for generating and coordinating subagents. Standard JavaScript tools like JSON, Math, and Array can be used to process data. Workflows can choose which model subagents use and decide whether they run in an isolated worktree. If interrupted, the workflow can resume from where it left off.

实践哥MinLi - inline image

3. Why Workflows are Needed

The default harness completes planning and execution within a single context window. This works well for coding tasks but fails for long-running, massive parallel, highly structured, or adversarial tasks. Specifically, it shows three failure modes:

  • Agent Laziness: Faced with complex multi-part tasks, Claude stops prematurely, finishing only a portion (e.g., processing 35 out of 50 security reviews).
  • Self-Preference Bias: When asked to validate or judge results against a rubric, Claude tends to favor its own conclusions.
  • Goal Drift: Fidelity is lost over multiple interactions; each summary drops details, including edge case requirements and constraints.

Workflows counter this by orchestrating independent subagents, each with its own context window, focused goal, and isolation.

4. Dynamic vs. Static Workflows

Previously, static workflows built with the Claude Agent SDK or claude -p coordinated multiple Claude Code instances in a generic way, requiring you to cover all edge cases. With Claude Opus 4.8 and dynamic workflows, Claude can now write harnesses tailored to specific scenarios.

实践哥MinLi - inline image

5. Practical Patterns for Using Workflows

You can trigger a workflow by requesting one directly or using ultracode in your prompt to ensure Claude Code creates one. Common patterns include:

实践哥MinLi - inline image
  • Classify and Execute: A classifier agent determines the task type and routes it to different agents or behaviors; it can also classify output upon completion.
  • Fan-out and Synthesize: Break a task into many smaller steps, run an agent for each, and synthesize the results. This is useful when many steps benefit from clean, non-interfering context windows. Synthesis acts as a barrier, waiting for all agents to finish before merging structured output.
  • Adversarial Validation: For every agent generated, run a separate adversarial agent to validate output against a rubric or criteria.
  • Generate and Filter: Generate multiple ideas on a topic, filter them by rubric or validation, and keep only the highest quality, verified results after deduplication.
  • Tournament: Have N agents compete on the same task using different methods. Pairwise judging agents determine winners until only one remains.
  • Loop until Complete: For tasks with unknown workloads, continuously generate agents until a stop condition is met (e.g., no new discoveries, no more errors in logs).

6. Application Scenarios

  • Migration and Refactoring: Bun used workflows when rewriting Zig to Rust. It breaks tasks into serial steps (call sites, failing tests, modules), generates subagents for each fix in a worktree, performs adversarial reviews, and merges. Avoid resource-intensive commands to maximize parallelism.
  • Deep Research: Claude Code's /deep-research skill uses workflows to fan out web searches, scrape sources, adversarially verify claims, and synthesize a cited report. This applies to non-web research too, like compiling Slack status reports or exploring codebase features.
  • Deep Validation: For reports requiring citations for every fact, a workflow can identify claims, have subagents check each one, and use a verifier agent to ensure source quality.
实践哥MinLi - inline image
  • Sorting: For large lists needing qualitative measurement (e.g., ranking tickets by severity), ranking 1000+ lines in one prompt reduces quality and blows out context. Use tournaments, pairwise pipelines, or parallel bucket ranking; each comparison is its own agent.
实践哥MinLi - inline image
  • Memory and Rule Following: When Claude misses rules even in CLAUDE.md, create a workflow with a rule verifier for each rule. Use a skeptic persona to review rules to prevent false positives. Conversely, mine recurring corrections from recent sessions, cluster them with parallel agents, and adversarially validate if the rule would have prevented the error before refining CLAUDE.md.
实践哥MinLi - inline image
  • Large-scale Triage: A triage workflow classifies items, deduplicates against existing records, and takes action. A 'quarantine' pattern prevents agents reading untrusted content from executing high-privilege actions, delegating those to processing agents. Use with /loop for continuous operation.
实践哥MinLi - inline image
  • Exploration and Taste: Useful for design or naming decisions that rely on 'taste' and benefit from rubrics. Claude explores solutions while a review agent judges them against a rubric. Solutions can be ranked or selected via tournament.
  • Evaluation: Run lightweight evals by generating independent agents in a worktree and a comparison agent to score outputs against a rubric.
  • Model and Intelligent Routing: Create a task-tuned classifier agent to decide which model to use. For example, explaining an auth module depends on file count; a classifier researches this first, then routes to Sonnet or Opus based on complexity.

7. When Not to Use Workflows

Workflows are new and not needed for every task; they consume significantly more tokens. Use them creatively for tasks beyond conventional usage. For routine coding, consider if extra compute is necessary; most coding doesn't need five reviewers.

8. Tips for Building Workflows

  • Prompting: Detailed prompts work best. Workflows aren't just for big tasks; you can prompt a quick workflow for a fast adversarial review of a hypothesis.
  • Combine with /goal and /loop: For repeatable workflows like triage or research, use /loop for intervals and /goal for hard completion requirements.
  • Token Budget: Set a clear token budget (e.g., 10k tokens) in the prompt to limit usage.
  • Saving and Sharing: Press 's' in the workflow menu to save. Check them into ~/.claude/workflows or distribute via skills. Reference JavaScript workflow files in SKILL.md. For flexibility, prompt Claude to treat skill workflows as templates rather than literal scripts.
实践哥MinLi - inline image
实践哥MinLi - inline image

9. A New Starting Point

Workflows provide a powerful new way to extend Claude Code. See it as a starting point to explore new methods for completing tasks with Claude. There is much more to discover about how to use it best.

One-click save

Use YouMind for AI deep reading of viral articles

Save the source, ask focused questions, summarize the argument, and turn a viral article into reusable notes in one AI workspace.

Explore YouMind
For creators

Turn your Markdown into a clean 𝕏 article

When you publish your own long-form writing, images, tables, and code blocks make 𝕏 formatting painful. YouMind turns a full Markdown draft into a clean, ready-to-post 𝕏 article.

Try Markdown to 𝕏

More patterns to decode

Recent viral articles

Explore more viral articles