1 What Is a Loop?
A loop is a way to allow your AI coding agent to work autonomously toward a specified goal. The critical feature is that it removes the human from the iteration cycle, letting the agent work much faster toward a defined outcome.
Two Components
- Trigger — what kicks off the loop. Three options:
- Manual — you tell the agent to run the loop
- Scheduled — runs at a set time or on a repeating cadence
- Action-based — fires on events like opening a PR
- Goal — the termination condition. Two types:
- Verifiable — a concrete, deterministic check (e.g., "100% test coverage")
- LLM as a Judge — the model itself decides when the goal is met (e.g., "refactor until satisfied")
2 The Loop Library
Matthew launches the Loop Library, a free collection of loops he uses personally and ones he's seen others use. The library is hosted on here.now and serves as a single place to discover, get inspired by, and copy loops directly into your workflow.
The library lives at signals.forwardfuture.ai/loop-library and is continuously updated as he discovers new loop patterns.
3 Sub-50ms Page Load Loop
Matthew's favorite loop and a textbook example of a verifiable goal. The objective: get every single page load in the app under 50 milliseconds.
The Prompt
"Continue optimizing the code for speed. After each significant change, measure page load performance across every page under the same repeatable test conditions. Continue until every page loads in under 50 milliseconds."
How It Works
- The agent iterates through every window, page, and modal in the application
- Loads each one and measures performance
- If any page exceeds 50ms, it optimizes until it meets the threshold
- Moves to the next page and repeats
Triggering
In this case, Matthew triggers it manually, but it can also run on PR open — ensuring every new PR doesn't regress page load performance. In Codex, you type /goal at the end of the prompt. Claude Code has a similar /goal feature.
4 Overnight Docs Sweep
A scheduled loop that runs every night: "Each night, review the codebase in full and make sure all documentation reflects the latest changes from the previous day. Update the documentation as needed, then open a pull request with those changes."
Key Characteristics
- LLM as a Judge — no deterministic way to verify "complete documentation coverage"
- Schedule trigger — runs automatically each night via Codex automations
- Opens a PR with changes for human review
To set it up in Codex: go to the Automations tab, select "Create via chat," paste in the loop prompt, and let it set up the recurring automation.
5 Architecture Satisfaction Loop
Attributed to Peter Steinberger, this is elegantly simple: "Refactor until you are happy with the architecture."
The Prompt
"Refactor until you are happy with the architecture. Be very strict about simplicity. Make sure every single line of code is DRY. Then after each significant step, live test the system, run auto review and commit. Track progress in progress.md."
- LLM as a Judge — "happy with the architecture" is the model's decision
- You can add guidance on what "happy" means: strict simplicity, DRY code, etc.
- Tracks its own progress in a markdown file as it loops
- Can be kicked off manually or run every night as a codebase quality sweep
6 Logging Coverage Loop
"Review the system's logging and add missing coverage until every important path produces useful, tested logs."
- LLM as a Judge — "every important path" is non-deterministic; the model decides what's important
- Manually triggered
- Sets the stage for the next loop (Production Error Sweep) — these two loops compound together
7 Production Error Sweep
"Every single night, review production logs for errors. If you find an actionable issue, trace it to its root cause, fix it, verify the fix, and open a pull request. Then ping me in Slack with the findings and PR link. If no actionable errors are present, ping me with that result instead."
- Verifiable goal — the concrete end state is "no more unaddressed errors in the logs"
- Scheduled trigger — runs every night
- Fixes issues one by one, opening PRs for each
- Integrates with Slack for notifications
The natural companion to the Logging Coverage loop — first ensure comprehensive logging, then automatically act on what those logs reveal.
8 SEO/GEO Visibility Loop
"Run an SEO/GEO audit across crawlability, indexation, page intent, titles, internal links, structured data, source citations, and answer-first content. Rank the gaps. Fix the highest-leverage issues. Rerun the same crawl. Repeat until no critical technical issues remain."
- Verifiable goal — "no critical technical issues remain" can be checked against the crawl results
- Covers both traditional SEO and the emerging GEO (Generative Engine Optimization)
- Can handle 1 or 50 issues — the loop continues regardless
- Best run on a weekly schedule
9 Full Product Evaluation Loop
The most ambitious and "handwavy" loop: "Create N realistic scenarios covering every major capability. Before testing, define clear success criteria and choose a consistent evaluation method. Run every scenario under the same conditions and record evidence for each outcome. Fix the underlying cause of anything that does not meet the criteria. Rerun the affected scenarios. Continue until every scenario meets the original quality bar."
How It Differs from a Test Suite
- Unlike traditional tests, this is non-deterministic — the model goes through every use case, determines if it's "good enough," and updates if necessary
- Can take 12+ hours to complete
- Comes up with "very good optimizations"
Customization Example
For an LLM-powered Q&A product: "Come up with 100 different wide-ranging use cases for asking the LLM questions and judge whether the response is good enough. If it's not, iterate and improve it."
10 Loop Caveats
Caveat 1: Not for Every Problem
- Verifiable goals work best — "every page loads under 50ms" is ideal loop territory
- LLM-as-judge goals are more brittle — you're leaving taste and judgment to the model
- Feature building is particularly hard — "Loop until we build a full permissioning system" doesn't work well because you can't predict which direction the AI will go
The Excel Clone Experiment
Matthew tried telling the model to "clone Excel, feature parity" as a goal. The agent ran for days — it actually opened Excel on his computer, used computer use, and clicked through to verify feature parity. He eventually stopped it manually. Not recommended.
Caveat 2: Loops Are Expensive
- They churn through tokens autonomously until they hit the goal
- Some might run for 10 minutes, others for days
- Great for users with unlimited token budgets ("token maxers")
- May not be practical for those with strict token constraints
🎯 Key Takeaways
🔑 Key Takeaways
- Loops = autonomous agent iteration — a trigger + a goal, with the human removed from the cycle
- Verifiable goals are strongest — deterministic checks like "under 50ms" or "zero errors" make the most reliable loops
- LLM-as-judge goals are useful but brittle — model judgment works for architecture quality and documentation completeness, but results vary
- Loops compound — the Logging Coverage + Production Error Sweep combo shows how layering loops creates autonomous maintenance systems
- Three trigger types — manual, scheduled, and action-based (PR opens) cover virtually all use cases
- /goal flag — both Codex and Claude Code support this mechanism for telling the agent to keep iterating
- Feature building doesn't loop well — lack of direction control makes open-ended feature development a poor fit
- Loops are expensive — they consume tokens autonomously and can run for hours or days; budget accordingly
- Overnight loops are a killer pattern — schedule architecture cleanup, documentation, and error sweeps to run while you sleep
- The Loop Library is a free resource — a curated collection of reusable loop patterns at signals.forwardfuture.ai/loop-library
🔗 Resources & Links
- Loop Library — free collection of AI coding agent loop patterns
- here.now — free, instant web hosting for agents (hosts the Loop Library)