Course contents
The Agentic Loop
Claude works in a loop of gathering context, acting and verifying. Learn why constraints stated up front and a runnable check make that loop converge.
Before any theory, try to predict the loop yourself. Claude has just been told “fix the failing tests.” Put its moves in the order you'd expect.
Put Claude's moves on “fix the failing tests” in order.
- Edit the files to fix the issue
- Run the test suite to see what's failing
- Search for the relevant source files
- Read the error output
- Run the tests again to verify
- Read those files to understand the code
Gather, act, verify
Claude Code's docs name three phases: gather context, take action and verify results. They aren't fixed stages. A question about your codebase might need only the first. A bug fix cycles through all three several times. A refactor spends most of its effort verifying. After each tool call, Claude reads the result and picks the next step, chaining dozens of actions and correcting course as it learns.
You're part of the loop too. You can press Esc to stop, or queue a message that Claude reads after its current tool calls. That's the reason to watch the first minute of a new task: an early correction costs one message, and a late one costs the work done in the wrong direction.
Constraints are cheapest before the plan
Claude plans from what it knows when it starts. A constraint stated up front shapes that plan for free. The same constraint arriving after Claude has read three files and edited two forces a re-plan, and some of the finished work may have to be undone. Compare “Refactor the auth module. Keep the public API stable. Add tests for every changed file.” with “Refactor the auth module,” followed two minutes later by “oh, and don't break the API.” The first is one loop; the second is a loop, an interruption and a repair.
Constraints worth stating up front include what must not change (a public API, a database schema), where to look (“token refresh lives in src/auth/”), which approach you prefer when two are reasonable, and what “done” means. Claude can't read any of these from the code.
Turn this request into one Claude can finish in a single loop. Switch on the parts that help and leave out the ones that hurt.
Add rate limiting to the login endpoint.
Give the loop a way to end
Claude stops when the work looks done. If nothing tells it whether the work is done, “looks done” is all it has. Give it something that comes back pass or fail, and it closes the loop itself: make the change, run the check, read the failure, fix it, run the check again. The best-practices guide calls the command that runs your checks “the single most useful line” you can put in your project instructions.
Which of these can Claude use to verify its own work?
A line in the prompt saying “be careful”
One more habit: ask for evidence, not reassurance. “All tests pass” tells you little; the command Claude ran and its output tell you a lot, and reading the output is faster than rerunning it yourself. For a session you weren't watching, the output is the only evidence you have.
Which addition changes what Claude builds, not just how hard it thinks?
Add a /health endpoint
acme/web-app · Accept edits
Plain-English definitions from the AI Coding Dictionary.