<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Michael Segner on Jinnchang</title><link>https://jinnchang.github.io/authors/michael-segner/</link><description>Recent content in Michael Segner on Jinnchang</description><generator>Hugo</generator><language>en</language><lastBuildDate>Tue, 30 Jun 2026 20:45:11 +0800</lastBuildDate><atom:link href="https://jinnchang.github.io/authors/michael-segner/index.xml" rel="self" type="application/rss+xml"/><item><title>Getting Started With Loops</title><link>https://jinnchang.github.io/reads/getting-started-with-loops/</link><pubDate>Tue, 30 Jun 2026 20:45:11 +0800</pubDate><guid>https://jinnchang.github.io/reads/getting-started-with-loops/</guid><description>&lt;blockquote&gt;
&lt;p&gt;了解 Claude Code 团队如何定义代理循环，以及从回合制循环到目标驱动、时间驱动和主动式循环的实践指南——还有何时使用每种循环。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;现在有很多关于&amp;quot;设计循环&amp;quot;而非提示你的编码代理的讨论。如果你在 X 上花些时间试图弄清楚循环到底是什么，你会发现多种不同的答案。&lt;/p&gt;
&lt;p&gt;在 Claude Code 团队，我们将&lt;strong&gt;循环定义为代理重复工作周期，直到满足停止条件&lt;/strong&gt;。我们根据以下维度对几种不同类型的循环进行分类：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;如何触发&lt;/li&gt;
&lt;li&gt;如何停止&lt;/li&gt;
&lt;li&gt;使用哪种 Claude Code 原语&lt;/li&gt;
&lt;li&gt;每种循环最适合什么类型的任务&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;我们将介绍主要的循环类型、何时使用每种循环，以及如何在管理 token 用量的同时保持代码质量。并非所有任务都需要复杂的循环；从最简单的方案开始，有选择地使用这些模式。&lt;/p&gt;
&lt;h2 id="回合制循环"&gt;
 回合制循环
 &lt;a class="heading-link" href="#%e5%9b%9e%e5%90%88%e5%88%b6%e5%be%aa%e7%8e%af"&gt;
 &lt;i class="fa-solid fa-link" aria-hidden="true" title="Link to heading"&gt;&lt;/i&gt;
 &lt;span class="sr-only"&gt;Link to heading&lt;/span&gt;
 &lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;&lt;img src="di.png" alt="图"&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;触发方式&lt;/strong&gt;：用户提示词。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;停止条件&lt;/strong&gt;：Claude 判断任务已完成或需要更多上下文。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;最适用于&lt;/strong&gt;：不属于常规流程或计划的较短任务。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;用量管理方式&lt;/strong&gt;：编写具体的提示词，并使用技能改进验证以减少回合数。&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;你发送的每一条提示词都会启动一个手动循环，由你指挥每个回合。Claude 收集上下文、采取行动、检查工作、必要时重复，然后回复。我们称之为代理循环。&lt;/p&gt;
&lt;p&gt;例如，让 Claude 创建一个点赞按钮。它会读取你的代码、进行编辑、运行测试，然后交出它&lt;em&gt;认为&lt;/em&gt;可用的结果。然后你手动检查工作，写下下一条提示词。&lt;/p&gt;
&lt;p&gt;你可以通过将手动步骤编码为 SKILL.md 来改进验证步骤，这样 Claude 就能端到端地检查更多自己的工作。（关于在技能、钩子和子代理之间选择哪种自动化方式，请参阅我们的&lt;a href="https://claude.com/blog/steering-claude-code-skills-hooks-rules-subagents-and-more" class="external-link" target="_blank" rel="noopener"&gt;驾驭 Claude Code 指南&lt;/a&gt;。）&lt;/p&gt;
&lt;p&gt;这应该包括让 Claude 能够&lt;em&gt;看到&lt;/em&gt;、&lt;em&gt;衡量&lt;/em&gt;或&lt;em&gt;交互&lt;/em&gt;结果的工具或连接器。检查越量化，Claude 就越容易自我验证。&lt;/p&gt;
&lt;p&gt;例如，在你的 SKILL.md 文件中，你可以指定：&lt;/p&gt;
&lt;div class="code-block"&gt;
 &lt;button
 class="copy-button"
 type="button"
 aria-label="Copy"
 &gt;
 &lt;svg
 class="copy-icon"
 xmlns="http://www.w3.org/2000/svg"
 width="16"
 height="16"
 viewBox="0 0 24 24"
 fill="none"
 stroke="currentColor"
 stroke-width="2"
 stroke-linecap="round"
 stroke-linejoin="round"
 aria-hidden="true"
 &gt;
 &lt;rect
 x="9"
 y="9"
 width="13"
 height="13"
 rx="2"
 ry="2"
 &gt;&lt;/rect&gt;
 &lt;path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"&gt;&lt;/path&gt;
 &lt;/svg&gt;
 &lt;svg
 class="check-icon"
 xmlns="http://www.w3.org/2000/svg"
 width="16"
 height="16"
 viewBox="0 0 24 24"
 fill="none"
 stroke="currentColor"
 stroke-width="2"
 stroke-linecap="round"
 stroke-linejoin="round"
 aria-hidden="true"
 &gt;
 &lt;polyline points="20 6 9 17 4 12"&gt;&lt;/polyline&gt;
 &lt;/svg&gt;
 &lt;/button&gt;
 &lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-plain" data-lang="plain"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;---
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;name: verify-frontend-change
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;description: Verify any UI change end-to-end before declaring it done.
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;---
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;# Verifying frontend changes
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;Never report a UI change as complete based on a successful edit alone. Verify it the way a human reviewer would:
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;1. Start the dev server and open the edited page in the browser.
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;2. Interact with the change directly. For a new control (button, input, toggle): click it, confirm the expected state change, and screenshot before/after.
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;3. Check the browser console: zero new errors or warnings.
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;4. Use the Chrome Devtools MCP, run a performance trace and audit Core Web Vitals.
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;If any step fails, fix the issue and rerun from step 1 — do not hand back partially verified work.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;h2 id="目标驱动循环goal"&gt;
 目标驱动循环（/goal）
 &lt;a class="heading-link" href="#%e7%9b%ae%e6%a0%87%e9%a9%b1%e5%8a%a8%e5%be%aa%e7%8e%afgoal"&gt;
 &lt;i class="fa-solid fa-link" aria-hidden="true" title="Link to heading"&gt;&lt;/i&gt;
 &lt;span class="sr-only"&gt;Link to heading&lt;/span&gt;
 &lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;&lt;img src="goal-based-loop-goal.png" alt="目标驱动循环"&gt;&lt;/p&gt;</description></item></channel></rss>