Architecture Overview
1,902 files, 512K lines of TypeScript — a complete anatomy of an AI coding assistant
~5 min read
Project Scale #
How big is Claude Code?
Imagine a 1,000-page technical book with 500 lines of code per page — that's the scale of Claude Code. It's written in TypeScript, runs on Bun (a JavaScript runtime faster than Node.js), and uses React to draw its UI — not in a browser, but in your terminal.
0
Source files
0
Lines of code
0
.ts files
0
.tsx files
Module Overview #
Bubble area = lines of code, color = architecture layer
Tech Stack #
What powers Claude Code?
Bun
JavaScript/TypeScript runtime, 3-5x faster than Node.js
TypeScript
Type-safe JavaScript with strict typing throughout
React + Ink
React rendering to terminal instead of browser, component-based TUI
Yoga
Facebook's Flexbox layout engine for terminal layout
Zod
Runtime type validation for tool inputs and config
tree-sitter
AST parsing for Bash commands, used for security analysis
Directory Structure #
Click folders to expand
Design Highlights #
Engineering practices worth learning from Claude Code
Async Generators Power Everything
From API streaming to tool execution, all data flows use async generators. Flat memory usage, real-time UI updates, native cancellation support.
Read-Parallel, Write-Serial Tool Scheduling
Read ops (Glob, Grep, Read) run safely in parallel. Write ops (Edit, Write, Bash) must run serially. This simple partitioning dramatically improves speed while avoiding race conditions.
Three-Layer Defense-in-Depth Permissions
ML classifier handles 80% of common cases, rule engine covers user-defined policies, confirmation dialog is the last resort. A perfect balance of speed and safety.
Feature-Gated Progressive Rollout
Feature flags via feature('FLAG_NAME') control rollout by user type, environment, or percentage. Unused code is eliminated by Bun's bundler.
Related Pages
← → arrow keys to navigate