All articles
Guide9 min readUpdated June 23, 2026

How to Set Up Your First AI Loop (Step-by-Step Guide)

A step-by-step walkthrough for setting up your first AI loop using agentic tools like Claude Code and Codex, or no-code tools like n8n and Make.

๐ŸŽฏ Quick Answer: How to set up your first AI loop

There are two paths. If you're comfortable in a terminal, Claude Code's loop feature lets you set up a recurring AI task in under 5 minutes with a single command. If you prefer no-code tools, n8n or Make lets you build the same thing visually in about 30 minutes.

Bottom line: Pick a deterministic goal, choose your tool, set a trigger, define what "done" looks like, and cap the number of iterations. Start with something simple like "summarize new support tickets and flag urgent ones."

If you're not sure what AI loops are or why they matter, start with our complete guide to AI loops. This tutorial picks up where that explainer leaves off.

The "AI loop" concept went mainstream in June 2026 when Boris Cherny at Anthropic said "I don't prompt Claude anymore, I write loops." Peter Steinberger echoed it for OpenClaw, and the idea spread fast. But most of the explainers out there are written for developers who already live in a terminal.

This guide covers both paths: the agentic loop approach using tools like Claude Code and Codex, and the no-code loop approach using n8n or Make. Pick whichever fits your workflow.

What you'll need

Before you build your first loop, here's what to have ready:

  • A clear, testable goal. This is the most important ingredient. "Summarize new emails" is a good goal. "Make my business better" is not. If you can't write a pass/fail check for the goal, your loop will struggle.
  • An AI model or agent. For agentic loops, that means Claude Code or Codex. For no-code loops, you'll need an OpenAI or Anthropic API key.
  • A trigger. Something that starts the loop on a schedule or when an event happens.
  • A stopping condition. Define what "done" looks like and set a max iteration count to control costs.

Path 1: Agentic loops (Claude Code, Codex, OpenClaw)

Agentic loops are the approach that went viral. Instead of writing a single prompt and hoping for the best, you give an AI agent a goal and let it work in cycles: act, evaluate, adjust, repeat.

How an agentic loop works

An agentic loop has four parts:

  1. Goal: What the agent should accomplish ("Review this pull request and fix any lint errors").
  2. Action: The agent takes a step toward the goal (reads the code, runs the linter, edits a file).
  3. Evaluation: The agent checks whether the step worked (did the linter pass?).
  4. Repeat or stop: If the goal isn't met, the agent tries again. If it is, the loop ends.

This is the ReAct pattern (Reason, Act, Observe) that powers tools like Claude Code, Codex, and OpenClaw. The key difference from prompting is that the agent decides what to do next based on what happened last time, not based on a fixed script you wrote upfront.

Setting up a loop in Claude Code

Claude Code has a built-in loop feature that lets you schedule recurring AI tasks in your session. Here's how to set one up:

  1. Open Claude Code in your terminal and navigate to your project.
  2. Write your goal as a loop instruction. Be specific. Instead of "fix bugs," write "check the test suite, identify any failing tests, and fix them one at a time. Stop when all tests pass or after 5 attempts."
  3. Set the trigger. You can run the loop on a schedule (every 30 minutes) or when a file changes (on save).
  4. Set a max iteration count. This prevents the loop from running forever if something goes wrong. Five to ten iterations is a good starting point.
  5. Let it run. The agent will work through the cycle, evaluating after each step, until it hits the goal or the iteration cap.

๐Ÿ’ก Tip: Start with a loop that reviews code or tests, not one that deploys to production. A code review loop can't break anything, and you'll learn how the agent evaluates its own work before you give it higher-stakes tasks.

Setting up a loop in Codex

Codex (OpenAI's coding agent) supports a similar loop pattern. The setup is nearly identical:

  1. Define the goal in natural language. Codex understands goals like "refactor the auth module to use the new session library and make sure all existing tests still pass."
  2. Set the working directory so the agent knows which files it can read and edit.
  3. Set iteration limits to cap how many times the agent can attempt the goal before stopping.
  4. Review the output after each run. Codex logs what it did at each step, so you can see the reasoning chain.

When to use agentic loops

Agentic loops shine when the task requires the AI to make decisions and adapt. Good use cases:

  • Review pull requests and flag issues before a human looks at them
  • Run tests, identify failures, and fix them iteratively
  • Monitor logs for errors and write bug reports automatically
  • Refactor code across multiple files while keeping tests green

If your task is a simple one-shot transformation (summarize this text, translate this file), a regular prompt is fine. You don't need a loop for that. For a deeper comparison, see our guide on AI agent loops vs. traditional prompts.

Path 2: No-code loops (n8n, Make)

If you're not a developer or you don't want to work in a terminal, you can build the same loop pattern visually using no-code automation tools. The principles are identical. You're just drawing boxes instead of writing commands.

For a deeper comparison of tools, see our guide to the best AI loop tools covering Claude Code, OpenClaw, n8n, Make, and more.

Step 1: Pick a deterministic goal

A deterministic goal is one you can verify with a clear yes or no. "Did the summary mention the customer's name?" is deterministic. "Is the summary good?" is not.

Good first-loop goals:

  • Summarize new support tickets and tag them by urgency (low, medium, high)
  • Check if a new blog post meets your formatting checklist
  • Review a new lead's website and extract their company size and industry
  • Monitor a competitor's pricing page and flag changes

Bad first-loop goals:

  • "Write better content" (subjective)
  • "Build a marketing strategy" (too broad)
  • "Improve customer satisfaction" (no clear stopping condition)

๐Ÿ”‘ Key insight: The goal determines everything else. A vague goal means a vague loop that burns tokens without producing useful results. Spend more time on the goal than on any other step.

Step 2: Choose your tool

For this tutorial, we'll use n8n because it's free, open-source, and has strong AI node support. The same principles apply in Make.

  1. Sign up at n8n.io (or self-host if you prefer).
  2. Create a new workflow.
  3. You'll see a blank canvas with a trigger node waiting for you.

If you prefer Make, the steps are nearly identical. Make calls them "scenarios" instead of "workflows" and "modules" instead of "nodes," but the logic is the same.

Step 3: Set your trigger

Every loop starts with a trigger. For your first loop, use a schedule trigger because it's the easiest to test.

In n8n:

  1. Click the trigger node (it defaults to "On manual click").
  2. Change it to Schedule Trigger.
  3. Set it to run every 30 minutes.

That's your loop's heartbeat. Every 30 minutes, the workflow fires.

๐Ÿ’ก Tip: Start with a 30-minute interval. Running every minute sounds cool but will eat through your API budget fast. You can always shorten the interval later once you trust the loop.

Step 4: Add a data source

Your AI needs something to work on. For this example, let's connect a Google Sheets node that pulls new support tickets.

  1. Add a Google Sheets node after the trigger.
  2. Connect your Google account.
  3. Select the spreadsheet that holds your tickets.
  4. Set the operation to "Get rows" and add a filter for rows where the "Status" column equals "New."

Now every 30 minutes, your loop grabs any new tickets and passes them to the next step.

Step 5: Add the AI node

This is where the actual AI work happens.

  1. Add an AI Agent node (or OpenAI node) after the Google Sheets node.
  2. Connect your OpenAI or Anthropic API key.
  3. Write the system prompt. This is where your goal becomes an instruction.

Example prompt for ticket triage:

You are a support ticket triage assistant. For each ticket, write a 2-sentence summary, assign an urgency level (low, medium, high), and extract the customer's name and plan type. Format your response as JSON with fields: summary, urgency, customername, plantype.

The more specific your prompt, the better the results. Show the exact output format you want.

Step 6: Add the evaluation step

This is what makes it a loop instead of a one-shot prompt. After the AI produces its output, check whether it meets your criteria.

  1. Add a Switch node (or If node) after the AI node.
  2. Set the condition: "Does the response contain valid JSON with all four fields?"
  3. If yes, route to the output node (update the sheet, send a Slack message, etc.).
  4. If no, route back to the AI node with a correction message.

That feedback path is the loop. The AI tries, the evaluation checks, and if it fails, the AI tries again with feedback on what went wrong.

Step 7: Set a max iteration count

Loops can run forever if you let them. Always cap the number of retries.

  1. Add a Set variable node before the feedback path that increments a counter.
  2. Add a condition: "If counter is greater than 3, stop and send an alert."
  3. This prevents runaway API costs and stuck loops.

Step 8: Add the output

Where does the result go? Some options:

  • Update the Google Sheet with the summary, urgency, and extracted fields
  • Send a Slack message for high-urgency tickets
  • Create a Notion task for tickets that need human follow-up
  • Send an email digest of all processed tickets

For your first loop, keep it simple. Just update the sheet and send one Slack message for high-urgency items.

Common errors and fixes

The AI output is inconsistent or malformed. Your prompt isn't specific enough. Add an example of the exact output format you want. Show, don't just tell. Providing a JSON template with field names is more effective than describing the format in prose.

The loop runs but nothing happens. Check your trigger. Is the schedule set correctly? Is your Google Sheets filter actually finding new rows? The most common issue is a filter that returns zero results.

Costs are higher than expected. Check your iteration count. If the evaluation step keeps failing and the loop retries, you're paying for each retry. Lower the max iteration count and improve your prompt so it succeeds on the first try.

The agentic loop in Claude Code keeps editing the wrong files. Narrow the working directory. Give the agent a specific folder or file to work in, not the entire repo. The more context you provide upfront, the fewer wrong turns the agent takes.

Which path should you pick?

Factor Agentic loops (Claude Code, Codex) No-code loops (n8n, Make)
Best for Code tasks, dev workflows, iterative fixes Business processes, data tasks, non-developers
Setup time 5 to 10 minutes 30 to 45 minutes
Cost Claude Code subscription or API usage n8n free tier + API costs
Flexibility High, the agent adapts Medium, you define the flow
Learning curve Comfortable in terminal Drag-and-drop visual editor
Iteration control Built-in max iteration count Manual counter node setup

If you work with code, start with Claude Code. If you don't, start with n8n. Both produce the same fundamental pattern: goal, action, evaluation, repeat.

What to build next

Once your first loop is running, here are ideas for your next one:

  • Content review loop: Check new blog posts against a formatting checklist and flag issues
  • Lead enrichment loop: Research new leads and add company size, industry, and tech stack to your CRM
  • SEO monitoring loop: Check your rankings weekly, identify drops, and suggest fixes
  • Bug triage loop: Pull new GitHub issues, reproduce them, and write a report for the team
  • Social listening loop: Monitor mentions of your brand and summarize sentiment weekly

For a deeper look at the methodology behind designing effective loops, read our loop engineering explainer. If you want to understand the difference between loops and one-shot prompts at a conceptual level, our guide on AI agent loops vs. traditional prompts breaks it down.

For a broader look at building AI-powered apps without code, check out our building apps with AI track.

Sources

Frequently Asked Questions

Do I need to know how to code to set up an AI loop?

No. Tools like n8n and Make let you build AI loops using visual drag-and-drop workflows. You need to write a clear prompt and understand conditional logic, but no programming is required. If you do code, tools like Claude Code and Codex offer a faster setup with more flexibility.

How much does it cost to run an AI loop?

With n8n's free tier, your only cost is the AI API calls. A simple loop running every 30 minutes with GPT-4o-mini costs roughly $2 to $5 per month. Claude Code loops are included in your Claude subscription. Set a max iteration count to avoid runaway costs.

What is the difference between a loop and a regular AI prompt?

A regular prompt is a single request and response. You ask, the AI answers, you're done. A loop adds an evaluation step: the AI produces output, checks whether it meets the goal, and retries with feedback if it doesn't. The loop continues until the goal is met or the iteration cap is reached. See our [loops vs. prompts guide](/articles/ai-loops-vs-prompts) for the full breakdown.

Can I use Claude Code loops without a subscription?

Claude Code loops require a Claude subscription (Pro, Team, or Max). If you don't have a subscription, use the no-code path with n8n and the Anthropic API instead. You'll pay per token rather than a flat monthly fee.

What is the best first AI loop to build?

A support ticket triage loop. It has a clear input (new tickets), a clear output (summary, urgency, extracted fields), and a natural evaluation step (did the AI produce valid JSON?). It also delivers immediate value: your team gets pre-sorted tickets without any manual work.

How do I stop a loop from running forever?

Set a max iteration count. In Claude Code, this is a parameter in the loop instruction. In n8n, add a counter variable and a condition that stops the workflow after 3 to 5 retries. Always have a fallback that alerts you if the loop hits the cap.

Advertiser disclosure: some links on this website are affiliate links, meaning No Code MBA may make a commission if you click through and purchase.

Keep researching

More AI guides

Compare tools, sharpen your workflow, and find the next project worth building.

View all articles
What is No Code MBA?

We teach non-technical people to build real AI products.

No Code MBA is a project-based school for builders without an engineering background. AI tools like Cursor and Claude Code write the code. You ship the apps, automations, and AI SaaS. 60+ courses, 5,000+ builders, 60-day money-back guarantee.