Ink Internals & Terminal Rendering
Overview
Ink is a React renderer for terminals. Claude Code uses a customized Ink that handles layout (Yoga), ANSI escape codes, input handling, and screen updates. Understanding Ink is key to understanding the UI.
Plain text
┌─────────────────────────────────────────────────────────────────────────────┐
│ INK RENDERING PIPELINE │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ REACT LAYER │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ JSX/TSX │───►│ React │───►│ Reconciler│───►│ Ink │ │
│ │Components│ │ Virtual │ │ (diff) │ │ Renderer │ │
│ │ │ │ DOM │ │ │ │ │ │
│ └──────────┘ └──────────┘ └──────────┘ └────┬─────┘ │
│ │ │
│ LAYOUT LAYER ▼ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Ink Nodes │───►│ Yoga │───►│ Geometry │ │
│ │ (tree) │ │ (flexbox) │ │ (x,y,width, │ │
│ │ │ │ │ │ height) │ │
│ └──────────────┘ └──────────────┘ └───────┬──────┘ │
│ │ │
│ OUTPUT LAYER ▼ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ ANSI Codes │◄───│ Output │◄───│ Screen │ │
│ │ Generation │ │ Buffer │ │ Rendering │ │
│ │ │ │ │ │ │ │
│ └──────┬───────┘ └──────────────┘ └──────────────┘ │
│ │ │
│ ▼ │
│ ┌──────────────┐ │
│ │ Terminal │ │
│ │ stdout │ │
│ └──────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────┘