Back to all articles
TutorialDecember 2, 2026·11 min read

How to Run Dynamic Workflows in Claude Code Without Filling Your Context (2026)

You ask Claude Code to check every route handler in your app for missing authentication. It starts with a subagent per folder, collects the results, verifies a few, and by the time it's halfway through, your conversation is long, the context is filling, and Claude is juggling dozens of findings at once. You want the same thorough check, but without every intermediate result landing in your session.

The short answer: that's what dynamic workflows are for. Anthropic's documentation describes a dynamic workflow as "a JavaScript script that orchestrates many subagents at once." Claude writes the script for your task, a runtime runs it in the background, and the intermediate results stay in the script, not in your conversation. Anthropic's page puts it directly: "Intermediate results stay in script variables instead of landing in Claude's context."

This guide covers what dynamic workflows are, how they differ from subagents, skills, and agent teams, how to run one, how to watch and manage it, how to save it for reuse, what it costs, and how to keep the context your workflows rely on in one place.

What a dynamic workflow is

A workflow moves the plan out of the conversation and into code. Anthropic's page explains: "Claude writes the script for the task you describe, and a runtime executes it in the background while your session stays responsive."

Anthropic suggests reaching for a workflow "when a task needs more agents than one conversation can coordinate, or when you want the orchestration codified as a script you can read and rerun." Its examples include a codebase-wide bug sweep, a large migration, research that needs sources cross-checked, and a hard plan drafted from several angles.

Who can use it. Anthropic's page says dynamic workflows "are available on all paid plans, with Anthropic API access, and on Amazon Bedrock, Google Cloud's Agent Platform, and Microsoft Foundry." On Pro, you turn them on from the Dynamic workflows row in /config.

Why workflows keep your context clear

Claude Code has several ways to run a multi-step task. Anthropic's page compares them by who holds the plan and where results go:

SubagentsSkillsAgent teamsWorkflows
Who decides what runs nextClaude, turn by turnClaude, following the promptThe lead agent, turn by turnThe script
Where intermediate results liveClaude's context windowClaude's context windowA shared task listScript variables
ScaleA few delegated tasks per turnSame as subagentsA handful of long-running peersDozens to hundreds of agents per run
InterruptionRestarts the turnRestarts the turnTeammates keep runningResumable in the same session

The key row is where intermediate results live. Anthropic's page explains the difference: with subagents, skills, and agent teams, "Claude is the orchestrator: it decides turn by turn what to spawn or assign next, and every result goes into a context window." A workflow script "holds the loop, the branching, and the intermediate results itself, so Claude's context holds only the final answer."

There's a quality benefit too. Anthropic's page says a workflow "can have independent agents adversarially review each other's findings before they're reported". You get a checked result instead of a single pass.

How to run your first workflow

The quickest start is the built-in workflow. Anthropic's page says /deep-research "Fans out web searches on a question across several angles, fetches and cross-checks the sources it finds, votes on each claim, and returns a cited report". It requires the WebSearch tool.

Here's Anthropic's example:

/deep-research What changed in the Node.js permission model between v20 and v22?

Claude Code asks whether to allow the workflow. Select Yes to continue. The run starts in the background, and you get one report at the end.

How to ask Claude to write a workflow

For your own task, there are two ways.

Ask in your prompt. Include the keyword ultracode, or ask in your own words. Anthropic's page says asking for it directly, such as "use a workflow" or "run a workflow", also works. One of Anthropic's example prompts:

use a workflow to audit every route handler under src/routes/ for missing authentication checks, and adversarially verify each finding before reporting it

Anthropic's page notes the keyword "only chooses how Claude structures the work: the agents' tool calls receive the same permission checks and sandboxing as any other tool call in the session."

Turn on ultracode for the session. Run /effort ultracode and Claude plans a workflow for every substantive task. Anthropic's page warns that this applies to every task, "so each request uses more tokens and takes longer than the same request without a workflow." Turn it off with /effort ultracode off when you return to routine work.

The keyword only counts in a prompt you type yourself. Anthropic's page lists cases where it doesn't start a workflow, including a prompt passed with -p and a scheduled task prompt.

Approve the plan before it runs

In the CLI, Claude Code shows the planned phases and asks you to choose: run it, run it and don't ask again for that workflow in this project, view the raw script, or cancel. Anthropic's page says the "don't ask again" option appears when you run a bundled, saved, or plugin workflow by name, "not for a script Claude wrote for the current task."

Whether you see the prompt depends on your permission mode. In Auto mode, you're asked on the first launch only. In Manual or accept edits mode, you're asked every run unless you chose "don't ask again" for that workflow. In bypass permissions mode, the run starts immediately.

The agents the workflow starts follow your permission rules. Anthropic's page advises: "To avoid prompts on a long run, add the tools the agents need to your allow rules before starting."

Watch and manage the run

Workflows run in the background. Run /workflows to list running and completed workflows and open a progress view. Anthropic's page says it "shows each phase with its agent counts."

From the progress view, you can drill into a phase and an agent to see its prompt, recent tool calls, and result. Anthropic lists the keys, including p to pause or resume the run, x to stop the selected agent or the whole workflow, r to restart a running agent, and s to save the run's script as a command.

A paused run can be resumed. Anthropic's page explains what happens on a relaunch: a completed agent "returns its saved result", while a failed agent "runs again, and so does every agent the script starts after it, even ones that completed."

There's one thing to know before you close your session. Anthropic's page says: "If you background your session or exit Claude Code while a workflow run is in progress, the run doesn't continue on its own." You resume it by asking Claude to relaunch the workflow.

Save a workflow for reuse

When a run does what you wanted, you can save it. Run /workflows, select the run, and press s. Anthropic's page describes the two locations:

  • .claude/workflows/ in your project: "shared with everyone who clones the repo".
  • ~/.claude/workflows/ in your home directory: "available in every project, visible only to you."

A saved workflow runs as /<name> in future sessions. If a project workflow and a personal workflow share a name, Anthropic's page says the project one runs. Saved workflows can also take input through args, such as a list of issue numbers.

Know the limits and the cost

Anthropic's page lists runtime limits. By default, up to 16 agents run at once, fewer when fewer CPUs are available. There's a cap of 1,000 agents per run. And a run has no mid-run user input: it pauses on its own only for agent permission prompts and a usage-limit wait. For sign-off between stages, Anthropic suggests running each stage as its own workflow.

On cost, Anthropic is direct: "A workflow spawns many agents, so a single run can use meaningfully more tokens than working through the same task in conversation." Runs count toward your plan's usage and rate limits.

To keep it in check, Anthropic suggests running the workflow "on a small slice first: one directory instead of the whole repo, or a narrow question instead of a broad one." Claude Code also shows a Large workflow warning when a run schedules more than 25 agents or its projected token total passes 1.5 million. You can set a size guideline in /config under Dynamic workflow size.

One more detail affects speed and cost. Workflow agents' prompt caches hold for five minutes by default, even on a subscription. Anthropic's page says you can set subagentPromptCacheTtl to 1h to keep them longer, and adds that the API bills one-hour cache writes at a higher rate.

What people try first

Running a large task as one long conversation. Every intermediate result lands in Claude's context.

Turning on ultracode for everything. Each request then uses more tokens and takes longer.

Closing the session mid-run. The run doesn't continue on its own. Ask Claude to relaunch it.

Running the full repo first. Try a small slice to gauge the spend.

Expecting to approve stages mid-run. There's no mid-run input; split stages into separate workflows.

The Fix: Run large tasks as workflows without crowding your context

Step 1: Pick a task that fits

Choose work that needs many agents or the same step across many items, such as an audit, a migration, or cross-checked research.

Step 2: Ask for a workflow

Say "use a workflow" or include ultracode in your prompt, and describe the task, the scope, and how findings should be verified.

Step 3: Approve and watch

Review the phases, approve the run, and open /workflows to follow progress.

Step 4: Start small, then scale

Run it on one directory first. If the result is right, run it on the rest.

Step 5: Save it

Press s in /workflows to save the script to .claude/workflows/ for your team or ~/.claude/workflows/ for yourself.

Step 6: Write down the context agents need

Workflow agents start from your project's files and the prompts the script gives them. Keep the background they need, such as the rules for what counts as a finding, in a short note you can reuse.

Setting this up in MemoryLake

Workflows keep intermediate results out of your context, and saved scripts make the orchestration repeatable. The background behind a run, such as why certain routes are exempt or which past findings were false alarms, is still something you have to supply, and it's useful in other assistants too.

MemoryLake is a memory layer for that kind of project context, kept in one place you maintain and available to the assistants you connect, such as ChatGPT, Claude Code, and Codex.

You write the entries yourself. Nothing is read out of, written to, or deleted from your workflow scripts, workflow runs, Claude Code sessions, CLAUDE.md, auto memory, or any vendor's store. Dynamic workflows work the way Anthropic describes them.

Step 1: Create an API key

Sign in and generate a key from the dashboard. Keep it somewhere private.

The MemoryLake console showing the API keys screen, where a new key is created and copied for use in an agent
The MemoryLake console showing the API keys screen, where a new key is created and copied for use in an agent

Step 2: Upload your first memories

Start with the note from Step 6 of the fix: the rules, exceptions, and past decisions your workflow runs depend on.

The MemoryLake workspace with the first documents uploaded, listing each file as it becomes searchable memory
The MemoryLake workspace with the first documents uploaded, listing each file as it becomes searchable memory

Step 3: Connect your AI & agents

Connect Claude Code, ChatGPT, Codex, and the other assistants you use, so the same context is there in each.

The MemoryLake integrations screen listing the AI clients and agent frameworks that can be connected to the memory layer
The MemoryLake integrations screen listing the AI clients and agent frameworks that can be connected to the memory layer

What this changes in practice

The first difference is less repetition in prompts. The background for a run doesn't have to be rewritten each time.

The second is consistency. The same rules apply whether you run a workflow, ask a single question, or work in another assistant.

The third is cleaner results. When agents know which findings were already ruled out, the final report has less noise.

Best practices for Claude Code dynamic workflows

Use workflows for scale, not small tasks. They're built for many agents.

Ask for adversarial verification. Independent agents can check each other's findings.

Add allow rules before long runs. It avoids permission prompts mid-run.

Start with a slice. Gauge tokens before running everything.

Watch /workflows. You can pause, stop, or restart agents there.

Save what works. Saved workflows rerun the same orchestration each time.

Split stages that need sign-off. A run takes no mid-run input.

Conclusion

Dynamic workflows let Claude Code run large tasks as a script instead of a long conversation. Claude writes the script, a runtime runs it in the background, and intermediate results stay in script variables, so your context holds only the final answer. You can try the built-in /deep-research, ask for a workflow with "use a workflow" or ultracode, approve the planned phases, watch it in /workflows, and save what works to .claude/workflows/ or ~/.claude/workflows/.

Runs can use many more tokens than a conversation, so start small, add allow rules first, and split stages that need your sign-off. Keep the background your runs depend on written down, so every run starts from the same context.

Frequently asked questions

What is a dynamic workflow in Claude Code?

Anthropic describes it as a JavaScript script that orchestrates many subagents at once. Claude writes it for your task, and a runtime runs it in the background.

How is a workflow different from subagents?

With subagents, results go into Claude's context window. In a workflow, intermediate results stay in script variables, so Claude's context holds only the final answer.

How do I start a workflow?

Ask for one in your prompt, such as "use a workflow", or include the keyword ultracode. You can also run the built-in /deep-research.

Are dynamic workflows available on Pro?

Yes. Anthropic says they're available on all paid plans. On Pro, turn them on from the Dynamic workflows row in /config.

Does a workflow keep running if I close Claude Code?

No. The run doesn't continue on its own. Ask Claude to relaunch it, and completed agents return their saved results.

Where are saved workflows stored?

In .claude/workflows/ in your project, shared with the repo, or ~/.claude/workflows/ in your home directory, visible only to you.

Do workflows use more tokens?

Yes. Anthropic says a run can use meaningfully more tokens than working through the same task in conversation.