1421-Line While Loop
- Entity ID:
ent-20260419-14d5ba7d2378 - Type:
concept - Scope:
shared - Status:
active - Aliases: while(true) loop, query.ts main loop, agentic loop body
Description
The 1,421-line while(true) state-machine loop body in query.ts (lines 307-1728) that serves as the heartbeat of Claude Code — orchestrates compression, model calls, streaming tool execution, error recovery, hooks, and attachment injection per iteration.
Key claims
- stop_reason==='tool_use' is unreliable
- State machine replaced recursion to avoid stack overflow
- query.ts while loop body is 1,421 lines
- Program quality, not model quality, separates Claude Code from OSS agents
- Each iteration runs 10 fixed steps in order
- Shell injection sinks sit outside the agent loop
- 9 distinct continue points in the query loop
- print.ts 3,167-line function and query.ts 1,421-line while loop are the canonical god-function examples
Relations
- 1421-Line While Loop --[contains]--> query.ts
- Harrison Security query.ts Deep Dive --[summarizes]--> 1421-Line While Loop
- 1421-Line While Loop --[uses]--> Query Loop State Object
- 1421-Line While Loop --[implements]--> 10 Steps Per Iteration
- query.ts --[implements]--> 1421-Line While Loop