Claude Code automation primitives loops goals routines dynamic workflows

Claude Code automation primitives loops goals routines dynamic workflows
Share

Anthropic has repackaged automation in Claude Code as four composable primitives — loops, goals, routines, and dynamic workflows — that turn the developer from "the loop" into the designer of a loop that runs itself. Each one wraps the same turn-based cycle every Claude Code prompt already executes: evaluate the prompt, call tools, receive results, repeat until the model stops.

How Loops, Goals, Routines, and Dynamic Workflows Compose

How Loops, Goals, Routines, and Dynamic Workflows Compose (source: mer.vin)

The four primitives span a spectrum from session-scoped polling to cloud-persistent scheduling to multi-agent orchestration, and each is a thin control layer around Claude Code's core model-tool while-loop . Loops (/loop) re-run a prompt at intervals down to one-minute granularity, capped at 50 scheduled tasks per session with a 7-day auto-expiry, and only while the session stays open with local file access . Goals (/goal) define a verifiable end state: a separate fast evaluator checks the stop condition each time Claude tries to finish and sends it back until the goal is met or a turn cap fires .

Routines move recurring work to Anthropic-managed cloud infrastructure — no local file access, but it survives a machine shutdown and runs on schedules, API POSTs, or GitHub events . Dynamic workflows are the orchestration layer: Claude automatically writes a JavaScript script that fans out dozens of parallel subagents, keeping intermediate results in script variables instead of Claude's context window, so only the final answer lands back in context .

PrimitiveWhere it runsSurvives shutdown?Key bound
/loopLocal sessionNo≤50 tasks, 7-day expiry
/goalLocal sessionNoOne active goal, turn cap
RoutinesAnthropic cloudYesNo local file access
Dynamic workflowsBackground JS runtimeRestarts on exit≤16 concurrent, 1,000 agents/run

The scale signal is concrete: Jarred Sumner used dynamic workflows to port roughly 750,000 lines of Bun from Zig to Rust, with 99.8% of the existing test suite passing and eleven days from first commit to merge . Source video: Anthropic walkthrough.

Tag and Plan Prerequisites

Tag and Plan Prerequisites (source: mer.vin)

Before composing anything, confirm your Claude Code version and plan, because each primitive has a distinct floor. /loop needs v2.1.72 or later , and /goal needs v2.1.139, added May 11, 2026, with one active goal per session that restores on resume . Dynamic workflows reached general availability on May 28, 2026 and require v2.1.154 or later . The Ultracode per-session mode—auto-orchestrating every substantive task—and the "Large workflow" warning both require v2.1.203+ and an xhigh-capable model; activating Ultracode lasts only the current session .

Plan gates matter too. Dynamic workflows run on all paid plans and via the Anthropic API, Amazon Bedrock, Vertex, Agent Platform, and Microsoft Foundry—enable them from the Dynamic workflows row in /config . Routines require Pro, Max, Team, or Enterprise with Claude Code on the web enabled and remain in research preview, so behavior, limits, and the API surface can change; the API uses the beta header experimental-cc-routine-2026-04-01 .

How to Enable and Compose Each Primitive

How to Enable and Compose Each Primitive

Enable the four primitives in order of increasing autonomy: /loop and /goal are session-scoped slash commands you invoke inside an open Claude Code session, routines are saved in the Claude Code web UI, and dynamic workflows are triggered in natural language. Each targets a different failure mode—scheduling, verification, durability, and parallel orchestration—so the setup differs per layer.

Quick Answer: Type /loop 5m for in-session scheduling (up to 50 tasks), /goal … stop after N tries for verified end states, save routines in the web UI for cloud runs, and say "use a workflow" to fan work across agents—capped at 1,000 per run.

Loops (/loop). Schedule a recurring prompt at cron-like intervals down to one-minute granularity while the session stays open, with full local file access:

/loop 5m check the open PR, address any review comments, fix failing CI

This fires every five minutes. A session holds up to 50 scheduled tasks, missed fires do not catch up, and recurring tasks expire automatically seven days after creation as a safety bound. Tasks stop firing the moment the session closes.

Goals (/goal). Define a verifiable end state and a turn cap instead of a process:

/goal get the homepage Lighthouse score to 90 or above, stop after 5 tries

Each time Claude tries to stop, a separate fast evaluator model checks the condition using only the transcript Claude surfaces—it does not run tools or inspect files itself. Running bare /goal reports turns and token usage so far.

Routines. In the Claude Code web UI, save a prompt plus repository, environment, connectors, and triggers—a schedule, an API POST, or GitHub events, which you can combine on one routine. Runs execute as full cloud sessions without interactive approval prompts.

Dynamic workflows. Say "use a workflow" in natural language, type ultracode for a single run, or set /effort ultracode for the whole session; Claude auto-generates the JavaScript script. Save any successful run's script to .claude/workflows/<name>.js as a reusable /<name> command, passing runtime input via an args global. The scale is real: Boris Cherny, identified as Claude Code's creator, described running "a few thousand" agents overnight.

Sharp Mistakes and Misconceptions

The most common failure is treating /loop as durable automation. It is session-scoped: a loop only fires while the session stays open on your machine, tasks stop the moment the session closes, and recurring tasks expire seven days after creation . Anything that must survive a reboot or run unattended on a schedule belongs in a routine, which executes on Anthropic-managed cloud infrastructure whether or not your machine is on .

A second trap sits inside /goal: the separate evaluator model does not run tools or inspect files independently. A goal is only as verifiable as the evidence Claude surfaces in the transcript, so if the proof never appears there, the goal can read as met when it isn't . Deterministic, quantitative criteria—test pass counts, a Lighthouse threshold like 90—work reliably; vague qualitative goals invite the "good enough" judgment call the evaluator can't police .

With routines, a green infrastructure status does not prove the task succeeded—inspect the run transcript each time—and the API surface is in research preview, subject to change without notice . Dynamic workflows have their own boundaries: no mid-run user input, and no direct filesystem or shell access—only the spawned sub-agents touch files. Exiting Claude Code restarts a workflow fresh; within-session resume caches completed sub-agent results, but cross-session persistence does not exist . Watch for the "Large workflow" warning, which fires above 25 scheduled sub-agents or a projected 1.5 million tokens on v2.1.203+.

Composing Primitives: Recipes and Examples

The payoff comes from stacking the primitives so the human stops being the loop. A concrete pipeline: a /loop 5m polls a pull-request channel every five minutes, a /goal defines the end state as "all review comments addressed and CI green," and a dynamic workflow fans out parallel sub-agents to triage and fix each failing check . The loop supplies cadence, the goal supplies a verifiable stop condition, and the workflow supplies parallelism.

You do not have to author the fan-out pattern yourself. The bundled /deep-research workflow ships in the box: it fans web searches across angles, cross-checks sources, and votes on each claim before returning a cited report. As of v2.1.196 it marks unverifiable claims "unverified" rather than refuting them . Its script is a reusable reference for the fan-out, cross-check, and vote pattern.

Right-size the scale. The /config guideline classes runs as small (fewer than 5 sub-agents), medium (fewer than 15), and large (fewer than 50)—use the smallest class that solves the problem . Production-scale usage is already public: Boris Cherny, identified as Claude Code's creator, described running "5 to 10 concurrent sessions" and "a few thousand" agents overnight . Start with one composed recipe, verify each run, and scale the class only when the smaller one falls short.

Frequently asked questions

What is the difference between /loop and a routine in Claude Code?

/loop is session-scoped: it re-runs a prompt at intervals with full local file access, but only while the session stays open on your machine. It caps at 50 scheduled tasks per session and tasks expire seven days after creation . Routines run on Anthropic-managed cloud infrastructure that executes whether or not your machine is on, with no local file access. They require a Pro, Max, Team, or Enterprise plan with Claude Code on the web enabled, and are currently in research preview . Use loops for interactive polling; use routines for work that must survive a shutdown.

Does /goal guarantee the goal condition is actually met?

No. Each time Claude tries to stop, a separate small evaluator model checks the condition and sends Claude back to work until the goal is met or a turn cap is reached. The catch: that evaluator does not run tools or read files independently—it judges only from the evidence Claude surfaces in the transcript . Deterministic, quantitative stop conditions—a test pass rate, a Lighthouse score above a threshold—are reliable. Qualitative goals like "looks polished" are not, because they leave the "good enough" judgment call intact .

What Claude Code version do I need for dynamic workflows?

Dynamic workflows reached general availability on May 28, 2026 and require v2.1.154 or later . The Large workflow warning and per-session Ultracode (/effort ultracode) need v2.1.203 or later . The adjacent primitives arrived earlier: /goal was added May 11, 2026 and needs v2.1.139 or later, while /loop needs v2.1.72 or later .

Can I run a dynamic workflow overnight unattended?

No—workflows are session-scoped. Runs are resumable within a session, where completed agents return cached results, but exiting Claude Code restarts a workflow fresh; nothing persists across sessions . For overnight, cloud-persisted execution, use routines instead: they run on Anthropic infrastructure whether or not your machine is on . A practical pattern is to have a routine trigger the work on schedule and let a workflow handle the parallel fan-out within each run.

How many sub-agents can a dynamic workflow run at once?

A workflow runs up to 16 agents concurrently—fewer on low-CPU machines—with a hard cap of 1,000 agents total per run. A "Large workflow" warning fires when a run schedules more than 25 agents or projects past 1.5 million tokens (v2.1.203 or later), and the /config size guideline classes runs as small (fewer than 5), medium (fewer than 15), or large (fewer than 50) agents . Because runs can consume substantially more tokens than a typical session, pilot at a small class before scaling up .

Enjoyed this article? Subscribe to get new stories by email whenever they're published.

Subscribe