In Claude Code, what happens in the gather-context, take-action and verify-results phases, and how do you steer the loop mid-run?
answer
- model reasons, tools act
- every tool result feeds the next step
- phases blend, not a fixed pipeline
- verification needs a check Claude can run
- Esc cancels the running tool call
basics
~20 sClaude Code repeats three blended phases until the task looks done: gather context (read, search), take action (edit, run commands) and verify results (tests, builds). Each tool result shapes the next step; Esc stops the running call so you can redirect.
solid answer
~50 sClaude Code is the harness around the model: the model decides, and the built-in tools act. When you give it a task it **gathers context** (`Read`, searches, `git` state), **takes action** (`Edit`, `Write`, `Bash`) and **verifies results** (re-running tests or a build through `Bash`, and type errors that `LSP` reports after an edit once a code intelligence plugin is installed). The phases blend and repeat: every tool result feeds the next decision, so a question may only need gathering while a bug fix cycles many times. Claude stops when the work *looks* done, so give it a check it can run. To steer, press `Esc`: the running tool call is cancelled, the work done so far is kept, and Claude waits for you. Typing a correction and pressing `Enter` instead queues it for Claude to read once the current tool calls finish.
go deeper
Name the three phases and give a tool for each: Read or a search to gather, Edit or Bash to act, a test run to verify. Know that Esc stops the current step without undoing earlier work.
Explain that each tool result decides the next step, so the loop adapts to the task, and that the harness, not the model, runs tools and manages context. Show how a runnable check closes the verify phase.
Show how you design sessions around verification: a test command, a build, lint or LSP diagnostics, and evidence in the transcript. Explain when you interrupt with Esc versus queue a correction, and what each costs.
Frame the loop as a feedback system whose quality depends on the signals you give it: weigh prompt guidance, runnable checks and permission boundaries as the three levers a team standardises when it rolls the tool out.
## The loop in one sentence Claude Code's documentation describes the **agentic loop** as three phases: **gather context**, **take action** and **verify results**. They are not a fixed pipeline. They blend together, Claude uses tools in all of them, and the loop repeats until the task is complete or you interrupt it. Two components power it: the **model**, which reasons and decides what to do next, and the **tools**, which act. Claude Code itself is the layer around the model that provides those tools and manages the context the model sees; this surrounding layer is what the docs call the **agentic harness**. ## What each phase looks like with real tools | Phase | Typical built-in tools | What comes back into the loop | | :- | :- | :- | | Gather context | `Read`, `find` / `grep` through `Bash` (or `Grep` / `Glob` where they are present), `LSP` navigation, `WebFetch`, `WebSearch` | File contents, search hits, definitions, documentation | | Take action | `Edit`, `Write`, `NotebookEdit`, `Bash` | A confirmation, a diff, command output | | Verify results | `Bash` running tests, a build or a linter; `LSP` diagnostics after an edit | Pass or fail, error text, type errors | The docs walk through "fix the failing tests" as a typical chain: 1. Run the test suite to see what is failing. 2. Read the error output. 3. Search for the relevant source files. 4. Read those files to understand the code. 5. Edit the files to fix the issue. 6. Run the tests again to verify. Each step returns information that informs the next one. That is the whole mechanism: there is no separate planner choosing all six steps in advance. A question about the codebase may only need the gather phase; a bug fix cycles through all three phases several times; a refactor may spend most of its time verifying. ## Why the verify phase is the one you design - **Claude stops when the work looks done.** Without a check it can run, "looks done" is the only signal it has, and you become the verifier. - **A check closes the loop.** A test suite, a build exit code, a linter or a script that diffs output against a fixture produces a result Claude can read, so it can iterate until the check passes. - **Code intelligence helps automatically.** With a code intelligence plugin installed, the `LSP` tool reports type errors and warnings after each file edit, so some mistakes surface before any build runs. Without the plugin, the tool stays inactive. - **Ask for evidence.** Asking Claude to show the test output or the command it ran is faster to review than re-running the check yourself. ## Steering the loop while it runs You are part of the loop. Claude works autonomously but stays responsive to input: - **`Esc`** stops Claude immediately. The running tool call is cancelled, the work done so far is kept, and Claude waits for your next instruction. On a permission prompt, `Esc` declines that action. - **Typing a correction and pressing `Enter`** does not stop anything. The message shows as queued; if Claude is running tool calls, it reads the message as soon as those calls finish, within the same turn, and adjusts before its next step. Undoing what the loop already changed is a different mechanism (checkpoints and rewind), and the full set of input keys belongs to the material on input modes and shortcuts. ## Where the loop is bounded The loop's freedom is bounded by the session's **permission mode** and **permission rules**: before an action that needs approval, Claude Code asks you, or, in auto mode, a classifier reviews it. Those controls decide what a step is allowed to do; the loop decides which step to take. Extensions sit on top of the same loop rather than replacing it: skills run through the `Skill` tool, subagents through the `Agent` tool, and MCP servers add tools of their own. ## Common misreadings - Treating the loop as a scripted plan: the next step is chosen from the last result. - Assuming verification always happens: it happens when Claude has a check to run or you ask for one. - Expecting `Esc` to throw away the turn: it keeps what was already done and only stops what is running.
- Why does a Claude Code session sometimes declare success on code that does not build?Because Claude stops when the work looks done, and without a check it can run, looking done is the only signal. Give it something that returns pass or fail, such as the test suite, a build command or a linter, and ask it to run that after its changes. Installing a code intelligence plugin also lets the `LSP` tool report type errors after each edit.
- What does Claude keep, and what does it lose, when you press Esc mid-turn in Claude Code?It keeps the work already done in the turn: earlier edits and results stay. Only the tool call that is running is cancelled, and Claude then waits for your next instruction. Reverting the earlier edits is a separate step through checkpoints, not something `Esc` does.
- In Claude Code, who chooses the next tool call, and what does the harness add around that choice?The model chooses, based on your prompt and what the previous tool results showed. Claude Code, the harness, provides the tools, runs them, checks each call against the permission mode and rules, and manages the context the model sees, including what is kept when the window fills.
- Claude Code plans every tool call up front, then executes the list unchanged.
- Claude always runs the tests before finishing, whether or not you ask.
- Pressing Esc mid-turn rolls back every edit Claude made in that turn.
- The model runs tools itself; Claude Code only renders the chat.
- A message typed while Claude works is lost unless you press Esc first.