Components Module
346 files · ~40K linesReact for the Terminal — Ink components powering the REPL. The largest module by file count (346 files). Uses the same React patterns as web apps, but renders to ANSI escape codes via the yoga-layout flexbox engine.
Ink = React Native for the Terminal
Web / React Native / Ink — The Same Abstraction
The same flexbox engine runs in all three contexts. Only the output target differs.
div, spanCSS flexbox (browser)useState, useEffectPixels on screenView, TextYoga engineuseState, useEffectNative UI widgetsBox, TextSame Yoga engineuseState, useEffectANSI → terminalThe Rendering Stack — JSX to Terminal in 5 Layers
How your React component becomes terminal text — the 5-layer transformation.
Box, Text, flexbox props — you write thisReact reconciler + useState/useEffectFlexbox calculations (same as React Native)\x1b[32m, cursor movements, terminal rows/colsYour terminal window renders thisREPL.tsx — 5005 Lines, 6 Responsibilities
What a single file manages for the entire Claude Code interactive session.
Multi-line input, history navigation, paste detection, slash command autocomplete
Subscribes to QueryEngine async generator — each token triggers a re-render showing partial output
Each tool type has its own renderer: BashTool shows colored output, FileEdit shows diffs, WebFetch shows extracted content
Renders terminal dialogs for tool approval — Allow once / Always allow / Never — inline in the REPL
Spinning indicators during API calls, compaction notices, MCP connection status, token usage bar
Maintains UI state: scroll position, collapsed/expanded tool results, model name display
Component Tree
The hierarchy of major components inside REPL.tsx.
main.tsxentryscreens/REPL.tsx5K linescomponents/Inputcomponents/Messagescomponents/ToolResultcomponents/PermissionDialogcomponents/StatusBarCLI entry — initializes Ink, renders REPL into terminal stdout
5005-line main screen, owns all REPL state
Multi-line text input with history
Scrollable message list
Per-tool result renderers
Allow/deny terminal dialog
Token usage, model, MCP status
Key Files
screens/REPL.tsx5005 linesMain REPL screen — orchestrates all terminal UI state
components/150+ filesInk terminal components: prompts, tool results, messages, spinners
main.tsx4683 linesCLI initialization, renders REPL into terminal via Ink
ink/~80KBCustom Ink fork — yoga-layout flexbox engine for terminal rendering
cli/print.ts5594 linesFormatted terminal output, ANSI styling, diff rendering
hooks/~30KBPermission hooks, tool approval UI hooks, state bindings
utils/hooks.ts (5022 lines) provides the React hooks that Components binds to — state, streaming, input.
REPL subscribes to the QueryEngine async generator stream for live streaming token display.
Components use services/analytics to track user interactions like command usage.