Skip to main content

Dynamic Workflows and Ultracode NEW

UPDATED 2026-08-13 5 min read EDIT ON GITHUB ↗

Delegate 100 agents sequentially and your context collapses first. Dynamic workflows solve this by keeping the plan in script variables rather than in Claude’s context — intermediate results stay in the script, and only the final result returns to the session. It is where tokenomics meets loop engineering: enabling massive fan-out while containing context cost.

Info
One-line summary: Dynamic workflows are automation scripts written in JavaScript that orchestrate dozens to hundreds of agents in parallel. Ultracode is triggered by /effort ultracode or the ultracode keyword.
Platform basics
Background on the platform layer is in Dynamic Workflows. This page is the MoAI-ADK account of it.

The 3 Orchestration Primitives

MoAI-ADK provides 3 orchestration primitives, and the selection criterion is “who holds the plan.”

1. Sequential Sub-agents

MoAI’s default mode — delegating one agent per turn, in sequence.

CharacteristicDescription
Plan locationClaude’s context (turn-by-turn judgment)
Intermediate resultsAccumulate in Claude’s context window
ParallelismSequential execution (1 agent per turn)
ScaleTypically 3-5 agents
Context costEvery agent result consumes context

When to use:

  • Simple 1-5 agent tasks
  • Coding-centric run-phase work
  • When agents have many inter-dependencies

2. Agent Teams

A mode where multiple teammates collaborate via a shared TaskList.

CharacteristicDescription
Plan locationShared TaskList (cross-team coordination)
Intermediate resultsTaskList + each teammate’s context
Parallelism3-5 concurrent (Anthropic recommendation)
ScaleSmall teams (3-5 members)
Context costIndependent context per teammate

When to use:

  • Multiple teammates working in parallel
  • Cross-layer dependencies (backend ↔ frontend)
  • Collaboration and review between teammates needed
Warning
In v3.0, MoAI’s Agent Teams static orchestration layer was retired. Forcing --team falls back to sub-agent mode. The native Claude Code teammate runtime (e.g. the GLM panes of moai cg) continues to operate.

3. Dynamic Workflows

Automation scripts written in JavaScript orchestrate many agents.

CharacteristicDescription
Plan locationScript code (declarative plan)
Intermediate resultsScript variables (no context accumulation)
ParallelismUp to 16 concurrent (up to 1000 total)
ScaleVery large (dozens to hundreds of agents)
Context costOnly the final result consumes context

When to use:

  • Large-scale parallel work (dozens to hundreds of agents)
  • Whole-codebase scans
  • Large migrations
  • Cross-source verification

Selection Decision Tree

A flowchart for deciding which primitive to choose.

flowchart TD
    START[Assess task characteristics] --> Q1{How many independent
agents needed?} Q1 -->|1-5| Q2{Parallel execution
required?} Q1 -->|5-10| Q3{Very
complex?} Q1 -->|10+| WORKFLOW["Choose Dynamic Workflow
Optimal for parallel scripts"] Q2 -->|No| SUBAGENT["Sequential Sub-agent
Sequential delegation"] Q2 -->|Yes| TEAMS["Agent Teams
Team collaboration"] Q3 -->|Yes| TEAMS Q3 -->|No| SUBAGENT SUBAGENT --> DONE["✓ Selection complete"] TEAMS --> DONE WORKFLOW --> DONE

Ultracode and Dynamic Workflows

/effort ultracode

bash
/effort ultracode

Enables automatic workflow generation for all substantive work in the current session.

Effects:

  • Reasoning effort: set to xhigh
  • Automatic workflow generation enabled
  • The optimal orchestration primitive is chosen per task

When to use:

  • Very complex multi-phase work
  • Large projects that need automatic orchestration

The ultracode Keyword

If you want to trigger a workflow for a single request rather than the whole session, use the keyword.

bash
> Find and classify all TODO comments in our codebase.
> (Without the ultracode keyword, runs as a regular sub-agent)

VS

> ultracode: Find and classify all TODO comments in our codebase.
> (Automatically generates a workflow)

Dynamic Workflow Structure

Basic Script Template

javascript
// Workflow script: classify TODOs across the entire codebase
const packages = [
  "internal/auth",
  "internal/api",
  "internal/db",
  "pkg/utils"
];

const results = [];

for (const pkg of packages) {
  // Create an independent agent for each package
  const result = await agent({
    agentType: "Explore",
    model: "sonnet",
    effort: "low",
    prompt: `
      Find and classify all TODO comments in the ${pkg} package.
      Format: [file] [line] [category] [content]
    `
  });
  results.push({ pkg, todos: result });
}

// Final consolidation
const summary = {
  total_packages: packages.length,
  package_summaries: results,
  grand_total_todos: results.reduce((sum, r) => sum + r.todos.length, 0)
};

return summary;

Characteristics

ItemDescription
Agent creationDynamically created in a loop (await agent({...}))
Intermediate resultsStored in script variables (no context accumulation)
Parallel executionIndependent tasks auto-parallelized (up to 16 concurrent)
Final returnOnly the consolidated result returns to the current session

MoAI Integration Considerations

The AskUserQuestion Constraint

Workflow agents cannot interact with the user directly.

text
✗ A workflow agent raising a question to the user → not possible
✓ The MoAI orchestrator collects all choices up front → then runs the workflow

Resolution:

  1. The MoAI orchestrator calls AskUserQuestion
  2. Collects the user’s responses
  3. Runs the workflow with the responses included in its input

Implementation Kickoff Approval

Workflow execution requires user approval just like any run phase. A massive fan-out does not make the human gate disappear.

text
/moai run --workflow SPEC-XXX

→ MoAI: "Running this SPEC as a workflow. Proceed?"
→ AskUserQuestion approval required

Cost Awareness

Dynamic workflows save context, but total token consumption can be large. The fan-out scale is the cost.

TaskAgent countExpected cost
Small package scan5Low
Mid-size codebase20Medium
Full repo scan100+High

Cost controls:

  • Model: use sonnet low effort (read-only extraction)
  • Agent count: limit scope (packages.slice(0, 20))
  • Parallelism: manually tune down from the max of 16

Workflow Activation and Configuration

Activation Conditions

Dynamic workflows run only under the following conditions.

  1. Claude Code v2.1.154+
  2. A paid plan (Pro or Team)
  3. "disableWorkflows": false in /config

Disabling

Can be disabled at the organization or user level.

bash
/config
# Turn off the dynamic workflows toggle

OR

export CLAUDE_CODE_DISABLE_WORKFLOWS=1
Info
Tip: For small workloads, Sequential Sub-agents suffice. Use dynamic workflows only when you need to “orchestrate dozens to hundreds of independent tasks in parallel” — and remember that the fan-out itself is the cost.