Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Introduction  ›  Lesson

The Agentic Loop

What is Agentic Loop? 12 minA coding agent works in a loop of gathering context, acting and checking the result, repeating until a check passes, so a clear runnable check is what makes the loop converge.

The Agentic Loop

Watch Claude Code on a real task and you will see a rhythm: it reads something, changes something, runs something, then reads again. That rhythm is the agentic loop. Once you can see its shape, you know exactly where to steer it.

The rule

Gather, act, check — and repeat until the check passes.

  • Gather context. Read files, search for names, look at recent changes, run harmless commands to learn how the project works.
  • Act. Edit files or run commands that move towards the goal.
  • Check. Run the tests, read the output, compare the result with what you asked for.
  • Repeat. Every tool result goes back to the model, which decides the next move. The loop ends when the check passes, when it needs your input, or when you stop it.

You are part of this loop, not outside it. You approve actions, you can interrupt at any step, and you can redirect it with a new message. Each pass also adds file contents and command output to the conversation, which is why a wandering task grows slower and costlier than a short, well-aimed one.

The weakest link in most loops is the check. If Claude has nothing to run, "check" shrinks to "this looks plausible to me", and the loop can finish on code that has never been exercised. A clear, runnable check — a failing test, a command whose output should change, an exact expected number — turns the loop from guessing into converging.

The shortcut

Before you press Enter, name the check: "How will Claude know it is done?" If you cannot answer, add a check to the prompt.

The loop for "let a customer pause tomorrow's delivery"Step 1 of 5
  1. Gather

    Claude reads orders.py to see how the delivery list is built, then reads tests/test_orders.py to learn the test style.

Notice what drove the fix in the fourth step: the failing test. Without it, the loop would have stopped after the first edit with a confident summary and a hidden off-by-one bug.

Drills

Answer fast — trust the rule.

quick drill

In what order does the agentic loop run?

quick drill

Claude edits orders.py, runs the tests, and two fail. What should a healthy loop do next?

quick drill

Which prompt gives the loop the strongest check?

quick drill

Where do you sit in the agentic loop?

Remember

  • Gather, act, check, repeat — the loop ends when the check passes or it needs you.
  • Shortcut: name the check before you send the prompt.
  • Trap: a loop with no runnable check finishes on "looks plausible".

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainTrace the loop

Describe, step by step, the agentic loop Claude Code would run to add a 'pause tomorrow' option to the tiffin app. Then explain why including a runnable check in your prompt makes the loop better.