Skip to content
Stop Writing Prompts, Start Designing Loops: A 14-Step Roadmap

Stop Writing Prompts, Start Designing Loops: A 14-Step Roadmap

This article presents a 14-step roadmap for transitioning from manual prompt writing to designing automated loops that orchestrate AI coding agents, covering when loops are justified, five building blocks, minimal viable loop construction, failure modes, and security considerations.

ThinkInAI Community
ThinkInAI Community
ThinkInAI Community

Most developers still manually prompt their coding agents: type, wait, read diff, repeat. Nine out of ten builders have never written a loop that prompts the agent for them. The leverage point has shifted from writing prompts to designing systems that write prompts . This 14-step roadmap draws on Anthropic engineering docs, Addy Osmani's loop engineering essay, and recent measurement studies.

Part 1 · Why and How to Decide

01. Loop Engineering Replaces Your Role as Prompt Writer

For two years you got output by writing a prompt, sharing context, reading the return, then writing the next prompt. The agent was a tool you held. That part is ending. Loop engineering means building a small system that discovers work, dispatches it to an agent, checks results, records what happened, and decides the next step. You design the system once; thereafter the system prompts the agent.

Addy Osmani breaks it into six parts: automation, worktrees, skills, connectors, sub-agents, and state. Anthropic engineers now merge 8× more code per day than in 2024 — a number Anthropic itself calls "almost certainly an overstatement of real productivity gains." The number is debated; the mechanism is not: leverage has moved from prompting to designing the loop that prompts.

02. Run the Four-Condition Test Before Building Anything

Loops only pay off when four conditions hold. Miss one and the loop costs more than it returns. AlphaSignal's most honest take — the part most X threads skip:

Task recurs. Loop setup cost must be amortized over many runs. One-off tasks are faster and cheaper with a good prompt. If the work doesn't happen weekly, you don't have a loop — you have a script you ran once.

Verification is automated. The loop needs something that can judge failure while you're away: test suite, type checker, linter, build. Without automated checks you're back in the chair reading diffs — exactly the work the loop was meant to remove.

Token budget absorbs waste. Loops re-read context, retry, explore. Every run burns tokens whether or not it ships. This technique scales with budget, which is why it feels obvious to people with near-free tokens and reckless to people paying per call.

Agent has senior-engineer tooling. Logs, reproducible environments, ability to run its own code and see where it breaks. Without these the loop is blind iteration.

03. Who Wins, Who Loses — Loops Favor Those Who Can Afford Them

The economics aren't universal. People who call loops table stakes usually have unmetered tokens. People who call them reckless are often on a $20 consumer plan trying to run heavy verification loops without hitting caps or surprise bills.

Who actually benefits in practice:

Teams with repetitive, machine-checkable work and budget to run it — continuous test triage, dependency upgrades, lint-and-fix, issue-to-PR drafts on well-tested codebases.

Codebases that already have strong test suites. If a junior engineer can do the task from a checklist and the test suite catches their mistakes, a loop fits.

Async-first teams already using multi-agent patterns. For them, routines are the missing orchestration layer.

Who should skip it today:

Solo builders on consumer plans — token bill arrives before productivity.

Anyone working on code without automated verification. A loop without real checks is the agent agreeing with itself over and over.

Teams whose real bottleneck is review throughput, not authoring speed. Loops produce more code; if review is already the bottleneck, they just make the queue longer.

For one-offs, exploratory work, or anything where "done" needs human judgment, a single well-scoped prompt still wins . The honest version: loop engineering is real, but most developers don't need it yet.

04. 30-Second Loop Check

The four-condition test in step 2 is strategic. This is tactical — a checklist to run before you turn a specific task into a loop.

Miss any item, keep it a manual prompt.

1. Task occurs at least weekly. Below weekly → setup cost never amortizes.

2. Tests, type-check, build, or linter can reject bad output. No automated gate → agent grades its own homework.

3. Agent can run the code it changes. No reproducible env → iteration is blind.

4. Loop has a hard stop condition. Token budget, iteration cap, or wall-clock limit. Without these the loop runs until someone notices the bill.

5. Human review before merge, deploy, or dependency change. Any irreversible action needs a human approval gate.

Good first loops: CI failure triage (nightly scan, categorize, draft fixes for easy ones), dependency upgrade PRs (weekly scan, test compat, open PR), lint-and-fix pipelines (auto-apply style fixes on PR open), flaky test reproduction (loop runs until a hypothesis survives), issue-to-PR drafts on well-tested codebases where bad output gets rejected by the test suite.

Bad first loops — these need a human in the chair: architecture rewrites, auth or payments code, production deploys, vague product work, anything where "done" needs subjective judgment.

Part 2 · Five Building Blocks

05. Automations: The Heartbeat

Automations make a loop a loop instead of a one-off you ran once. They kick off on a schedule, an event, or a trigger. They're the heartbeat — everything else in the loop hangs on them.

In the two main tools it looks roughly like this:

Codex. Automations tab — pick a repo, set a prompt, set a cadence, choose local checkout or background worktree. Runs that find something go to a Triage inbox; runs that find nothing auto-archive.

Claude Code. Three primitives compose the same shape: /loop for in-session cadence, Desktop scheduled tasks for persistence across restarts, Routines for cloud runs that survive laptop close. Plus hooks for lifecycle events.

Two primitives inside automations separate loops that work from loops that burn money:

/loop — repeats on a cadence. Use when you want a periodic check regardless of state.

/goal — runs until a condition you write actually becomes true. A separate small model checks completion, so the model writing code isn't the one grading it. This is maker-vs-checker separation applied to the stop condition itself.

> /loop 30m /goal all tests in test/auth pass and lint clean.
  Scan src/auth for new failures, propose fixes in claude/auth-fixes,
  open draft PR when goal condition met.

▲ Claude
  CronCreate(*/30 * * * * : auth quality loop)
  Stop condition: tests pass + lint clean (verified by checker)
✓ Scheduled. Will keep running after intermediate completions
  until independent checker judges /goal condition met.

06. Worktrees: Parallelism Without Collisions

Once you run more than one agent, files start colliding. Two agents writing the same file is as messy as two engineers committing to the same lines without talking.

Git worktree solves this — it's a separate working directory on its own branch sharing the same repo history, so one agent's edits literally cannot touch another agent's checkout.

Video link: https://video.twimg.com/tweet_video/HKYZaJqXQAAIF96.mp4

GIF

How it shows up in the two tools:

Codex — built-in worktree support; multiple threads operate on the same repo without stepping on each other.

Claude Code — exposes git worktree directly with --worktree flag to open a session in its own checkout, and isolation: worktree setting for sub-agents so each helper gets a fresh checkout that auto-cleans on exit.

Worktrees eliminate mechanical collisions, but you're still the ceiling. Your review bandwidth determines how many agents you can actually run in parallel — not the tool.

07. Skills: Project Knowledge Written Once, Read Every Run

A skill is how you stop re-explaining the same project context every session like a goldfish. Both tools use the same format: a folder with a SKILL.md holding instructions and metadata, plus optional scripts, references, and assets.

Why this matters especially for loops: a loop without skills re-derives the entire project context from zero every cycle. With skills, intent compounds.

Conventions, build steps, "we don't do X because of that one incident" — written once externally, read every run.

name: ci-triage
description: Classify CI failures by root cause (env, flake, real bug,
  dependency, infra), draft fixes for simple ones, escalate rest.
  Trigger on any workflow run failure or morning triage loop.
---

# CI triage skill

## Classification rules
- env: missing secret, env var misconfig, infra not provisioned. # human
- flake: passes on re-run without code change. # re-run once, then archive
- bug: deterministic failure tied to recent commit. # draft fix
- dependency: failure tied to version bump. # draft rollback
- infra: timeout, OOM, runner issue. # escalate

## Fix patterns
- Auth tests → check src/auth/middleware first
- Database tests → verify migration applied to CI env
- E2E tests → check selectors against latest UI snapshot

## Never do
- Disable failing tests — always escalate instead
- Modify CI config without human approval
- Touch src/payments/ or src/billing/ (see claude/permissions.md)

## State
Update STATE.md after each run: files checked, classifications,
PRs opened, items escalated.

08. Connectors: Loops Touch Your Real Tools via MCP

A loop that only sees the filesystem is a small loop. Connectors built on Model Context Protocol (MCP) let agents read your issue tracker, query your database, hit your staging API, post to Slack.

Codex and Claude Code both support MCP, so a connector you write for one usually works in the other.

This is the difference between an agent saying "here's the fix" and a loop that opens the PR, links the Linear ticket, and pings the channel when CI goes green .

Connectors are why a loop can act in your real environment instead of just telling you what it would do if it could.

Highest-ROI connectors for loop work, in order:

GitHub — read repo, create branches, open PRs, comment issues, respond to webhook events. Biggest day-one win for any code loop.

Linear or Jira — update tickets as loop progresses, link PR back to issue, auto-close on verified pass.

Slack — post triage summaries, ping humans on escalation, morning digest of overnight runs.

Sentry / your error tracker — let loop investigate production alerts and draft fixes for high-frequency errors.

09. Sub-Agents: Keep the Maker Away from the Checker

This is the evaluator-optimizer pattern from Anthropic's December 2024 engineering post, just with a new name. One model generates, another critiques, repeat. The vocabulary trending in 2026 was already documented 18 months ago.

How sub-agents land in the two tools:

Codex — spawns sub-agents only when asked; they run in parallel and fold results back into one answer. You can define your own agents in .codex/agents/ as TOML files — name, description, instructions, optional model and reasoning effort. Your security reviewer can be a high-effort strong model while the explorer is a fast read-only thing.

Claude Code — does the same with sub-agents in .claude/agents/ and agent teams that hand work to each other. Common split: one agent explores, one implements, one verifies against spec.

Part 3 · Build It Right or Don't Build It

10. State Files. Agents Forget. Files Don't.

This part sounds too dumb to be important, but it's the spine of every working loop. A markdown file, a Linear board, a JSON blob — anything that lives outside a single conversation and records what's done and what's next.

Why it matters: agents have short-term memory by default. What they learn in this session is gone tomorrow unless you write it down.

Osmani's rule: agents forget, repos don't. A loop without persistent state restarts every run; a loop with state keeps moving forward.

# Loop state · ci-triage

## Last run
2026-06-09 03:30 UTC · 7 failures classified, 3 fixes drafted, 4 escalated

## In progress
- claude/fix-auth-token-refresh — local tests pass, awaiting CI
- claude/fix-flaky-payment-webhook — retry pattern applied, monitoring

## Completed today
- claude/bump-axios-1.7.4 → merged (CI green, deps loop verified)
- claude/lint-fix-pass-june-9 → merged

## Escalated to humans
- src/billing/refund.ts — failing 3 ways, root cause unclear
- ci/staging-runner — infra timeout, not code

## Lessons learned (write here, not in chat)
- 2026-06-08: PowerShell hits TLS 1.2 issue on this Windows runner. Use bash.
- 2026-06-07: tests/e2e/checkout needs Stripe webhook secret in env. Skip if missing.

## Stop conditions met since last review
- /goal "all tests pass + lint clean" met at commit 3a7b8c1 on 02:14 UTC

Two patterns for where state lives:

Markdown in repo — STATE.md at root or in .claude/. Version-controlled. Readable diff. Best for solo or small-team work.

External system (Linear, GitHub Issues, database) — survives across repos, queryable, supports team-wide visibility. Best for production loops where multiple humans need to see what the loop is doing.

For long-running loops that can drift, pair the state file with a standing high-level spec — e.g., VISION.md or AGENTS.md — that the agent re-reads every run. State tells the agent where it is . Spec tells it where it's going .

11. Minimum Viable Loop

If you passed the four-condition test in step 2, build the minimum viable loop before adding anything fancy. Four pieces, no swarm.

In plain English the four pieces are:

One automation. A scheduled run that triggers on a cadence and stops on a clean condition. Use /loop in Claude Code or automation in Codex. Pair with /goal when you want it to run until a stated condition is true.

One skill. A SKILL.md that holds project context so the agent doesn't re-derive from zero every run.

One state file. A markdown file or Linear board that records what's done and what's next. Tomorrow's run picks up instead of restarting.

One gate. A test, type-check, or build that automatically fails bad work. This piece decides whether the loop helps you or just spends money.

Order matters: make one manual run reliable. Turn it into a skill. Wrap it in a loop. Then schedule it. Skipping steps is how loops fail in production.

The metric that actually matters is cost per accepted change — not tokens spent, not tasks attempted, not loops scheduled. If your accepted-change rate is below 50%, you're doing the review work the loop was supposed to save you, and the loop is losing money.

12. The Ralph Wiggum Loop. Loops That Fail Quietly.

Engineer Geoffrey Huntley documented and named this failure mode. An agent that should only emit a completion token when done emits it early, the loop exits, and a half-finished task is left behind. With no hard gate, the loop fails silently and keeps spending money.

Ralph Wiggum loops happen when:

No real verifier. Just a second agent "reviewing" with no objective signal. Two optimists agreeing with each other.

Soft done conditions. "Done" is judged by the agent, not defined by a test, build, or type-check.

No hard stop. Loop runs until something external kills it (rate limit, you notice), not until success is verified.

The fix is the gate from step 11 — something that can objectively fail the work . A test that passes or fails. A build that compiles or doesn't. A linter that returns zero or non-zero. Not an opinionated verifier.

Other measured failure modes worth knowing:

Goal drift in long sessions. Every summarization is lossy; "don't do X" constraints vanish by turn 47. Mitigation: re-read a standing VISION.md or AGENTS.md every run.

Self-preference bias. The agent writing code is too nice when grading its own work. Mitigation: use a separate verifier sub-agent that doesn't see the maker's reasoning.

Agent laziness. Loop declares "good enough" at partial completion. Mitigation: use /goal with an objective stop condition checked by a fresh model.

13. Understanding Debt and Cognitive Surrender

This is a failure mode that gets sharper when loops get better , not worse. Two named risks, both from Osmani's post:

Understanding debt. The faster a loop ships code you didn't write, the wider the gap between what the repo contains and what you understand. The bill that hurts isn't the token bill. It's the day you have to debug a system nobody on the team has read.

Cognitive surrender. The temptation to stop forming your own judgment and accept whatever the loop hands back grows stronger. Designing loops with judgment is the antidote; designing loops to avoid thinking is the accelerant. Same motion, opposite outcomes.

Mitigations aren't technical:

Read the diffs. If you don't read what the loop ships, you're renting understanding debt at compound interest.

Spot-check gates. Pick a few loop-opened PRs and verify the tests that approved them actually catch the failure modes you care about. Gates rot.

Gate loops off architecture work. Keep them on small, machine-checkable changes. The moment you let them touch things that need judgment, understanding debt accelerates.

Pair-design loops with a teammate. Two sets of eyes at design time catch blind spots the loop would otherwise exploit forever.

14. The Security Tax. Unattended Loops Are Unattended Attack Surface.

A loop that runs unattended is also attack surface that runs unattended.

Threat model your loop must defend:

Generated code shipped without review. Loop opens PRs faster than humans read. Without a gate that includes security checks (SAST, dependency audit, secret scanning), insecure code merges automatically.

Skills as injection vectors. Loops that auto-install skills inherit every prompt injection hidden in their descriptions. Audit skill sources before install.

Secrets in logs. Debug logs from long-running loops scatter secrets into logs you don't monitor. Disable verbose logging in production loops; redact what does get logged.

Permission creep. A loop tested with read-only gets "just one" write permission for convenience and never gets re-audited. Re-audit scopes every 30 days.

§ Mistakes That Turn Loops Into Money Pits

Building loops without the four-condition test. Step 2 exists for a reason. Most developers miss at least one condition.

No objective gate. A second agent "reviewing" with no test, type-check, or build is just a second optimist.

Same agent writing and verifying. Self-preference bias. Maker grades own homework, always "A+".

No state file. Tomorrow's run starts from zero instead of picking up.

Fuzzy stop conditions. "Looks good" never works. Use tests, type-pass, or build-pass.

No token budget cap. Loops re-read context and retry. Without a cap, ambitious loops burn 5-10× your expected tokens.

Running heavy verification loops on consumer plans. Token bill or rate limit — one of them finds you.

Auto-installing community skills. 520 of 17,022 audited skills leaked credentials. Read source before install.

Using loops for work that needs judgment. Architecture, auth, payments, vague product decisions. Let loops do lint-and-fix, not strategy.

Not reading diffs. Understanding debt compounds. The day you debug a system nobody read costs more than tokens.

Conclusion

The Leverage Point Moved. Your Job Moved Too.

For two years the leverage in working with coding agents sat in the prompt. Better prompt, better context, better one-shot output.

That phase is ending. Agents are good enough that the next leverage point sits one layer up: the system that decides what they do, when they do it, what gate they must pass, and what state persists between runs.

But the honest version of this story isn't that everyone should rush to build loops. Most developers still don't need a loop — until the task recurs, verification is automated, budget absorbs waste, and the agent has senior-engineer tooling.

Miss one condition and the loop costs more than it returns.

If you pass the test, build small. One automation. One skill. One state file. One gate. Make one manual run reliable. Turn it into a skill. Wrap it in a loop. Then schedule it. Order matters. Skip steps and you're paying for a system nobody understands.

Cherny's point isn't that work gets easier. It's that the leverage moved. Build the loop. Keep engineering.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

automationsoftware engineeringCodexClaude CodeAI Coding AgentsGit WorktreesLoop Engineering
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.