The Agentic Loop
Gather context, take action, verify results
- Name and describe the three phases of the agentic loop: gather context, take action, verify results
- Explain why the loop is adaptive — and how the phase mix changes from a question to a bug fix to a refactor
- Map each of Claude Code's five built-in tool categories to the phase it serves
- Articulate why the loop (the harness), not the model alone, is what creates agency
- Connect the loop to two ideas that shape every workflow ahead: verification signals and finite context
Claude Code works by running an adaptive loop with three blended phases: gather context, take action, and verify results. Understanding this loop — and why the harness around the model creates the agency — explains everything else you'll learn.
- 1The mental model: a loop, not a single answer
- 2The three phases up close
- 3The loop is adaptive
- 4How tools map to each phase
- 5Why the loop — not the model — creates agency
- 6Two ideas the loop sets up: verification and finite context
The mental model: a loop, not a single answer
A code-completion tool predicts your next few characters. Claude Code does something fundamentally different: when you give it a task, it runs a loop. It works through three phases — gather context, take action, and verify results — using tools at every step, and it repeats the cycle, course-correcting from what it learned, until the task is done.
The official docs describe it cleanly:
"When you give Claude a task, it works through three phases: gather context, take action, and verify results. These phases blend together. Claude uses tools throughout, whether searching files to understand your code, editing to make changes, or running tests to check its work."
The word that matters is blend. These aren't rigid, sequential steps with hard borders. Claude might gather a little context, take an action, see the result, gather more context, and act again — chaining dozens of tool calls together. You are part of the loop too: you can interrupt at any point (press Esc) to redirect, and Claude course-corrects.
Keep this single picture in your head for the rest of the course. Almost every feature you'll learn — plan mode, CLAUDE.md, subagents, hooks, context management — is a way to shape one or more phases of this loop.
Key insight
Agentic, not autocomplete
An autocomplete tool only sees the current file and predicts text. Claude Code sees your whole project, runs commands, reads results, and decides what to do next. The difference isn't a smarter model — it's the loop.
The three phases up close
Each phase is a different kind of work Claude does — and each is powered by a different set of tools.
| Phase | What Claude does | Example tool actions |
|---|---|---|
| Gather context | Reads and understands before acting | Read files, search by pattern, grep content, explore the codebase, fetch docs |
| Take action | Makes the change the task requires | Edit files, create files, run shell commands, run git, start a server, create a branch |
| Verify results | Checks whether the action actually worked | Run tests, read command output, compare to a screenshot, evaluate success |
Here's the loop in motion. When you say "fix the failing tests," Claude might:
1. Run the test suite to see what's failing ← gather context
2. Read the error output ← gather context
3. Search for the relevant source files ← gather context
4. Read those files to understand the code ← gather context
5. Edit the files to fix the issue ← take action
6. Run the tests again to verify ← verify resultsEach tool use returns information that feeds back into the loop and informs the next decision. Step 6 might pass — done — or it might surface a new failure, sending Claude back to gather more context. That feedback is the engine.
Example
Why the phases blend
Notice steps 1 and 6 both run the test suite — once to gather context (what's broken?) and once to verify (is it fixed?). The same tool serves different phases depending on intent. That's why the docs say the phases blend rather than running in strict order.
The loop is adaptive
Claude doesn't run all three phases every time. It decides what each task requires, based on what it learned from the previous step. The mix of phases adapts to the work:
| Task | Typical phase mix |
|---|---|
| "How does our auth flow work?" | Mostly gather context — read and explain; little or no action, no verification |
| "Fix this failing test" | All three, cycling repeatedly until tests pass |
| "Rename this function across a small file" | Mostly take action — minimal context, light verification |
| "Refactor the payments module" | Heavy gather context up front, then action, then extensive verification |
This adaptivity is why you can't reduce Claude Code to a script. It chains together however many actions a task needs and course-corrects along the way. A question may only gather context. A quick rename may skip serious verification. A refactor leans hard on verification because there's more that can break.
Understanding this helps you set expectations: if you ask a pure question, don't be surprised when Claude never edits a file. If you ask for a risky change, expect — and want — it to spend time verifying.
Tip
You shape the mix
Plan mode (Shift+Tab to cycle to it) forces Claude into read-only gather context mode so it explores and proposes before touching anything. It's a deliberate way to bias the loop toward context-gathering on uncertain work. You'll go deep on this in Module 2.
How tools map to each phase
Tools are what make Claude Code agentic. Without tools, a model can only produce text. With tools, it can act — and each tool use returns information that feeds the next decision. Claude Code's built-in tools fall into five categories, and each one naturally serves a phase of the loop:
| Category | What Claude can do | Primary phase |
|---|---|---|
| File operations | Read files, edit code, create files, rename and reorganize | Gather context (read) + Take action (edit/create) |
| Search | Find files by pattern, search content with regex, explore codebases | Gather context |
| Execution | Run shell commands, start servers, run tests, use git | Take action + Verify results |
| Web | Search the web, fetch documentation, look up error messages | Gather context |
| Code intelligence | See type errors and warnings after edits, jump to definitions, find references | Verify results (requires code-intelligence plugins) |
A few mappings are worth pausing on:
- File operations span two phases. Reading a file gathers context; editing it takes action. Same category, different intent.
- Execution is the workhorse of verification. Running tests is how Claude checks its own work — which is exactly why giving it something runnable matters so much (next section).
- Beyond these five, Claude also has tools for spawning subagents and asking you questions — orchestration moves you'll meet later.
Note
Extensions sit on top
Skills, MCP servers, hooks, and subagents are a layer on top of the core agentic loop — they extend what Claude can gather, do, and verify. The five built-in categories are the foundation everything else builds on.
Why the loop — not the model — creates agency
Here's the part that surprises people. The intelligence comes from the model, but the agency comes from the harness around it.
The docs name this directly:
"The agentic loop is powered by two components: models that reason and tools that act. Claude Code serves as the agentic harness around Claude: it provides the tools, context management, and execution environment that turn a language model into a capable coding agent."
Think about what the harness actually is. The vast majority of Claude Code is plain, deterministic software engineering: the code that finds files, runs your tests, snapshots files for checkpoints, manages permissions, packs and compacts the context window, parses tool output, and feeds it back. By Anthropic's own accounting, roughly 98.4% of Claude Code is deterministic infrastructure — ordinary, predictable code — and only about 1.6% is the AI decision logic where the model chooses what to do next.
That tiny slice of model reasoning is decisive, but it's only useful because the deterministic 98.4% gives it real tools, real results to react to, and a loop to run in. A model with no tools is a chatbot. A model wrapped in a loop that gathers context, acts, and verifies is an agent.
This reframes how to get good results: you improve outcomes less by "asking the model harder" and more by shaping the loop — giving it the right context, the right tools, and a clear way to verify success.
Key insight
The 98.4 / 1.6 split
Almost all of Claude Code is boring, reliable plumbing. The AI is a thin decision layer steering that plumbing. This is good news: it means most of the system behaves predictably, and your job is mostly about feeding the decision layer well — clear tasks, good context, real verifiers.
Two ideas the loop sets up: verification and finite context
The loop quietly raises two questions that shape every workflow you'll build. The rest of the course answers them.
1. Verification matters because Claude stops when work looks done. The verify phase only works if there's a signal to check against. Give Claude a failing test, a build command, a screenshot of the target UI, or an exact expected output, and it will run the verify phase against that signal and iterate until it passes. Give it nothing to check against, and you become the verification loop — eyeballing every change by hand. The single highest-leverage habit in Claude Code is handing it something it can verify against.
Implement validateEmail. Test cases:
'user@example.com' → true, 'invalid' → false, 'user@.com' → false.
Run the tests after.That last line — run the tests after — closes the loop for Claude. Module 2 is all about this.
2. Context is finite, and every loop iteration consumes it. Each file read, each command output, each test run pours into a context window that holds the conversation, file contents, CLAUDE.md, memory, and system instructions. As the loop runs, context fills up. Performance is about quality of context, not just quantity — raw logs and repeated reads compete with the signal that matters. Managing what's in the window (with /context, /clear, /compact, and subagents) becomes a core skill. Module 3 is all about this.
Hold onto the loop as your map. Everything ahead is a technique for running it better.
Watch out
No verifier, no autonomy
Without a way to check its work, Claude declares success the moment the change looks complete — even if it's subtly wrong. Don't skip giving it a verifier; it's the difference between an agent that iterates to correctness and one that hands you a plausible guess.
Try it: Watch the loop run — and break the verify phase on purpose
Make the three phases visible in a real session.
Setup. Open any small project (or git init a scratch folder with a trivial function and a test for it).
Part 1 — see all three phases.
- Start Claude Code:
claude - Ask it to make a small change that has a test, e.g. "Add input validation to
parseAmountand run the tests after." - Press Ctrl+O to open the transcript viewer and watch the tool calls. Label each one in your head: is it gathering context (read/search), taking action (edit/run), or verifying (running tests)?
- Note where the loop cycles — did a failed test send Claude back to gather more context?
Part 2 — adaptivity.
5. In the same session ask a pure question: "How does parseAmount handle negative numbers?" Confirm Claude only gathers context — it reads and explains, but doesn't edit or run tests.
Part 3 — remove the verifier.
6. Ask for a change with no way to verify: "Tweak the error message in parseAmount to be friendlier." (no test, no expected output). Notice Claude stops when the change looks done — you're now the verification loop.
7. Re-run it as a verifiable task: give an exact expected string and ask it to add/adjust a test asserting that string, then run it. Watch the verify phase do real work.
Reflect. Write two sentences: (a) which phase mix each of the three requests produced, and (b) what changed about Claude's behavior the moment you gave it something to verify against. You've just experienced what Modules 2 and 3 formalize.
Key takeaways
- 1Claude Code runs an adaptive loop with three blended phases: gather context, take action, verify results.
- 2The loop adapts to the task — a question may only gather context; a refactor leans on verification; a quick rename mostly takes action.
- 3Claude Code's five built-in tool categories (file operations, search, execution, web, code intelligence) each serve a phase of the loop.
- 4Agency comes from the harness, not the model alone: ~98.4% of Claude Code is deterministic infrastructure, only ~1.6% is AI decision logic.
- 5Verification only works when you give Claude a signal to check against — otherwise you become the verification loop.
- 6Every loop iteration consumes finite context, which is why context management is a core skill.
Quiz
Lock in what you learned
Check your understanding
0 / 4 answered
1.You ask Claude Code, "How does our authentication flow work?" Which phase mix should you expect?
2.When Claude runs "fix the failing tests" and executes the test suite both near the start and at the end, what's happening?
3.What does the claim that ~98.4% of Claude Code is deterministic infrastructure and ~1.6% is AI decision logic tell you about where agency comes from?
4.Why is giving Claude something to verify against (a test, build, or expected output) the highest-leverage habit?
Go deeper
Hand-picked sources to keep learning
The primary source for the agentic loop, the three phases, the five tool categories, and the agentic-harness framing.
Step-by-step walkthroughs of the loop in practice, including the explore-plan-implement-commit pattern.
Why verification is the safety net and how to give Claude something to check against.
Previews Module 3: how finite context fills as the loop runs, and tools to manage it.
Practitioner perspective on why context quality (not just size) and verification drive results.
Official repository — issues, releases, and reference for the CLI.