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 Code
bestätigt 10.11.2026Claude receives your prompt, along with the system prompt, tool definitions, and conversation history.
bestätigt 10.11.2026A turn is one pass through the loop
bestätigt 10.11.2026That was four turns: three with tool calls, one final text-only response.
bestätigt 10.11.2026Every 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 default
bestätigt 10.11.2026can chain dozens of tool calls across many turns
bestätigt 10.11.2026Uses a model classifier to review actions such as shell commands and network requests
bestätigt 10.11.2026A 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.2026This happens without yielding control back to your code.
bestätigt 10.11.2026Result
bestätigt 10.11.2026Message: marks the end of the agent loop. Read-only tools (like Read, Glob, Grep, and MCP tools marked as read-only) can run concurrently.
bestätigt 10.11.2026Tools that modify state (like Edit, Write, and Bash) run sequentially to avoid conflicts.
bestätigt 10.11.2026When 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.2026Without limits, the loop runs until Claude finishes on its own
bestätigt 10.11.2026Setting a budget is a good default for production agents.
bestätigt 10.11.2026Count each turn with tool calls, plus one for the final text-only response.
bestätigt 10.11.2026Without that extra turn, the run ends with a Result
bestätigt 10.11.2026Message of subtype error_max_turns and no final response. max_turns=2 in the loop above would have stopped before the edit step
bestätigt 10.11.2026The response that reaches the cap still completes and counts toward total_cost_usd.
bestätigt 10.11.2026The subtype field (available in both SDKs) is the primary way to check termination state.
bestätigt 10.11.2026Tool calls that need approval and aren’t covered by allow rules trigger your canUseTool callback; no callback means deny
bestätigt 10.11.2026Also emitted for any user inputs you stream mid-loop.
bestätigt 10.11.2026No 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 retry
bestätigt 10.11.2026Every call that would otherwise prompt is denied, though a mod you installed can still approve some of those calls.
bestätigt 10.11.2026Runs tool calls without asking for approval, including calls to tools you didn’t list in allowed
bestätigt 10.11.2026Tools. A few calls still go to your canUseTool callback Never prompts.
bestätigt 10.11.2026