IT Services Circle
Jun 12, 2026 · Artificial Intelligence
Inside Claude Code’s Query Loop: From a Simple While Loop to an Industrial‑Grade Agent Engine
This article dissects Claude Code’s 1729‑line queryLoop, explaining its four‑layer call chain (ask → QueryEngine → query → queryLoop), the async‑generator core that streams model output, how tool calls are handled in parallel, the explicit state object, and the many error‑recovery paths that make the loop production‑ready.
Async GeneratorClaude CodeError Recovery
0 likes · 27 min read
