NachschlagenQuellenregister

Dokumentationerreichbar

Anthropic, How the agent loop works

code.claude.com (externe Seite)

Die Seite des Agent SDK zur Agentenschleife von Claude Code: wie eine Nachricht durch die Schleife läuft, wie Werkzeuge ausgeführt werden, was das Kontextfenster füllt, wann verdichtet wird und wo Hooks eingreifen.

geprüft 10.11.2026

Worauf sich diese Seite beruft, wörtlich, abgerufen am 14.10.2026:

  • the SDK runs the same execution loop that powers Claude Codebestätigt 10.11.2026
  • Claude receives your prompt, along with the system prompt, tool definitions, and conversation history.bestätigt 10.11.2026
  • A turn is one pass through the loopbestätigt 10.11.2026
  • That was four turns: three with tool calls, one final text-only response.bestätigt 10.11.2026
  • Every request for core built-in tools such as Bash, Read, and Edit; on demand for MCP tools and other built-in tools, which tool search defers by defaultbestätigt 10.11.2026
  • can chain dozens of tool calls across many turnsbestätigt 10.11.2026
  • Uses a model classifier to review actions such as shell commands and network requestsbestätigt 10.11.2026
  • A turn is one pass through the loop: Claude produces output, and if it includes tool calls, the SDK executes them and the results feed back to Claude automatically.bestätigt 10.11.2026
  • This happens without yielding control back to your code.bestätigt 10.11.2026
  • ResultMessage: marks the end of the agent loop.bestätigt 10.11.2026
  • Read-only tools (like Read, Glob, Grep, and MCP tools marked as read-only) can run concurrently.bestätigt 10.11.2026
  • Tools that modify state (like Edit, Write, and Bash) run sequentially to avoid conflicts.bestätigt 10.11.2026
  • When a tool is denied, Claude receives a rejection message as the tool result and typically attempts a different approach or reports that it couldn’t proceed.bestätigt 10.11.2026
  • Without limits, the loop runs until Claude finishes on its ownbestätigt 10.11.2026
  • Setting a budget is a good default for production agents.bestätigt 10.11.2026
  • Count each turn with tool calls, plus one for the final text-only response.bestätigt 10.11.2026
  • Without that extra turn, the run ends with a ResultMessage of subtype error_max_turns and no final response.bestätigt 10.11.2026
  • max_turns=2 in the loop above would have stopped before the edit stepbestätigt 10.11.2026
  • The response that reaches the cap still completes and counts toward total_cost_usd.bestätigt 10.11.2026
  • The subtype field (available in both SDKs) is the primary way to check termination state.bestätigt 10.11.2026
  • Tool calls that need approval and aren’t covered by allow rules trigger your canUseTool callback; no callback means denybestätigt 10.11.2026
  • Also emitted for any user inputs you stream mid-loop.bestätigt 10.11.2026
  • No valid structured output was produced within the configured retry limit: every attempt failed validation, or a model fallback retracted the completed output with no successful retrybestätigt 10.11.2026
  • Every call that would otherwise prompt is denied, though a mod you installed can still approve some of those calls.bestätigt 10.11.2026
  • Runs tool calls without asking for approval, including calls to tools you didn’t list in allowedTools. A few calls still go to your canUseTool callbackbestätigt 10.11.2026
  • Never prompts.bestätigt 10.11.2026

31 Der Harness

Alle Quellen

↑↓ auswählenEnter öffnenDie Suche läuft im Browser. Nichts wird übertragen.