Loop Engineering Tools
Design loops that stop on time, stay on budget, and never merge without approval.
Loop Engineering helps you create safe, verifiable, token-aware workflows for Claude Code, Codex, Cursor, GitHub Actions, and Ralphify.
/goal Fix the failing CI checks for this pull request with the smallest safe change.Work toward this goal until all validation checks pass or the stop rule is reached.Loop cycle:1. Discovery — Read the latest CI failure, related pull request comments, and recent commits before choosing the next action.2. Handoff — Assign the work to one coding agent in an isolated branch or worktree. Keep the final merge decision with a human reviewer.3. Verification — A separate reviewer checks the diff, confirms validation results, and rejects shortcuts such as deleting tests or weakening checks.4. Persistence — Write a short run note with the error seen, files changed, checks run, and the next recommended action.5. Scheduling — Run manually for each failing pull request. Move to a scheduled check only after the loop is reliable.Context:This is a TypeScript project. Prefer small focused changes. Read existing patterns before editing.Validation:pnpm lintpnpm testpnpm buildIndependent checker:A separate reviewer checks the diff, confirms validation results, and rejects shortcuts such as deleting tests or weakening checks.Boundaries:Do not delete tests.Do not bypass lint or type checks.Do not modify unrelated files.Do not merge without human approval.Stop rule:Stop when all validation commands pass, or after 5 failed iterations.Maximum iterations: 5Budget:Stop before exceeding the agreed per-run token budget.Human approval:Required before merge, deploy, delete, purchase, or external communication.Fallback:If blocked, summarize the current errors, attempted fixes, and recommended human decision.Do not delete tests, bypass checks, or modify unrelated files just to satisfy the validation condition. If blocked, stop and summarize the blocker, attempted fixes, and recommended next action.
What Is Loop Engineering?
Loop Engineering is what comes after a good prompt. You design the small system around the agent: what it reads, who receives the work, how the result is checked, what gets remembered, and when the loop should stop.
A prompt asks for one answer. A loop keeps returning to the work with rules, memory, and a reason to stop.
The Five Moves That Make a Loop Work
A loop is not just a long prompt. It is a repeatable path from a signal to a checked result, with enough memory to improve the next pass.
The loop reads the signal: CI failure, issue, review comment, commit, inbox, or saved report.
The work is given to the right agent, branch, worktree, or human owner with a clear goal.
A checker tests the result against commands, artifacts, review rules, and real intent.
The loop saves what happened, what changed, and what still needs attention next time.
The loop either stops for a human or runs again on a manual, timed, or event-based trigger.
The agent that makes the thing should not be the only one grading it.
A loop becomes safer when the maker and checker are separate. The checker can be a test suite, a review checklist, another agent, or a human reviewer. What matters is that it can say no.
Check Loop ReadinessWho checks the result?
Name a separate reviewer, test suite, scoring rule, or second agent. The maker should not be the only judge.
What does the checker reject?
Call out shortcuts: deleted tests, skipped checks, unrelated edits, vague summaries, or changes that only satisfy the metric.
What happens on failure?
A good loop stops, reports the blocker, and asks for a human decision instead of quietly trying forever.
Start with one small loop you would actually review.
A good first loop is boring in the best way: one source, one goal, one check, one stop rule. For example, read a failing CI run, propose the smallest fix, run the checks, then stop for a human before merge.
- 01Pick one discovery source, such as CI failures or open review comments.
- 02Write one outcome-based goal and the validation command that proves it.
- 03Add a checker that can say no.
- 04Set a stop rule, budget cap, and human approval point.
- 05Save a short run note so the next pass has memory.
Loop Engineering Templates
Monitor a pull request until CI is green and review comments are resolved.
Fix failing CI by reading logs, applying minimal changes, and rerunning validation.
Reproduce a bug, fix the smallest cause, and verify with a regression test.
Review a code change for correctness, safety, maintainability, and test coverage.
Use one agent to implement and another independent reviewer to check the result.
Refresh an existing SEO page while preserving search intent, URL, and internal link strategy.
Loop Engineering with AGENTS.md, SKILL.md, and RALPH.md
Create durable project instructions for AI coding agents.
Create reusable workflow packages for repeated agent tasks.
Export loop definitions for Ralphify-style local loop experiments.
Loop Safety Checklist
- Is the goal machine-verifiable?
- Is the discovery source clear?
- Is there an independent checker?
- Can the agent run tests or checks?
- Are forbidden actions clearly defined?
- Is there a max iteration limit?
- Is there a budget limit?
- Is there a rollback or fallback plan?
- Is human approval required before merge, deploy, delete, purchase, or external communication?
Token-Aware Loop Engineering
Long-running loops can burn tokens quickly. Good loop design defines max iterations, retry limits, memory strategy, and human review gates before the agent starts.
What goes wrong when a loop runs without judgment
Verification debt
Outputs pile up faster than anyone checks them. The fix is a real checker and a clear human review point.
Comprehension rot
The loop keeps changing things while your mental map falls behind. Read the run notes and review diffs regularly.
Cognitive surrender
The loop sounds confident, so you stop having opinions. Let agents execute; keep judgment with a person.
Token blowout
Scheduled loops multiply cost quickly. Set retry caps, daily limits, and smaller context windows before scheduling.
Explore Loop Engineering Tools and Runtimes
Official Claude Code feature for keeping Claude working toward a measurable completion condition.
Official Codex automation feature for recurring tasks and background work.
Experimental runtime for loop engineering workflows using RALPH.md-style loop definitions.
Open-source orchestrator that runs Claude Code or Codex in a continuous loop — creating PRs, waiting for checks, and merging — with budget, time, and iteration caps.
Claude Code plugin that runs an automated code-review loop using Codex as an independent reviewer, with timestamped execution logs.
Useful memory-first framing for token-rich and token-poor agent loops.
Loop Engineering Comparisons
Help improve Loop Engineering templates.
Send feedback, report a broken template, or ask for new loop examples. You can also join the update list for new agent loop templates and safety checklists.
Contact: hello@loopengineering.app
Loop Engineering FAQ
Loop Engineering is designing the system around an AI agent — the goal, context, validation, boundaries, budget, stop rule, and feedback — instead of prompting turn by turn.