資料來源#
- Anthropic's Boris Cherny: Why Coding Is Solved, and What Comes Next
- Full Walkthrough: Workflow for AI Coding — Matt Pocock
- How Anthropic's product team moves faster than anyone else | Cat Wu (Head of Product, Claude Code)
摘要#
迴圈是會重複執行提示的 agent 程序,直到佇列清空或達到停止條件。到 2026 年年中,三種逐漸匯流的實作顯示,迴圈正成為與單次工作階段同等地位的原語:Anthropic 的 /loop 斜線指令(以 cron 排程、重複執行)、Anthropic 的 routines(伺服器端的 /loop),以及 Matt Pocock 的 Ralph Wiggum loop(在 while 中以 bash 加上 claude --permission-mode accept-edits 執行)。Boris Cherny 稱迴圈是「未來」;Matt Pocock 將其作為端到端工作流程的 AFK 骨幹。
兩類迴圈#
由 cron 排程的迴圈(/loop、routines)#
在 Claude Code 與 Cowork 中使用。機制是:agent 透過工具呼叫 cron,將工作排程到未來某個時間;到了指定時間,該工作會帶著執行任務的指示重新進入 agent。排程可以重複執行(每分鐘、每 5 分鐘、每天)。
Boris Cherny 回報的用途:
- 照看 PR — 修復 CI、自動 rebase
- 維持 CI 健康 — 修復不穩定的測試
- 每 30 分鐘彙整 Twitter 回饋
- 「任何時候都有幾十個迴圈在執行」
- 夜間:「幾千個 agents」進行更深入的工作
Routines 是伺服器上的同一種原語,因此即使關閉筆電也能持續運作。
消化待辦清單的迴圈(Ralph Wiggum loop)#
由 Matt Pocock 等人使用。機制是:shell script 以固定提示執行 agent;提示要求 agent 從待辦清單挑選下一個任務並完成;script 隨後重新啟動。待辦清單是由 markdown issue 檔案(或 GitHub issues)組成的目錄。
Pocock 的 once.sh 骨架:
issues=$(cat issues/*.md)
recent_commits=$(git log -5 --oneline)
prompt=$(cat prompt.md)
claude --permission-mode accept-edits "$prompt" --context "$issues" "$recent_commits"「迴圈」包裝器只會反覆執行 once.sh,直到 agent 輸出 sentinel(no more tasks)或 harness 停止它。
提示會強制採用 AFK-only task selection — 只有標記為 AFK 的任務(相對於 human-in-loop)才符合資格。
迴圈為何重要#
- 將規劃成本攤銷到多次執行。 一次謹慎的規劃工作階段(例如透過 Design Concept Grilling)建立 Kanban 待辦清單(見 Vertical Slice Tracer Bullets);迴圈能在不需進一步人工輸入的情況下消化它。
- 數小時的任務變得可處理。 迴圈不是使用一個巨大的 context window,而是將工作切分成許多全新的工作階段,每次都維持在 Context Window Smart Zone 內。
- 平行化。 獨立的待辦項目會在不同的 sandbox 中同時執行。Pocock 的 Sandcastle library 透過 Docker containers 中每個 issue 專用的 git worktree 實現這點;之後由 merger agent 進行協調。
- 閒置運算。 Boris 的夜間配置是在便宜的閒置時段運行千 agent 迴圈——這些工作不值得人類花一晚處理,卻能以 agent 成本產生價值。
AFK 與 human-in-loop 任務#
Matt Pocock 的關鍵區分:
- AFK tasks — 實作、重構、測試腳手架、文件維護、CI 修復。agent 不需逐步核准也能成功;驗證是自動的(測試、型別、linters)。
- Human-in-loop tasks — 對齊、設計選擇、優先順序、QA。這些沒有機械式驗證;需要品味與默會脈絡。
迴圈適用於 AFK 類別。試圖讓 human-in-loop 工作進入迴圈會產生偏移——agent 會做出看似合理卻錯誤的決定,並逐步累積這些錯誤。
驗證是上限#
Pocock 更強的主張是:回饋迴圈的品質,決定迴圈能做到什麼的上限。 沒有好的測試、型別與 linters,迴圈就是「盲目寫程式」。這與 Agent Harness Engineering 對機械式強制的論點相同——只是迴圈更鮮明地暴露了成本,因為沒有人工捕捉偏移。
與模型軌跡的連結#
Boris Cherny 回報,Opus 4.7 會在沒有提示的情況下自發開始迴圈:
「我會告訴它:『去抓取這個資料查詢。』然後它會說:『嘿,我注意到資料會隨時間變化。我會開始一個迴圈,每 30 分鐘給你一份報告。』」
這符合 Harness Shrinkage as Models Improve——過去需要由 harness 注入的能力,會變成模型的自然行為。迴圈原語仍然存在,但使用者不再需要親自呼叫它。
相關連結#
- Claude Code Best Practices — 最佳實務指南將
/loop視為核心工作流程原語 - Engineer PM Convergence — 通才 PM-engineers 透過迴圈將工作扇出
- Boris Cherny — 主要倡議者,也是日常驅動者
- Matt Pocock — Ralph loop 與 Sandcastle 的典範
- Harness Shrinkage as Models Improve — 迴圈作為取代逐步提示的下一代原語
- Context Window Smart Zone — 為何切分成許多全新工作階段勝過一個漫長工作階段
- Vertical Slice Tracer Bullets — 迴圈所消化的待辦清單由什麼填滿
- Design Concept Grilling — 證成迴圈合理性的規劃步驟
- Deep Modules for Agents — 具備強大測試邊界的模組,讓迴圈得以運作
- Agent Harness Engineering — 將「驗證是上限」的論點一般化
- Symphony — 編排層中由 daemon 驅動的等價方案
- Claude Code Auto Mode — 讓
accept-edits模式在 AFK 迴圈中安全運作的權限分類器 - Agentic Misalignment (AM) — 迴圈加上薄弱的逐行動監督,正是 AM 的威脅面;迴圈審查者仰賴模型端的對齊能在無人看管時持續成立
- AI Brain Fry — 輸出倍增器在人類端的限制:更多迴圈輸出 → 更多審查 → 更多認知疲勞 → 更多漏掉的錯誤
- Human-AI Accountability Redesign — 迴圈迫使我們重新設計責任;控制幅度的重新設計,是無人看管迴圈部署所缺少的搭檔
- AI-Driven Formal Proof Search — DeepMind 的基本 proof-search agent 實際上就是「Ralph loop」(huntley2025ralph):由 generate→compile→learn-lessons 組成的 episodes,作為平行獨立 subagents 執行
- AlphaProof Nexus — 其基本 agent (A) 是 Ralph-loop fleet;它在大多數問題上匹配了客製系統
- Agent-Native Infrastructure — 透過 sensors/actuators 行動的常駐迴圈,是 Karpathy agent-native 世界的 runtime
- Loop Engineering — 位於此原語上一層的系統設計學科(Osmani / Steinberger):automations 是迴圈排程的心跳,而
/goal(持續執行直到書面條件成立,並在每次 turn 後由獨立的小模型檢查「完成」)則是將 maker/checker 分工套用到停止條件本身 - The Three Loops of AI-Native Building — Andrew Ng 的分類將此原語定位為:它完成三個巢狀迴圈中最內層的那一個,而外側的開發者回饋與外部回饋迴圈,速度慢 1–2 個數量級
開放問題#
- 當模型自行排程迴圈(4.7 行為)時,誰擁有預算?Boris 的回答是「模型自己決定」——但這會把成本紀律推入模型的訓練,而不是 harness。
- 如果模型夠聰明,迴圈是否仍需要 Kanban 待辦清單,還是模型會從原始目標中選擇自己的下一個任務?
- 迴圈輸出的審查現在是 Matt Pocock 自承的瓶頸——「我們只需要準備好進行更多 code review。」
資料來源#
- Anthropic's Boris Cherny: Why Coding Is Solved, and What Comes Next —
/loop與 routines 作為主要原語 - Full Walkthrough: Workflow for AI Coding — Matt Pocock — Ralph loop + Sandcastle 架構
- How Anthropic's product team moves faster than anyone else | Cat Wu (Head of Product, Claude Code) — 功能層級的迴圈(CI 修復、code review)
Cited by 31
- Learning to Co-Work with AI: A Software Engineer's Field Guide×6
Adopt the AFK vs human-in-loop split (Agent Loop Pattern). AFK tasks (implementation, refactoring,…
- Agent Control Plane Patterns: Tickets, Loops, Specs, and Memory Files×4
Agent Loop Pattern is necessary but not sufficient. A loop is an execution pattern: repeat a prompt…
- Harness Shrinkage as Models Improve×4
Ai Brain Fry — partially mitigated by harness shrinkage (less to oversee), reintroduced by output…
- Claude Code Best Practices×3
Loops and routines: /loop (cron-scheduled repeat job, in-CLI) and routines (server-side variant).…
- Loop Engineering×3
Automations — scheduled discovery + triage that run by themselves. The heartbeat that makes a loop…
- Open Questions Backlog×3
Agent Loop Pattern: Loop output review is now Matt Pocock's confessed bottleneck — "we just need to…
- The Three Loops of AI-Native Building×3
"This is an active area of invention!" — which is Loop Engineering and Agent Loop Pattern in their…
- Agentic Misalignment (AM)×2
This describes Cowork, Claude Code in agent mode (especially --dangerously-skip-permissions),…
- AI Brain Fry×2
Agent Loop Pattern — loops are an aggressive output multiplier; brain fry is the human-side limit…
- Opinions on Using AI Tools & the Future of the Software Engineering Role×2
Capabilities migrate inward. The /loop primitive (see Agent Loop Pattern) went from harness feature…
- Boris Cherny×2
Loops as the future. Heavy user of /loop (Claude-scheduled cron jobs) for PR babysitting, CI…
- Claude Code×2
/loop — Claude-scheduled cron job; primary primitive of Agent Loop Pattern
- Context Window Smart Zone×2
Fragment work into many sessions. Loops (see Agent Loop Pattern) and vertical slices (see Vertical…
- Human-AI Accountability Redesign×2
Agent Loop Pattern — loops increase agent output volume per human; the span-of-control redesign in…
- Vertical Slice Tracer Bullets×2
The Kanban is materialized as markdown files in issues/ (or GitHub issues) with explicit…
- Agent Harness Engineering
Agent Loop Pattern — the natural session-level primitive once the per-session harness works: drain…
- Agent-Native Infrastructure
Agent Loop Pattern — always-on agents acting via sensors/actuators are the runtime of an…
- Agentic Loops Overtake Bespoke Systems
Agent Loop Pattern — the "Ralph loop" basic agent is an instance of the loop-as-primitive
- AI-Driven Formal Proof Search
Agent Loop Pattern — the basic prover subagent is literally a "Ralph loop" (huntley2025ralph)
- AlphaProof Nexus
Agent Loop Pattern — the basic prover subagent is a "Ralph loop" (huntley2025ralph)
- Claude Code Auto Mode
Agent Loop Pattern — auto mode is a precondition for AFK loops; without it, every tool call would…
- Claude Opus 4.7
Agent Loop Pattern — /loop becomes natural model behavior at 4.7 per Boris Cherny's report
- Deep Modules for Agents
Agent Loop Pattern — review-in-fresh-context fits the loop's clear-then-restart rhythm
- Design Concept Grilling
Agent Loop Pattern — grilling sits at the human-in-loop top of the funnel; loop drains the AFK…
- Dynamic Workflows: An Algebra for Agents
The split is the loop primitive's question ("when does it run again?") versus this page's question…
- Engineer PM Convergence
Agent Loop Pattern — at the limit, individual contributors run dozens of agents and ship like teams…
- Matt Pocock
Independent AI-coding educator; built Sandcastle library; smart-zone/grill-me/tracer-bullets pedagogical framing; "bad…
- Agent Systems & Harness Engineering
Agent Loop Pattern — /loop (cron-scheduled) and Ralph Wiggum (backlog-draining) loops as…
- Peter Steinberger
Founder of PSPDFKit turned prolific independent AI-coding experimenter (@steipete); originated the framing that loop en…
- Stopping Under a Noisy Verifier
Agent Loop Pattern — the loop primitive whose stopping condition is a sentinel or a round cap; the…
- Symphony
Agent Loop Pattern — the daemon-driven equivalent at the orchestration layer; Symphony is…
Related articles
- Agent Harness Engineering
Patterns for scaffolding long-running LLM agents: environment design, progressive context disclosure, mechanical archit…
- Harness Shrinkage as Models Improve
Prompt scaffolding shrinks each model release; Cat Wu's pruning discipline; Boris Cherny "100 lines of code a year from…
- Claude Code
Anthropic's agentic coding product; created by Boris Cherny late 2024; TypeScript/React on Bun (itself Claude-rewritten…
- Loop Engineering
Replacing yourself as the agent's prompter by designing the system that prompts it: a recursive-goal loop built from fi…
- Verification as the New Bottleneck
Fiona Fung: coding is no longer the bottleneck — verification, review, maintenance are; shift-left; TDD loses its tax;…
