Hands‑On Loop Engineering with Claude Code and Fable 5: Practical Examples
This article walks through Claude Code’s Loop Engineering concepts—turn‑based, goal‑based, time‑based, and proactive loops—using concrete Fable 5 demos, detailed step‑by‑step instructions, and cost‑quality tips for building reliable AI‑driven automation.
0. Official definition of a Loop
Claude Code defines a Loop as an agent repeatedly executing work until a stop condition is met. Four Loop types are distinguished by trigger and stop condition: turn‑based, goal‑based, time‑based, and proactive.
1. Turn‑based: turning human verification into a skill
The basic daily workflow with Claude Code is a turn‑based loop: a human sends a prompt, Claude acts, the human reviews, and the cycle repeats. To automate verification, the human writes a verify‑ui‑change skill that encodes the acceptance criteria.
Case 1 demonstrates a static to‑do list page. The skill consists of five steps:
1. 启动本地服务,用浏览器工具打开页面
2. 真实操作改动的控件,截图before/after对比
3. 涉及持久化的改动,刷新页面确认状态保留
4. 浏览器console零新增报错
5. 任何一步失败,修复后从第1步重来,不交半成品In an A/B test, the author first disables the skill and lets Claude add a dark‑mode toggle, manually reviewing the result. Then the skill is re‑enabled and the same prompt is run again; Claude now starts the service, clicks the button, refreshes, and checks the console automatically. The author notes that the more quantifiable the verification, the easier Claude can self‑validate.
2. Goal‑based: using /goal to decide when to stop
The /goal command attaches an evaluation model that acts as a judge. Each time Claude wants to finish, the model checks the user‑defined conditions; if they are not met, the loop continues. Success criteria must be measurable, such as a Lighthouse score above 90.
Case 2 involves a date parser supporting ISO, US, and English formats with 12 pytest cases, three of which contain hidden bugs. The baseline passes 7 and fails 5. The /goal prompt is:
/goal python3 -m pytest的12个用例全部通过。只允许修改dateparse.py,不允许改动任何测试文件。最多尝试5轮。
The restrictions are crucial: prohibiting test changes prevents a shortcut where the goal is met by editing the tests, and limiting rounds controls token consumption. Typically the loop succeeds within a single round.
3. Time‑based: monitoring changing external states with /loop
When work depends on external systems (CI status, reviewer comments, queue length, model training progress), the simplest integration is periodic polling. The author’s example checks a pull request every five minutes, handling failed CI logs, fixing issues, and pushing updates until the CI is green and no comments remain.
/loop 每5分钟检查PR的CI状态:如果失败,读取失败日志,修复问题并push;有未处理的review评论就逐条处理;CI全绿且无未处理评论时停止。
The author warns against setting the interval too short (e.g., 30 seconds) because CI runs take about two minutes, leading to unnecessary token usage.
4. Proactive: combining triggers, goals, and static boundaries
The proactive loop is a composition of the previous three: /schedule defines the trigger, a goal description determines completion, and explicit permission boundaries restrict what the agent may modify. Human oversight is not required during execution.
Case 4 simulates a user‑feedback pipeline. A text‑tool library contains three hidden bugs; feedback arrives as markdown files in an inbox directory. The loop triages each report, fixes bugs, replies, and updates status. One report is a new requirement (Chinese word‑count support) that should not be implemented on the spot, serving as a test of the boundary rules.
5. Quality and cost considerations
For quality, any iteration that fails should not only be fixed for that round but also have the fix encoded back into the skill, goal description, or boundary rules so future rounds benefit automatically.
Cost monitoring is provided by three switches: /usage – shows token consumption split between skills and sub‑agents. /goal (without parameters) – displays current round count and token usage. /workflows – reports per‑agent usage and allows immediate termination.
The author also recommends routing routine, high‑volume tasks to smaller, faster models while reserving the strongest model for critical decision‑making and planning.
All experiments were performed with a single Fable 5 model without routing; however, long‑running loops would benefit from the suggested model routing strategy.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
