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.
Gather
Claude reads
orders.pyto see how the delivery list is built, then readstests/test_orders.pyto 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.
In what order does the agentic loop run?
Claude edits orders.py, runs the tests, and two fail. What should a healthy loop do next?
Which prompt gives the loop the strongest check?
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".
