Dashboard/Phase 1: Foundations
📖 Concept7 min10 XP

Lesson 3: The Agentic Loop

Day 3 of 50 · ~7 min read · Phase 1: Foundations


The Opening Question

You've now had Claude Code read and describe your project. That was simple: read, think, report back.

But most real coding tasks are more complex. They involve multiple steps, checking your work, and adjusting course.

Here's the question: when Claude Code has to do something complex — like "refactor this function to be async" or "add authentication to this API" — how does it break that down into steps? And how does it know what to do after each step?


Discovery

Let's think through this by imagining a real scenario.

Question 1: What should Claude do when the task is too big for one step?

Let's say you ask Claude: "Add a new user authentication system to our Express app."

That's not a one-liner. It involves:

  • Reading the current app structure
  • Understanding the existing user model
  • Designing a new auth flow
  • Writing new code
  • Updating tests
  • Maybe running the test suite to make sure nothing broke

If Claude just dove in and started writing, what could go wrong?

Pause and think: If you gave a junior developer that task, would they start coding immediately, or would they ask questions first?

A good developer would ask questions: "What framework are we using for auth? Do we want JWT or sessions? Should this break existing tests?" They'd also read the existing code before making changes.

Claude does the same thing. It doesn't just execute blindly. It plans. It reads first, reasons about what needs to change, and then acts.

And here's the key part: it doesn't assume everything will work on the first try.

Question 2: What's the read → reason → act → check cycle?

This is the core of the agentic loop. It's not a one-time process — it's a repeating cycle that Claude runs multiple times to complete a task.

Let me break it down:

Read: Claude examines the relevant files, searches for context, and builds a mental model of the current state.

Reason: Claude thinks about what needs to change, why, and in what order. It might ask itself: "Do I need to update the database schema? What's the smallest change that would work? What could break?"

Act: Claude makes one or more changes. It might edit a file, run a test, commit changes, or create a new file. But critically, it acts intentionally, not haphazardly.

Check: Claude verifies that its action worked. It might run tests, read the file it just edited to confirm the change, or ask you if the result looks right.

Then, if the check shows a problem, Claude loops back. It reads what went wrong, reasons about how to fix it, acts again, and checks again.

Question 3: Why doesn't Claude just do everything at once?

You might ask: "Why make multiple loops? Why not just think through the whole task, make all the changes, and be done?"

Think about this from Claude's perspective: What changes if Claude learns something new in the middle of executing?

For example, imagine Claude is adding authentication to an Express app. It reads the code and discovers the app uses a custom user model that's quite different from what Claude initially assumed.

If Claude had a rigid plan made before reading the code, it might miss that detail. But by reading, reasoning, acting, and then checking, Claude can adapt. It learns as it goes.

Pause and think: Have you ever started a coding task thinking you knew what needed to happen, then discovered halfway through that you were wrong? How did you adjust?

That adaptability is the whole point of the loop.

Question 4: What's the difference between one-shot and multi-step tasks?

Let's go back to Lesson 2. You might run:

claude "Add a .gitignore file"

That could complete in one loop: Claude reads your project structure, understands you need a gitignore, writes one, and shows you the result. Done.

But a more complex task like "Add authentication" might require 5-10 loops:

  1. Read the current code structure
  2. Reason about the auth design
  3. Create a new auth module
  4. Check: Does it import correctly?
  5. Update the user model
  6. Check: Does the schema work?
  7. Write tests
  8. Check: Do the tests pass?
  9. And so on...

Here's the thing: You don't need to micro-manage each loop. You ask Claude for the big goal, and Claude figures out the steps.

But you can see the loops happening in the conversation. Claude will say things like: "I've read your Express app... I'm going to create an auth middleware... let me check if that works... I found an issue, let me fix it..."

That's the loop, in real-time.


The Insight

Here's the core idea:

Claude Code doesn't execute tasks in one big chunk. Instead, it runs a repeating cycle of reading context, reasoning about next steps, taking action, and checking the results. This agentic loop lets Claude adapt to what it discovers, fix mistakes, and handle complexity one step at a time.

The mental model: The agentic loop is like pair programming with someone who's extra careful. They read the code, they think out loud, they make a small change, they check that it worked, and if it didn't, they fix it and try again. You can see the whole process and jump in anytime.


Try It

You've already installed Claude Code. Now let's watch the loop in action.

  1. In a small project, ask Claude to do something that requires multiple steps. For example:

    • "Add a function that validates email addresses to this module"
    • "Write a test for the function in index.js"
    • "Create a config file for our database connection"
  2. Watch the conversation. You'll see Claude:

    • Read files (it'll tell you which ones)
    • Reason about what to do (it might say "I see the current structure... I'll add this function here...")
    • Act (edit files, create new ones)
    • Check its work (run tests, read the file back, ask you if it looks right)
  3. Pay attention to when Claude loops. You might see it say: "Let me check if this works... [runs a test] ... I see an issue, let me fix it..."

That's the agentic loop in action. Count how many times you see the read → reason → act → check cycle.


Key Concepts Introduced

ConceptDefinition
Agentic loopThe repeating cycle of read → reason → act → check that allows Claude to complete complex tasks autonomously
Read phaseClaude examines files and builds context about the current state
Reason phaseClaude thinks about what needs to change and in what order
Act phaseClaude makes changes to your codebase (edits files, runs commands, etc.)
Check phaseClaude verifies its changes worked and can loop back if needed
Multi-step taskA goal that requires multiple agentic loops to complete
IterationThe process of looping back and adjusting when Claude learns something new

Bridge to Lesson 4

You now understand how Claude Code thinks and acts. But we haven't yet talked about what it can do.

When Claude acts, it uses tools. Tools are the "hands" of the agent — the ways Claude actually interacts with your project.

Tomorrow's question: What's the difference between Claude thinking and Claude doing? What tools does it actually have?

We'll explore the built-in tools that give Claude the ability to read, write, search, and run commands.


← Back to Curriculum · Lesson 4 →