Core Architecture

The 4 foundational files that power Claude Code. Each one is its own deep-dive page.

01

main.tsx

The Entry Point

CLI bootstrap, React/Ink rendering, parallel pre-loading, feature gating. Where 'claude' starts executing.

4,683 lines 803KB TSX
02
🧠

QueryEngine.ts

The Brain

Manages the full query lifecycle: API conversations, tool orchestration, permissions, token tracking, message history.

1,295 lines 46KB TS
03
🔄

query.ts

Execution Loop

The main conversation loop: construct messages, check token budget, call API, stream response, execute tools, repeat.

68KB 80% compaction TS
04
🔧

Tool.ts

Tool Interface System

Defines how all 45+ tools work: the Tool type, permission modes (Default/Auto/Bypass), execution interface.

792 lines 29.5KB TS