Skip to content

Definition

The core control loop where Claude requests tool calls, your code executes them and returns results, and the conversation is resent until Claude answers naturally — while stop_reason == 'tool_use': execute tools → append tool_result → resend.

Key points

  • Only stop_reason: "tool_use" continues the loop; every other stop reason exits it. See Stop reasons.
  • Default tool_choice is auto: each turn Claude decides to call a tool or respond directly. Loop ends when Claude answers naturally (stop_reason: "end_turn").
  • On tool_use: response contains one or more tool_use blocks; your code executes the operation and sends back a tool_result (in a user message), then resends the whole conversation.
  • Steerable via system prompt (e.g. "Always call a tool first before responding.").
  • Client SDK: you run the loop yourself. Agent SDK: Claude runs the gather→act→verify loop inside query() — same tools, agent loop, and context management that power Claude Code.
  • Applies to Tool execution types (client vs server): only client tools require you to build the tool_result and continue the loop.

Why it matters for the exam

  • D1 is 27% of scored content and the loop is its backbone; expect questions asking which stop_reason continues vs exits, and who runs the loop (Client SDK vs Agent SDK).

Common gotchas

  • Every non-tool_use stop reason ends the loop — including pause_turn, which requires a special resend rather than tool execution (see pause_turn handling).
  • All parallel tool_use blocks in one response must be answered with all their tool_result blocks in a single following user message.

See also

Sources