Loop Engineering Guides
Practical guides on Loop Engineering: what it is, how to build a first loop, how to use checkers, and how to keep repeated agent work safe and budget-aware.
Loop Engineering is the practice of designing the loop around an AI agent: what it reads, who receives the work, how the result is checked, what gets remembered, and when the loop stops or runs again.
Start with one small loop you can personally review. Pick one discovery source, one outcome, one validation step, one checker, one stop rule, and one place to save the run note.
Token-rich loops pass large context into every iteration. Token-poor loops pass summaries, retrieved memory, or scoped observations to reduce cost.
Safe loops define hard stop rules before execution: max iterations, budget caps, repeated failure limits, and human approval gates.
When a validation metric becomes the target, an agent may optimize the metric instead of the real goal. Good loop design adds boundaries against shortcuts.
Closed loops have clear validation and stop rules. Open loops explore uncertain tasks and need stronger human supervision.
Long-running loops need memory strategy: what to keep, what to summarize, what to retrieve, and what to forget.
Ralphify is an experimental open-source loop runtime. RALPH.md-style exports can help describe loop goals, commands, boundaries, and fallback rules, but they should be treated as experimental.
Context Engineering focuses on what information an agent receives. Loop Engineering focuses on how the agent iterates, validates, stops, and reports.
An agent harness is the system that validates, authorizes, executes, records, and returns observations for the actions a model proposes. Loop engineering decides how that harness iterates: the goal, validation, stop rule, budget, and feedback.
Every loop template here maps directly to a continuous-claude run. The template's objective, validation, and boundaries become the task prompt; the suggested max iterations become --max-runs; you add --max-cost and --max-duration caps, then run.
Worktree orchestrators run several coding agents at once, each in an isolated git worktree, so parallel work does not collide. They differ in supported agents, diff/review UX, merge flow, and license.
Both keep an agent working toward a goal with validation and a stop condition. Claude Code /goal frames a single goal with explicit boundaries and a max-iteration line; Codex /goal frames an objective with a “Done when” block and explicit stop conditions. The structure differs more than the intent.
AGENTS.md holds durable project rules and validation commands. SKILL.md packages a reusable workflow with triggers and steps. RALPH.md is an experimental loop definition for Ralphify-style runtimes. They are complementary, not competing.
continuous-claude runs an autonomous agent loop with cost, time, and iteration caps. A GitHub Actions workflow runs your validation on a schedule or trigger but does not run an autonomous agent. Use Actions to validate; use continuous-claude (with caps and human approval) to iterate.
All three keep a Claude Code session running between prompts. /goal starts the next turn when the previous finishes and stops when a fast model confirms your condition is met. /loop re-runs on a time interval. A Stop hook fires after every turn and stops when your own script or prompt decides.