Getting started with loops
Claude Code · Essay · 2026-06-30

Getting started with loops

上手智能体循环(loop)
Learn how the Claude Code team defines agentic loops, with practical guidance on progressing from turn-based to goal-based, time-based, and proactive loops—and when to use each.

了解 Claude Code 团队如何定义 agentic loop(智能体循环),并获得从逐轮(turn-based)进阶到目标驱动(goal-based)、定时(time-based)与主动(proactive)循环的实操指引——以及各自何时使用。
来源:Claude 官方博客(claude.com/blog)· 2026-06-30 · 约 1,000 词 · 7 章 · 全文双语对照 · 作者 Delba de Oliveira & Michael Segner
TL;DR · 速读

Six things to take away

  1. Loops = agents repeating cycles of work until a stop condition is met.

    loop 就是 agent 反复循环工作,直到满足停止条件。

    Claude Code 团队按四个维度区分 loop:如何触发、如何停止、用哪个原语、适合哪类任务。

  2. Turn-based → goal-based → time-based → proactive.

    四种 loop 由浅入深,不是所有任务都要复杂 loop。

    从最简单的方案入手,有选择地使用这些模式;先别过度设计。

  3. You can improve verification by encoding your manual steps as a SKILL.md.

    逐轮 loop 里,把手动步骤写成 skill 能提升自我验证。

    检查越量化(测试数、分数阈值),Claude 越容易自查,轮次越少。

  4. /goal lets an evaluator model keep Claude working until done.

    /goal 定义"完成",评估模型盯着它做到目标或撞轮次上限。

    Claude 不必自行判断"够好了没"而提前收工;确定性标准最有效。

  5. /loop runs locally; /schedule moves the loop to the cloud.

    定时 loop:/loop 跑本地,/schedule 搬云端做成 routine。

    适合周期性工作或对接外部系统;拉长间隔或改成事件驱动来省用量。

  6. Compose primitives + auto mode + workflows for proactive loops.

    主动 loop 把各原语 + auto mode + dynamic workflows 组合成无人值守流。

    质量靠周边系统(整洁代码库、第二个 review agent);控量靠清晰边界与选对模型。

There's a lot of talk right now about "designing loops" instead of prompting your coding agent. If you spend some time on X trying to pin down what a loop actually is, you'll come across multiple different answers.

眼下有很多关于"设计循环(loop)"而非直接给编码 agent 写 prompt 的讨论。如果你花点时间在 X 上想弄清 loop 到底是什么,会遇到五花八门的答案。

On the Claude Code team, we define loops as agents repeating cycles of work until a stop condition is met. We categorize a few different types of loops based on:

在 Claude Code 团队,我们把 loop 定义为:agent 不断重复一轮轮工作,直到满足某个停止条件。我们按以下几个维度来区分不同类型的 loop:

We'll cover the main loop types, when to use each, and how to maintain code quality while managing token usage. Not all tasks require complex loops; start with the simplest solution and use these patterns selectively.

我们会讲清主要的 loop 类型、各自何时使用,以及如何在控制 token 用量的同时保持代码质量。并非所有任务都需要复杂的 loop;从最简单的方案入手,有选择地使用这些模式。

Chapter 01

Turn-based loops

逐轮循环 · 你指挥每一轮
agentic loop · SKILL.md · 手动验证
Turn-based loop illustration
Triggered by · 触发方式

A user prompt.

一条用户 prompt。

Stop criteria · 停止条件

Claude judges it has completed the task or needs additional context.

Claude 判断任务已完成,或需要更多上下文。

Best used for · 最适合

Shorter tasks that are not part of a regular process or schedule.

不属于常规流程或排期的较短任务。

Managed usage by · 控量方式

Write specific prompts and improve verification using skills to reduce the number of turns.

写具体的 prompt,并用 skill 改进验证,以减少轮次。

Every prompt you send starts a manual loop with you directing each turn. Claude gathers context, takes action, checks its work, repeats if needed, and responds. We call this the agentic loop.

你发出的每一条 prompt 都会启动一个由你指挥每一轮的手动 loop。Claude 收集上下文、采取行动、检查自己的成果、必要时重复,然后给出回复。我们称之为 agentic loop(智能体循环)。

For example, ask Claude to create a like button. It reads your code, makes the edit, runs the tests, and hands back something it believes works. You then manually check the work, and write the next prompt.

举个例子,让 Claude 做一个点赞按钮。它会读你的代码、做出修改、运行测试,然后交回一个它认为能用的成果。接着由你手动检查,再写下一条 prompt。

You can improve the verification step by encoding your manual steps as a SKILL.md so Claude can check more of its own work, end-to-end. (For choosing between skills, hooks, and subagents for this kind of automation, see our guide to steering Claude Code.)

你可以把手动步骤固化成一个 SKILL.md 来改进验证环节,让 Claude 能端到端地检查更多自己的工作。(在这类自动化中如何在 skill、hook 和子 agent 之间取舍,见我们的《steering Claude Code》指南。)

This should include tools or connectors to allow Claude to see, measure or interact with the result. The more quantitative the checks are, the easier it is for Claude to self-verify.

这里应当包含让 Claude 能看到、测量或与结果交互的工具或连接器(connector)。检查越量化,Claude 就越容易自我验证。

For example, in your SKILL.md file you may specify:

例如,你的 SKILL.md 文件里可以这样写:

---
name: verify-frontend-change
description: Verify any UI change end-to-end before declaring it done.
---

# Verifying frontend changes
Never report a UI change as complete based on a successful edit alone. Verify it the way a human reviewer would:

1. Start the dev server and open the edited page in the browser.

2. Interact with the change directly. For a new control (button, input, toggle): click it, confirm the expected state change, and screenshot before/after.

3. Check the browser console: zero new errors or warnings.

4. Use the Chrome Devtools MCP, run a performance trace and audit Core Web Vitals.

If any step fails, fix the issue and rerun from step 1 — do not hand back partially verified work.
Chapter 02

Goal-based loop (/goal)

目标驱动循环 · 定义"完成"
/goal · 评估模型 · 确定性退出标准
Goal-based loop illustration
Triggered by · 触发方式

A manual prompt in real-time.

实时手动输入的一条 prompt。

Stop criteria · 停止条件

Goal achieved OR maximum number of turns reached.

目标达成,或达到最大轮次上限。

Best used for · 最适合

Tasks that have verifiable exit criteria.

具有可验证退出标准的任务。

Managed usage by · 控量方式

Setting a specific completion criteria and explicit turn caps, "stop after 5 tries."

设定具体的完成标准和明确的轮次上限,比如"试 5 次后停止"。

Sometimes, a single turn is not enough, especially for more complex tasks. Agents do better when they can iterate. You can extend how long Claude keeps iterating by defining what done looks like with /goal.

有时一轮并不够,尤其是较复杂的任务。agent 在能够迭代时表现更好。你可以用 /goal 定义"完成"是什么样子,从而延长 Claude 持续迭代的时间。

When you define the success criteria, Claude doesn't have to make a determination on what is "good enough" and end the loop early. Each time Claude tries to stop, an evaluator model checks your condition and sends it back to work until the goal is met or a number of turns you define is reached.

当你定义了成功标准,Claude 就不必自行判断怎样才算"足够好"而提前结束 loop。每当 Claude 想要停止,一个评估模型(evaluator model)都会核对你的条件,并把它送回去继续工作,直到目标达成、或达到你设定的轮次上限。

This is why deterministic criteria, such as number of tests passed or clearing a certain score threshold, are so effective.

这正是为什么确定性的标准——比如通过的测试数量,或跨过某个分数阈值——如此有效。

For example:

例如:

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

Time-based loop (/loop and /schedule)

定时循环 · 按间隔重跑
/loop · /schedule · 周期性工作 · 对接外部系统
Triggered by · 触发方式

A specified time interval.

指定的时间间隔。

Stop criteria · 停止条件

You cancel it, or the work completes (the PR merges, the queue is empty).

你取消它,或工作完成(PR 合并、队列清空)。

Best used for · 最适合

For recurring work, or interfacing with external environments / systems.

周期性重复的工作,或与外部环境 / 系统对接。

Managed usage by · 控量方式

Set longer intervals or react based on events rather than time.

拉长间隔,或改为基于事件(而非时间)来响应。

Some agentic work is recurring: the task stays the same and only the inputs change. For example, summarizing Slack messages every morning. Other work depends on external systems, and a simple way to interface with one is to check it on an interval and react to what changed. For example, a PR which may receive code reviews or fail CI.

有些 agent 工作是周期性的:任务不变,只有输入在变。比如每天早上汇总 Slack 消息。另一些工作依赖外部系统,而与外部系统对接的一个简单办法,就是按间隔去检查它,并对变化做出反应。比如一个可能收到 code review 或 CI 失败的 PR。

For these, you can trigger when Claude runs with /loop which re-runs a prompt on an interval. For example:

对这类工作,你可以用 /loop 来控制 Claude 何时运行——它会按间隔重跑一条 prompt。例如:

/loop 5m check my PR, address review comments, and fix failing CI

/loop runs on your computer, so if you turn it off, it stops. You can move the loop to the cloud by creating a routine with /schedule.

/loop 跑在你自己的电脑上,所以一旦你关掉它,它就停了。你可以用 /schedule 创建一个 routine,把 loop 搬到云端。

Chapter 04

Proactive loops

主动循环 · 无人值守的组合
auto mode · dynamic workflows · 事件 / 排期触发
Proactive loop illustration
Triggered by · 触发方式

An event or schedule, with no human in real time.

由事件或排期触发,过程中没有人实时参与。

Stop criteria · 停止条件

Each task exits when its goal is met. The routine itself runs until you turn it off.

每个任务在目标达成时退出;routine 本身则一直运行,直到你关掉它。

Best used for · 最适合

Recurring streams of well-defined work: bug reports, issue triage, migrations, dependency upgrades, etc.

定义明确、源源不断的重复性工作流:bug 上报、issue 分诊、代码迁移、依赖升级等。

Managed usage by · 控量方式

Routing routines to smaller, faster models and using the most capable model for judgment calls.

把 routine 路由到更小更快的模型,只在需要判断的关键环节用最强的模型。

The primitives above, along with other Claude Code features like auto mode and dynamic workflows (research preview) can be composed into a loop for long-running work.

上面这些原语,连同 Claude Code 的其他特性——比如 auto modedynamic workflows(研究预览版)——可以组合成一个用于长时间运行工作的 loop。

For example, to handle incoming feedback, you can use:

例如,要处理持续涌入的反馈,你可以用:

  • /schedule (research preview) to run a routine that checks for new reports/schedule(研究预览版):运行一个 routine,检查是否有新的上报。
  • /goal to define what done looks and skills to document how to verify it/goal:定义"完成"的样子;并用 skill 记录如何验证。
  • Dynamic workflows to orchestrate agents that triage each report, fix it, and review the fixDynamic workflows:编排多个 agent 去分诊每条上报、修复它、并复查修复。
  • Auto mode so the routine runs without stopping to ask for permissionAuto mode:让 routine 无需停下来请求权限即可运行。

Putting it together, a prompt could look like this:

把它们拼在一起,一条 prompt 可能长这样:

/schedule every hour: check #project-feedback for bug reports. /goal: don't stop until every report found this run is triaged, actioned, and responded to. When fixing a bug, use a workflow to explore three solutions in parallel worktrees and have a judge adversarially review them.
Chapter 05

Maintaining code quality

保持代码质量 · 打磨周边系统
整洁代码库 · 自我验证 · 第二个 review agent

The quality of a loop's output depends on the system around it. When designing the system:

一个 loop 产出的质量,取决于它周围的这套系统。设计这套系统时:

  • Keep the codebase itself clean: Claude follows patterns and conventions that already exist in your codebase.保持代码库本身整洁:Claude 会沿用你代码库里已有的模式和约定。
  • Give Claude a way to verify its own work: Encode what good looks like for you and your team with skills.给 Claude 一条自我验证的路径:用 skill 把"对你和团队而言什么才算好"固化下来。
  • Make docs easy to reach: Frameworks and libraries docs have up-to-date best practices.让文档触手可及:框架和库的文档里有最新的最佳实践。
  • Use a second agent for code reviews: A reviewer with fresh context is less biased and not influenced by the main agent's reasoning. You can use the built-in /code-review skill or Code Review for Github.用第二个 agent 做 code review:一个上下文全新的审查者偏见更少,也不受主 agent 推理过程的影响。你可以用内置的 /code-review skill,或用于 GitHub 的 Code Review

When an individual result doesn't meet the standard, don't stop at fixing the individual issue, try to encode it to improve the system for all future iterations.

当某个单独的结果不达标时,别止步于修好这一个问题——试着把它固化下来,为将来所有的迭代改进整个系统。

Chapter 06

Managing token usage

管好 token 用量 · 划清边界
选对原语与模型 · 先试点 · 用脚本 · /usage

To manage token usage, loops should have clear boundaries:

要管好 token 用量,loop 应当有清晰的边界:

  • Choose the right primitive and model for the job: Smaller tasks don't need multiple agents or loops. Some tasks can use cheaper and faster models.为任务选对原语和模型:小任务不需要多个 agent 或 loop;有些任务可以用更便宜、更快的模型。
  • Define clear success and stop criteria: Be specific about what done looks like so Claude can arrive at the solution sooner (but not too soon).定义清晰的成功与停止标准:把"完成"的样子说具体,好让 Claude 更快(但别太快)抵达解决方案。
  • Pilot before a large run: Dynamic workflows can spawn hundreds of agents. Gauge usage on a smaller slice of the work first.大规模跑之前先试点:dynamic workflows 可能派生出数百个 agent,先在一小块工作上估算用量。
  • Use scripts for deterministic work: Running a script is cheaper than reasoning through the steps. For example, a PDF skill can ship a form-filling script that Claude runs each time, instead of re-deriving the code.确定性工作用脚本:跑一个脚本比一步步推理便宜。比如一个 PDF skill 可以自带一个填表脚本,让 Claude 每次直接运行,而不必重新推导代码。
  • Don't run routines more often than you need to: Match the interval to how often the thing you're watching changes.routine 别跑得比需要的更勤:让间隔匹配你所关注的东西实际变化的频率。
  • Review usage: The /usage command breaks down recent usage by skills, subagents, and MCPs, /goal with no arguments shows number of turns and token usage so far, /workflows shows each agent's token usage and you can stop an agent at any time.审视用量:/usage 命令会按 skill、子 agent 和 MCP 拆解近期用量;不带参数的 /goal 会显示目前的轮次和 token 用量;/workflows 会显示每个 agent 的 token 用量,而且你随时可以停掉某个 agent。
Chapter 07

Getting started

如何上手 · 从你已有的工作里挑一件
总结表 · 找瓶颈 · 跑起来再迭代

To summarize:

总结一下:

Loop循环类型 You hand off你交出去的 Use it when何时使用 Reach for用什么
Turn-based逐轮 The check检查(验证) You're exploring or deciding你在探索或做决定 Custom verification skills自定义验证 skill
Goal-based目标驱动 The stop condition停止条件 You know what done looks like你清楚"完成"长什么样 /goal/goal
Time-based定时 The trigger触发 The work happens outside your project on a schedule工作在你项目之外、按排期发生 /loop, /schedule/loop、/schedule
Proactive主动 The promptprompt(整条指令) The work is recurring and well-defined工作是周期性且定义明确的 All of the above, and dynamic workflows以上全部,外加 dynamic workflows

To get started with loops, look at the work you already do. Pick one task where you're the bottleneck and ask which piece you could hand off: can you write the verification check? Is the goal clear enough? Does the work arrive on a schedule?

要上手 loop,先看看你已经在做的工作。挑一个你正是瓶颈的任务,问问自己哪一块可以交出去:你能写出那个验证检查吗?目标是否足够清晰?这份工作是否按某个排期到来?

Once you have an idea, run the loop, observe the results like where it stalls or over-reaches, and don't be afraid to iterate on it.

一旦有了想法,就把 loop 跑起来,观察结果——比如它在哪里卡住、在哪里用力过猛——并且别怕反复迭代它。

For more information, read the Claude Code docs on running agents in parallel, as well as the loop, schedule, goal, and dynamic workflows pages.

想了解更多,可以阅读 Claude Code 文档中关于并行运行 agent 的部分,以及 loopschedulegoaldynamic workflows 各页面。

This article was written by Delba de Oliveira and Michael Segner.
本文由 Delba de Oliveira 与 Michael Segner 撰写。