Vibe Coding using Claude Code/Setup & Foundations
Lesson 4 / 6 · 16 min · 0 / 5 exercises
Course contents
Concept · 5 hands-on exercises

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 it in orderExercise 1 of 4

Put Claude's moves on “fix the failing tests” in order.

  1. Edit the files to fix the issue
  2. Run the test suite to see what's failing
  3. Search for the relevant source files
  4. Read the error output
  5. Run the tests again to verify
  6. 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.

Why every surface behaves the same
The loop lives in the harness, not in the window you type into. The terminal, VS Code, the desktop app, a cloud session and a GitHub Action all run the same loop with the same tools, which is why a habit you learn here works everywhere.

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.

Build itExercise 2 of 4

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.

What gets sent
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.

Sort itExercise 3 of 4

Which of these can Claude use to verify its own work?

Card 1 of 6

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.

Quick checkExercise 4 of 4

Which addition changes what Claude builds, not just how hard it thinks?

Claude Code on the web · simulated session
Add a /health endpoint Open in ▾

Add a /health endpoint

acme/web-app · Accept edits

Add a /health endpoint to the API. It should return {status: 'ok'} and have a test.
acme/web-app⎇ claude/add-health-endpointAccept edits ▾Default
0 / 10Simulated session, no real API calls. Not affiliated with Anthropic; Claude, Claude Code and Clawd are Anthropic trademarks.
Check your understanding
Q1. Which three phases does Anthropic use to describe Claude Code's loop?
Q2. Why is a constraint cheaper in your first prompt than two minutes into the task?
Q3. Claude finishes and says “Done, everything works.” What's the most useful reply?
· Work through the 5 remaining exercises above (stuck? each one can show you the answer).
· Score 100% on the quiz.
Vocabulary in this lesson

Plain-English definitions from the AI Coding Dictionary.