component-architecture-deep-dive.md (1,695 lines, 51 KB)
The comprehensive reverse-engineering analysis of Claude Code v2.1.88's React component architecture. This is the main deliverable.
- Executive Summary — High-level overview of architecture priorities
- Section 1: Component Hierarchy & Topology — Root composition, screen structure, classification
- Section 2: State Management Architecture — Zustand-like store, AppState, context providers, settings layers
- Section 3: PromptInput Deep-Dive (2,338 lines analyzed) — Command queue, highlighting, footer pills, typeahead, image pasting, history, agent/teammate integration, vim mode
- Section 4: Message Rendering Pipeline — Normalization, filtering, grouping, virtual scrolling, message row dispatch, message actions
- Section 5: Permission UI System (51+ components analyzed) — Three-tier permissions, rule management, decision logic
- Section 6: Modal & Dialog System — OverlayContext, focus management, Dialog primitive, stacking
- Section 7: Settings Architecture (Config.tsx 1,821 lines) — Tabs, managed enums, search, three-layer config hierarchy
- Section 8: Scroll & Input Handling (ScrollKeybindingHandler 1,011 lines) — Acceleration curves, trackpad detection, keybindings
- Section 9: Performance Patterns — React.memo, memoization, React Compiler annotations, virtual scrolling, lazy loading
- Section 10: Design System — Dialog, Tabs, Pane, SearchBox, KeyboardShortcutHint primitives
- Section 11: Error Handling & Boundaries — SentryErrorBoundary, Suspense, graceful degradation
- Section 12: Key Constants & Context Providers — Input modes, command types, analytics events, provider matrix
- Section 13: Data Flow Diagrams — User input to execution, teammate messaging, permission mode cycling
- Section 14: Key Design Decisions & Trade-offs — Custom store vs Redux, selective rendering, virtual scrolling, feature gating, stash, settings
- Section 15: Security & Attack Vectors (Secondary addendum) — Vulnerabilities, mitigations, recommendations
- Appendix: File Size Reference — Tier 1, Tier 2, design system file sizes
- ast-analysis.md — AST-level analysis of component structure
- bootstrap-entry-point.md — Entry point and initialization flow
- codebase-structure.md — File organization and module layout
- data-flow-and-coupling.md — Inter-component data dependencies
- graph-and-complexity.md — Component dependency graph and complexity metrics
- native-ts-reimplementations-deep-dive.md — Ink.js and native terminal implementations
- query-engine-deep-dive.md — Main query loop and command execution engine
- state-migrations-output-deep-dive.md — State persistence and migration
- terminal-ui-deep-dive.md — Terminal rendering and input handling
Codebase analyzed: 389 component files, 81,546 lines of code
Tier 1 files (read completely): 8 files
- PromptInput/PromptInput.tsx: 2,338 lines
- Settings/Config.tsx: 1,821 lines
- LogSelector.tsx: 1,574 lines
- Stats.tsx: 1,227 lines
- permissions/PermissionRuleList.tsx: 1,178 lines
- mcp/ElicitationDialog.tsx: 1,168 lines
- VirtualMessageList.tsx: 1,081 lines
- ScrollKeybindingHandler.tsx: 1,011 lines
Tier 2 files (first 200 lines + key sections): 11 files
Design system components: Dialog, Tabs, Pane, SearchBox, KeyboardShortcutHint, Divider, Byline
- State Management — Custom Zustand-like store with useSyncExternalStore
- Selective Rendering — Fine-grained selectors prevent unnecessary re-renders
- Performance Optimization — React.memo, React Compiler, virtual scrolling, feature gates
- Permission System — 51+ dedicated components for nuanced tool control
- Real-time Interactivity — Keybinding context, event handlers, immediate feedback
- Multi-agent Coordination — Mailbox pattern for in-process teammate communication
- No Redux overhead — Custom store is ~200 lines, hand-tuned for terminal rendering
- 2800+ message sessions — Stay performant via virtual scrolling and memoization
- React Compiler annotations — _c arrays enable auto-memoization without explicit React.memo
- Feature gates at compile-time — bun:bundle eliminates dead code for multi-tenant builds
- Three-layer settings — GlobalConfig (user) + LocalSettings (project) + AppState (runtime)
- Permission triaging — Mode (auto/manual/bypass) + Rules (pattern/scope/action) system
- State is authoritative — No duplicated state; single AppState object
- Selectors are pure — Only return existing object references (no new objects in selectors)
- Terminal rendering is synchronous — No batching needed; updates immediate
- Permissions are composable — Rules combine with mode for flexible security model
- Pragmatic simplicity — Custom solution beats off-the-shelf library for this use case
Quick overview: Read the Executive Summary and Section 1.
Understanding state management: Read Sections 2 and 13 (Data Flow Diagrams).
Deep-diving on PromptInput: Read Section 3 in full (command queue, highlighting, footer pills, typeahead, image pasting, history, teammates, vim mode).
Understanding message rendering: Read Section 4 and trace through Messages.tsx + VirtualMessageList.tsx + MessageRow dispatch logic.
Permission system: Read Sections 5, 14, and 15 (design decisions, attack vectors).
Performance patterns: Read Section 9 and look at React.memo, useMemo, virtual scrolling patterns.
- Holistic reading — Read Tier 1 files completely (8 files, 8,398 LOC)
- Sampling — Tier 2 files (first 200 lines + key sections)
- State tracing — Read AppState.tsx, store.ts, context providers
- Data flow analysis — Trace from user input → command execution → message rendering
- Component relationships — Map how components interact via props and context
- Performance investigation — Identify memoization patterns, React Compiler usage, virtual scrolling
- Documentation synthesis — Distill into coherent architecture narrative
- src/state/AppState.tsx
- src/state/store.ts
- src/components/PromptInput/PromptInput.tsx (2,338 lines)
- src/components/ScrollKeybindingHandler.tsx (1,011 lines)
- src/components/TextInput.tsx / VimTextInput.tsx
- src/components/Messages.tsx (833 lines)
- src/components/VirtualMessageList.tsx (1,081 lines)
- src/components/Settings/Config.tsx (1,821 lines)
- src/components/permissions/ directory
- Key: PermissionRuleList.tsx (1,178 lines)
- Other: ExitPlanModePermissionRequest.tsx, PermissionRequest.tsx, etc.
- src/components/design-system/ (Dialog, Tabs, Pane, SearchBox, etc.)
- src/components/ (ModelPicker, QuickOpenDialog, HistorySearchDialog, etc.)
Analysis completed: April 2, 2026 Scope: Engineering architecture, composition patterns, state management, data flow, design decisions Security addendum: Attack vectors and mitigations in Section 15