Claude Codeのループが回らないのは、プロンプトではなく完了条件の問題だったAutonomous loops in Claude Code fail not because of prompt wording but due to…
Claude Codeで自律ループが正常に動作しない原因はプロンプトの書き方ではなく、タスク完了条件の設計にあることが判明。完了条件を明確に定義することでループが安定して機能するようになる。
Autonomous loops in Claude Code fail not because of prompt wording but due to poorly defined completion conditions. Properly specifying termination criteria enables stable, reliable loop execution.
AI 生成の要約と解説(解説は要約と収集メタデータに基づく)で、元記事全文の転載・翻訳ではありません。日本語版と英語版は言語ごとに独立して生成しています。正確性は元記事 (zenn.dev) でご確認ください。AI-generated summary and explainer (the latter based on the summaries and collected metadata), not a copy or translation of the full source article. Generated independently for each language. Verify accuracy at the original source (zenn.dev).
Claude Codeに自律作業を任せたループが回らない原因は、プロンプトの書き方ではなく完了条件の設計にあった。ログを検証した筆者はそう結論づけている。問題の核心は、完了条件を決定論的か非決定論的かで分類できていなかったことだと説明されている。
2分間に6回の差し戻し
筆者がログを見返すと、ターン終了をブロックするhookが、2分間に同じフィードバックを6回続けて返していた。Claude Codeは毎回「修正しました」と答え、hookは毎回同じ理由で差し戻す。それでもリポジトリの状態は1バイトも変わっておらず、完全な無限ループだったという。
筆者は当初、指示の書き方が甘いのだろうと考え、プロンプトを何度も書き直していた。しかし実測してみると、結論は違っていた。
完了条件の必須化
筆者はClaude Codeのサブエージェント委任に、検証可能な完了条件を必須としている。完了条件のない委任には、「できたように見える」以外の合否信号がないためだ。
仕組みは単純で、PreToolUseフックでAgentツールの呼び出しを検査する。委任プロンプトに <success_criteria> ブロックがなければdenyする。プロンプトの取り出しにはjq、タグの有無の確認にはgrepを使う。denyの理由文には「完了条件がありません。success_criteria ブロックに検証可能な合否条件とエビデンス要求を書いてください。」と書かれている。この文面がそのままClaude Codeへのフィードバックになり、次の呼び出しでは完了条件付きのプロンプトが来る。
順調に見えていた
ここまでは順調に見えていた。しかしhookを入れてしばらくして委任ログを読み返した筆者は、自分が勘違いしていたことに気づく。タグは確かに毎回書かれていた。
筆者は、この気づきに至るまでに事件を2つ踏んだと述べている。その記録と、たどり着いた完了条件の分類をメモとして残している。完了条件を明確に定義すれば、ループは安定して機能するようになるという整理だ。
Autonomous work in Claude Code can stall in ways that rewriting prompts does not fix. According to the author, the cause of a failed loop was how the completion condition was defined, not how the instructions were worded.
An infinite loop in the logs
The author handed autonomous work to Claude Code and later found a hook that blocks turn ending sending the same feedback six times in two minutes. Each time, Claude Code reported "fixed," and the hook rejected it for the same reason. The repository state had not changed by a single byte. The author calls it a complete infinite loop.
At first the author assumed the instructions were too loose and rewrote the prompt several times. Measuring the behavior led to a different conclusion: the loop failed because completion conditions had not been classified as deterministic or non-deterministic. The author says it took two incidents to reach this, and the write-up records both the incidents and the resulting classification.
Verifiable completion conditions
The author requires a "verifiable completion condition" for every subagent delegation in Claude Code. The reasoning is that a delegation without one has no pass/fail signal other than "it looks done."
The success_criteria hook
The mechanism is a PreToolUse hook that inspects Agent tool calls. It reads the delegation prompt and checks for a success_criteria block. If the block is missing, the hook denies the call. The deny reason says there are no completion conditions and asks for verifiable pass/fail conditions and evidence requirements to be written in that block.
Because the deny reason text goes straight back to Claude Code as feedback, the next call arrives with a prompt that includes completion conditions. The author says this worked smoothly, or appeared to.
Where the tag check fell short
After running the hook for a while, the author reread the delegation logs and realized something had been misunderstood. The tag was in fact written every time. Even so, the logs showed the loop still failing, which points to the content of the completion condition rather than its presence.
ポコとTECHガイドPoko & TECH Guide
ポコと当サイトのTECHガイドが、記事の要約と収集した情報から読みどころを語るAI生成の対話です。Poko and TECH Dashboard's own TECH Guide discuss the article's highlights in an AI-generated conversation based on its summary and collected source details.
- ポコPoko同じフィードバックが2分間に6回って、いったい何が起きてたの?The same feedback six times in two minutes? What was actually going on?
- TECHガイドTECH Guidehookがターン終了を差し戻し続けたのに、Claude Codeは毎回「修正しました」と言うだけ。リポジトリは1バイトも変わっていなかったそうです。A hook kept blocking the turn from ending, and Claude Code just said "fixed" every time. The repository didn't change by a single byte.
- ポコPokoプロンプトを書き直しても効かなくて、完了条件の分け方が問題だったってこと?So rewriting the prompt didn't help, and the real issue was how the completion conditions were sorted?
- TECHガイドTECH Guide筆者の結論はそうです。完了条件を決定論的か非決定論的かで分類できていなかった、と。だから委任には検証可能な完了条件を必須にしているんですね。That's the author's conclusion: they hadn't classified conditions as deterministic or not. That's why delegation now requires a verifiable completion condition.
- ポコPoko「できたように見える」だけじゃなくて、ちゃんと合否が分かる条件が要るんだね。So "it looks done" isn't enough. We need a condition that clearly says pass or fail.
- TECHガイドTECH Guideはい。ただ、このhookが見ているのはタグの有無です。タグが毎回書かれていても勘違いがあった、と筆者は気づいています。形だけで安心はできないかもね。Right. But the hook only checks whether the tag exists, and the author found a misunderstanding even with the tag always present. Form alone may not be reassuring.
匿名の公開いいねです。記事の保存・お気に入りではなく、Featured、Top 3、重要度、掲載順位には影響しません。仕組みとプライバシーAnonymous public likes are reactions, not saved articles or bookmarks. They do not affect Featured, Top 3, importance, or listing order.How it works and privacy


