7 AI Loops to Automate Your Code

Loops let AI agents work autonomously toward defined goals by combining a trigger (manual, scheduled, or action-based) with a goal (verifiable or LLM-judged). Seven production-ready loops span performance optimization, documentation, architecture refactoring, logging, error fixing, SEO audits, and product testing—but they're best for well-defined problems and require careful token budgeting.

What Loops Are and How They Work

Definition: Autonomous Goal-Seeking

A loop is a mechanism that allows an AI coding agent to work autonomously toward a specified goal without human intervention, removing the need for manual step-by-step direction and enabling faster execution.

Two Core Components

Every loop requires a trigger (what kicks it off) and a goal (what success looks like). The trigger can be manual, scheduled, or action-based; the goal can be verifiable (concrete, testable) or LLM-judged (the model decides when it's met).

Seven Production Loops

Sub-50ms Page Load Loop

Continuously optimizes every page, modal, and window in an application until each loads under 50 milliseconds. This is a verifiable goal with concrete metrics, making it ideal for loops. Trigger can be manual, scheduled, or tied to PR opens to prevent regressions.

Overnight Docs Sweep

Each night, reviews the entire codebase and updates documentation to reflect changes from the previous day, then opens a pull request. Uses LLM as judge since 'complete documentation' is subjective and requires model judgment.

Architecture Satisfaction Loop

Refactors code until the architecture is satisfactory, with the model deciding when it's 'happy.' After each step, it live-tests, runs auto-review, and commits. Can run nightly to keep the codebase clean and DRY.

Logging Coverage Loop

Reviews the system's logging and adds missing coverage until every important path produces useful, tested logs. Uses LLM as judge because 'important path' is non-deterministic and requires model judgment.

Production Error Sweep

Every night, reviews production logs for errors, traces root causes, fixes them, verifies fixes, opens pull requests, and notifies via Slack. Goal is concrete: no unaddressed errors in logs. Runs autonomously through all errors one by one.

SEO/GEO Visibility Loop

Runs an audit across crawlability, indexation, page intent, titles, internal links, structured data, and citations. Ranks gaps, fixes highest-leverage issues, reruns the crawl, and repeats until no critical technical issues remain. Ideal for weekly runs.

Full Product Evaluation Loop

Creates realistic scenarios covering every major capability, defines success criteria, runs all scenarios under identical conditions, and iteratively fixes anything that doesn't meet the bar. Non-deterministic and LLM-judged; can take 12+ hours but produces strong optimizations across the entire product.

Implementation and Tools

Using /goal in Codeex and Claude

To trigger a loop, paste the loop prompt into Codeex or Claude and add '/goal' at the beginning or end. This tells the tool to continue working autonomously until the specified goal condition is met, regardless of how long it takes.

Loop Library: Free Resource

A free library of production-ready loops that can be copied directly or used as inspiration for custom loops. Hosted on Vercel and maintained with new discoveries.

Caveats and Limitations

Not Every Problem Fits Loops

Loops work best when goals are verifiable (like 'under 50ms') or clearly definable. They struggle with subjective LLM judgment and are poor for building new features from scratch because the model's direction is unpredictable and feature decisions are ambiguous.

Token Cost and Budget Constraints

Loops churn through tokens autonomously and can run for 10 minutes to days. Some loops (like full product evaluation) routinely exceed 12 hours. This makes them expensive and unsuitable for teams without substantial token budgets or cost tolerance.

Feature Parity Example: Excel Clone

Attempting to build feature parity with Excel using a loop ran for days, using computer vision to click through Excel and verify features. Not recommended due to unpredictable direction and extreme token consumption.

Notable quotes

Loops are the frontier of AI workloads. — Matthew Berman
The hard part of building AI applications is not using the model. It's everything around the model. — Matthew Berman
I do not recommend doing that. — Matthew Berman

Action items

  • Visit the loop library (link in video description) and copy a loop matching your use case.
  • Paste the loop prompt into Codeex or Claude and add '/goal' to trigger autonomous execution.
  • Start with a verifiable, well-defined goal (e.g., performance metric or error count) rather than subjective ones.
  • Monitor token usage closely, especially for longer-running loops; set time/token limits if needed.
  • Schedule loops to run off-peak (e.g., nightly) to avoid disrupting development.
  • For custom loops, define success criteria clearly before execution to avoid unpredictable behavior.
  • Apply for free consulting sessions (link in video) if you need hands-on help designing loops for your codebase.
Matthew Berman
16 min video
3 min read
7 AI Loops to Automate Your Code
You just saved 13 min.
The big takeaway
Loops let AI agents work autonomously toward defined goals by combining a trigger (manual, scheduled, or action-based) with a goal (verifiable or LLM-judged). Seven production-ready loops span performance optimization, documentation, architecture refactoring, logging, error fixing, SEO audits, and product testing—but they're best for well-defined problems and require careful token budgeting.
What Loops Are and How They Work
Definition: Autonomous Goal-Seeking
A loop is a mechanism that allows an AI coding agent to work autonomously toward a specified goal without human intervention, removing the need for manual step-by-step direction and enabling faster execution.
Two Core Components
Every loop requires a trigger (what kicks it off) and a goal (what success looks like). The trigger can be manual, scheduled, or action-based; the goal can be verifiable (concrete, testable) or LLM-judged (the model decides when it's met).
1
Trigger: Manual kick-off, scheduled time, or action-based (e.g., PR open)
2
Goal: Verifiable (concrete metric) or LLM as judge (model decides)
3
Loop runs autonomously until goal is met
Loop structure: trigger + goal = autonomous execution
Seven Production Loops
Sub-50ms Page Load Loop
Continuously optimizes every page, modal, and window in an application until each loads under 50 milliseconds. This is a verifiable goal with concrete metrics, making it ideal for loops. Trigger can be manual, scheduled, or tied to PR opens to prevent regressions.
50ms
Target page load time
Loop optimizes every page until this threshold is met
Overnight Docs Sweep
Each night, reviews the entire codebase and updates documentation to reflect changes from the previous day, then opens a pull request. Uses LLM as judge since 'complete documentation' is subjective and requires model judgment.
Each night
Review codebase changes
Automated
Update documentation
Automated
Open pull request
Overnight docs sweep automation schedule
Architecture Satisfaction Loop
Refactors code until the architecture is satisfactory, with the model deciding when it's 'happy.' After each step, it live-tests, runs auto-review, and commits. Can run nightly to keep the codebase clean and DRY.
Logging Coverage Loop
Reviews the system's logging and adds missing coverage until every important path produces useful, tested logs. Uses LLM as judge because 'important path' is non-deterministic and requires model judgment.
Production Error Sweep
Every night, reviews production logs for errors, traces root causes, fixes them, verifies fixes, opens pull requests, and notifies via Slack. Goal is concrete: no unaddressed errors in logs. Runs autonomously through all errors one by one.
1
Review production logs nightly
2
Identify actionable errors
3
Trace to root cause
4
Fix and verify
5
Open PR and notify Slack
Production error sweep workflow
SEO/GEO Visibility Loop
Runs an audit across crawlability, indexation, page intent, titles, internal links, structured data, and citations. Ranks gaps, fixes highest-leverage issues, reruns the crawl, and repeats until no critical technical issues remain. Ideal for weekly runs.
1
Crawlability
2
Indexation
3
Page intent
4
Titles & links
5
Structured data
6
Citations
SEO/GEO audit dimensions checked and fixed
Full Product Evaluation Loop
Creates realistic scenarios covering every major capability, defines success criteria, runs all scenarios under identical conditions, and iteratively fixes anything that doesn't meet the bar. Non-deterministic and LLM-judged; can take 12+ hours but produces strong optimizations across the entire product.
1
Create n realistic scenarios for all capabilities
2
Define clear success criteria and evaluation method
3
Run scenarios under identical conditions
4
Fix underlying causes of failures
5
Rerun affected and complete test suite
6
Repeat until all scenarios meet quality bar
Full product evaluation loop process
Implementation and Tools
Using /goal in Codeex and Claude
To trigger a loop, paste the loop prompt into Codeex or Claude and add '/goal' at the beginning or end. This tells the tool to continue working autonomously until the specified goal condition is met, regardless of how long it takes.
Loop Library: Free Resource
A free library of production-ready loops that can be copied directly or used as inspiration for custom loops. Hosted on Vercel and maintained with new discoveries.
Caveats and Limitations
Not Every Problem Fits Loops
Loops work best when goals are verifiable (like 'under 50ms') or clearly definable. They struggle with subjective LLM judgment and are poor for building new features from scratch because the model's direction is unpredictable and feature decisions are ambiguous.
Verifiable goals (e.g., performance metrics)
9 /10 fit
LLM-judged goals (e.g., 'satisfactory')
6 /10 fit
Feature building from scratch
2 /10 fit
Loop suitability by problem type
Token Cost and Budget Constraints
Loops churn through tokens autonomously and can run for 10 minutes to days. Some loops (like full product evaluation) routinely exceed 12 hours. This makes them expensive and unsuitable for teams without substantial token budgets or cost tolerance.
10 min - days
Typical loop runtime
Loops consume tokens continuously until goal is met
Feature Parity Example: Excel Clone
Attempting to build feature parity with Excel using a loop ran for days, using computer vision to click through Excel and verify features. Not recommended due to unpredictable direction and extreme token consumption.
Worth quoting
"Loops are the frontier of AI workloads."
— Matthew Berman, at [5:10]
"The hard part of building AI applications is not using the model. It's everything around the model."
— Matthew Berman, at [6:10]
"I do not recommend doing that."
— Matthew Berman, at [15:25]
Try this
Visit the loop library (link in video description) and copy a loop matching your use case.
Paste the loop prompt into Codeex or Claude and add '/goal' to trigger autonomous execution.
Start with a verifiable, well-defined goal (e.g., performance metric or error count) rather than subjective ones.
Monitor token usage closely, especially for longer-running loops; set time/token limits if needed.
Schedule loops to run off-peak (e.g., nightly) to avoid disrupting development.
For custom loops, define success criteria clearly before execution to avoid unpredictable behavior.
Apply for free consulting sessions (link in video) if you need hands-on help designing loops for your codebase.
Made with Glimpse by Wozart
glimpse.wozart.com/v/rdniy8ff
Share this infographic

More like this