Claude Code · Advanced/Lesson 03 of 07~5 min

Run and save a dynamic workflow

When the plan becomes code, three things follow: you can read it before it runs, independent agents can check each other’s findings, and a run that worked becomes a command you rerun on new input.

The Third Way engineering team||Verified against Claude Code v2.1.285 (stable), October 2026

01The goal

Have Claude write a dynamic workflow for a job that fans out across many files, keep the run small, and save it as a slash command that takes its input from args.

02The idea

A dynamic workflow is a JavaScript script that Claude writes for your task, and that a runtime executes in the background while your session stays responsive. The script starts the agents and keeps their results in its own variables; only the final answer reaches your conversation. That is the "script holds the plan" arm of the last lesson’s chart, made literal.

↳The shape of a workflow script
export const meta = {
name: "audit-routes",
description: "Audit route handlers for missing auth checks",
}
 
const found = await agent("List every .ts file under src/routes/.")
 
const audits = await pipeline(found.files, file =>
agent(`Audit ${file} for missing authentication checks.`),
)
 
return audits.filter(Boolean)
agent() starts one subagent; pipeline() runs one per item in a list; parallel() runs a set at the same time. The first statement must be a literal export const meta object — anything cleverer there drops the script from / autocomplete once saved.

Because the plan is code, you can read it before approving it, and a saved run reruns identically. A size guideline tells Claude how many agents to aim for when writing the script — small means the fewest agents. It is advice to Claude, not a cap on the runtime. On the Pro plan, dynamic workflows are off until you turn them on from the Dynamic workflows row in /config.

03The walkthrough

  1. 01Start in Manual mode so you see every plan before it runs — claude --permission-mode manual (add --model sonnet for the cheaper variant; a workflow’s agents run on your session’s model when nothing else assigns one).
  2. 02Set the size guideline: /config workflowSizeGuideline=small. The choice lives in your home config, not the repository, and applies from your next prompt.
  3. 03Optionally, run the bundled research workflow once to feel the shape: /deep-research What changed in the Node.js permission model between v20 and v22? — approve with Yes, run it and wait. (It searches the web, so it needs the WebSearch tool.)
  4. 04Ask for one of your own, in your own words — that phrasing is the trigger: "use a workflow to audit every file under <folder> for errors that are caught and then ignored, and adversarially verify each finding before reporting it."
  5. 05Claude Code shows the planned phases and asks: Yes, run it; View raw script; No. Choose View raw script (or Ctrl+G to open it in your editor) and read it — it should look like the shape above. Then run it.
  6. 06While it works, /workflows: the progress view lists each phase with its agent counts; Enter drills into an agent’s prompt, tool calls and result; Esc backs out; p pauses and resumes; x stops. A one-line progress summary also rides in the task panel below the prompt.
  7. 07When the findings arrive, /workflows again, select your run, and press s. In the save dialog, Tab toggles between the project’s .claude/workflows/ — shared with everyone who clones the repo once committed — and your personal ~/.claude/workflows/. Choose the project folder, Enter. From your next session on, the workflow runs as a command: /audit-routes — listed in / autocomplete, and it takes input: "Run /audit-routes on samples" hands the folder to the script through args.

04Your turn

Build a workflow that finds every TODO and FIXME comment in a folder you name, checks whether each still applies to the current code, and reports only the ones that do — each item as a path:line plus one sentence. Keep it small: agents in batches, not one per comment. Save it to the project folder, commit it, then run it by name on two different folders without editing it between runs. If the first version does not read its folder from args, ask Claude to change the saved script so it does — a saved workflow is a file under .claude/workflows/, editable like any other.

The approval economics matter more here than anywhere else in the course. In auto mode, Claude Code asks only before your first workflow launch: one Yes records consent in your user settings, and later launches start without asking. So read each script before you approve it, and stay in Manual mode for a workflow you have not read. A run can use meaningfully more tokens than the same task in conversation — try it on one small folder first, and note that a stopped run does not resume with p; ask Claude to relaunch it, and agents that were mid-flight start over.

↳Check yourself
Q1

What does the size guideline do?

  1. AAdvises Claude how many agents to aim for — not a runtime cap
  2. BCaps the agents a run may start, hard
  3. CCaps the tokens a run may spend
→Check your answer
Answer: A

It is advice that shapes the script Claude writes. The runtime limits are separate; the Large workflow warning that reports oversized runs does not pause or limit them either.

Q2

In /workflows, what does pressing s on a run do?

  1. AStops it
  2. BSaves its script for reuse as a command
  3. CScrolls the log
→Check your answer
Answer: B

s opens the save dialog — Tab toggles between the project’s .claude/workflows/ and your personal folder. Stopping is x; pausing is p.

Q3

Why must the first statement be a literal export const meta object?

  1. AThe runtime cannot parse anything else
  2. BIt sets the agents’ permission mode
  3. COtherwise the saved script drops out of / autocomplete
→Check your answer
Answer: C

A variable, a function call or a spread in that position keeps the script runnable but keeps it out of the /<name> command listing.

The Third Way engineering team
Delivery engineering
Work with us