Understanding the loop explains why good prompts include a way to check the work and why Claude reads files before editing.
When you give Claude Code a task, it does not produce the answer in one go. It works in a loop of three overlapping phases: gather context (search and read files), take action (edit files, run commands) and verify results (run tests, read errors). Each step's result decides the next step, and it repeats until Claude judges the task complete or you interrupt.
Asked to "fix the failing tests", a typical run looks like this:
- run the test suite to see what fails,
- read the error output,
- search for the relevant source files and read them,
- edit the code,
- run the tests again to confirm.
Two parts make this work. The model (Claude) does the reasoning: deciding what to look at and what to change. The tools do the acting. Claude Code is the layer around the model, sometimes called the harness, that provides the tools and manages what the model sees. Built-in tools fall into groups: file operations (read, edit, create), search (find files, search contents), execution (run shell commands, tests, git), web (search, fetch pages) and code intelligence via plugins. There are also tools for asking you questions and for starting helper agents.
What Claude can reach: files in the folder you started it in (and others with permission), any command you could run in your terminal, and your git state such as the current branch and uncommitted changes.
The practical lesson: the loop closes best when there is something to check against. A task with a test, a build or an expected output lets Claude find and fix its own mistakes. A task with no check stops when the work merely "looks done".
Example
You: the date picker test fails on leap years, fix it
gather -> Bash: npm test -- datePicker (2 failures)
-> Grep: "isLeapYear" in src/
-> Read: src/utils/dates.ts
act -> Edit: src/utils/dates.ts (fix the year % 100 rule)
verify -> Bash: npm test -- datePicker (all passing)
Claude: Fixed isLeapYear: years divisible by 100 are only leap years
if also divisible by 400. Tests pass (12/12).Remember
- Gather context, take action, verify: the loop repeats until done or interrupted
- The model reasons; tools (files, search, shell, web) act
- Giving Claude a check to run lets the loop catch its own mistakes
Watch out for
- Asking for a change with no way to verify it, then being surprised that plausible-looking code does not work.