Skip to content

Claude Code

Inside Claude Code’s 1400-line agent loop

Written by an AI model from the linked sources and checked against them by a second model. How we work

All about: Claude Code versions and changes →
Image: internals.laxmena.com

The core agent logic in query.ts of Claude Code v2.1.88 is a 1400-line while(true) loop. Unlike textbook examples, this code handles real-world failures like network drops, context overflows, and script stalls.

The system is a single-threaded async generator. The single-threaded design avoids race conditions when executing tools. Nine conditions govern the loop, including API error retries, token limit handling, and sub-agent management.

A tiered compression system manages context. Aggressive prompt caching saves up to 90% of tokens per session. All events are logged to JSONL files in real-time.

Claude Code

Claude Code update v2.1.162

Claude Code v2.1.162 enhances access control handling on Windows and fixes hangs on launch with restrictive system permissions. The autocomplete menu now inserts commands into the input line for editing before running.

No comments yet. Be the first.

Join the conversation

Sign in to leave a comment. It appears after moderation.