Getting started with loops
02:00 · June 30, 2026 · Claude Blog

Summary
Loops in Claude Code are defined as agents that repeat cycles of work until a stop condition is met. Rather than relying solely on single prompts, developers design these repeating structures to handle iterative tasks in a controlled way. The approach distinguishes several loop types—turn-based, goal-based, time-based, and proactive—each suited to different workflow requirements. Not every coding task benefits from added complexity, so the recommendation is to begin with the simplest pattern that meets the need.
Turn-based loops advance one interaction at a time, making them appropriate when human oversight is required between steps. Goal-based loops continue until a specified objective is reached and are invoked through commands such as /goal. Time-based loops run for a defined duration or number of cycles, while proactive loops initiate work without explicit triggers once conditions are satisfied. Each type includes corresponding command examples, including /loop, that let users select the behavior directly within the Claude Code environment.
To preserve code quality during extended runs, the guidance stresses explicit stop conditions and regular review points. Token consumption is managed by limiting context growth across cycles and by breaking larger tasks into smaller, verifiable segments. These practices help keep automated sessions predictable and within practical resource limits.
Why it matters
It provides highly actionable, technical guidance for product teams and builders on how to implement and manage autonomous AI coding agents using Claude Code. The practical examples and token management strategies are directly applicable to Dutch AI engineering teams looking to optimize their development workflows.


