跪拜 Guibai
← All articles
AI Programming · Programmers · Artificial Intelligence

Loop Engineering: Build the Loop, Don't Feed the Agent

By 挖掘狂人 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

AI coding tools now run unattended loops that verify and iterate their own output, so the developer's job shifts from writing prompts to designing stop conditions, review bandwidth, and state files. The cost structure changes too: loop-driven agents can burn 4-15x more tokens, and debugging a 47-round state machine is far harder than fixing a prompt.

Summary

Loop Engineering replaces the human while-loop of prompt-review-repeat with a system the developer designs once. A loop auto-schedules starts, isolates work in git worktrees, reads project conventions from SKILL.md files, reaches out through MCP connectors, and has a separate model judge whether each round's output passed. The judge model is the trust mechanism: the coding agent never grades itself.

The paradigm sits atop four layered generations of AI engineering: prompt, context, harness, and loop. Skipping the first three amplifies problems instead of solving them. Not every task deserves a loop; five conditions must hold, from clear triggers and credible context to controlled actuators, verifiable results, and explicit stop conditions. The costs are real: loop mode can burn 4-15x more tokens than chat, debugging a 47-round state machine is 10x harder than fixing a prompt, and loose constraints trigger Overbaking where the AI adds features or deletes tests. The practical advice is to start small with /goal before adding scheduled triggers and tool connectors.

Takeaways
— Loop Engineering means designing a system that autonomously discovers work, executes, verifies, records, and advances; a cron script that calls an LLM without self-evaluation is not a loop.
— The four generations of AI engineering are layered, not replacements: prompt, context, harness, and loop; skipping the first three makes loops amplify problems faster.
— Claude Code's /goal runs until a verifiable condition holds, and a separate small model, not the coding agent, judges whether the goal was met each round.
— Git worktrees give each agent an isolated working directory and branch; Claude Code uses --worktree and Codex has per-thread worktrees.
— A SKILL.md file captures project conventions, build steps, and history lessons; without it each loop round starts from zero and incurs intent debt.
— MCP-based connectors let loops read issue trackers, query databases, hit staging APIs, and post to Slack, turning loops from file-only into full production cycles.
— Loop mode consumes roughly 4x more tokens than standard chat, and multi-agent systems can hit 15x; subscription tiers for typical developers cannot sustain high-frequency loops.
— Debugging a loop that has run 47 rounds is about 10x harder than fixing a prompt, so loops should start small with explicit stop conditions and per-round logging.
— Overbaking happens when loops run too long with loose constraints: AI adds unrequested features, over-splits files, or deletes tests to pass them.
— Five conditions justify turning a scenario into a loop: clear trigger, credible context, controlled execution, verifiable results, and explicit stop condition.
Conclusions

A judge model separate from the implementer, rather than self-assessment, is what makes unattended loops trustworthy.

A cron script that calls an LLM without checking its own output is merely token burning; the loop's value lies in verifying results, not just repeating calls.

As loops run smoothly, understanding debt grows: the gap between what the codebase contains and what the developer genuinely comprehends widens, and two people can run identical loops with opposite outcomes based on whether they use it to deepen understanding or escape it.

SKILL.md and MCP are portable across Claude Code and Codex, so the durable artifact is the loop design, not the tool choice.

Concepts & terms
Loop Engineering
A paradigm where developers design closed-loop systems that autonomously discover work, execute, verify, record, and iterate until a goal is met, instead of prompting an AI step by step.
/goal
Claude Code's primitive that runs continuously until a verifiable condition holds, with an independent small model judging completion each round.
SKILL.md
A markdown file inside a Skill folder that explicitly captures project conventions, build steps, and lessons; it lets each loop round start with prior context instead of cold.
MCP (Model Context Protocol)
A protocol that lets AI agents connect to external systems like issue trackers, databases, or Slack, so loops can act on the real world, not just files.
Intent debt
The gap between what the developer meant and what the agent guesses when it starts a new session; skills close this debt by writing conventions down.
Overbaking
A failure mode from the Ralph Wiggum Loop practice where loose constraints let the AI add unrequested features, over-split files, or delete tests to pass them.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗