The Entry Point - Where Everything Begins
main.tsx is the primary entry point for Claude Code. When you run claude in your terminal, this is the first file that executes. It's responsible for the entire application lifecycle - from parsing CLI arguments to rendering the interactive UI.
Parses arguments, sets up Commander.js commands
Renders the terminal interface using React and Ink
Loads API keys from Keychain, manages trust dialogs
Parallel pre-loading saves ~135ms on startup
// STEP 1: Performance Profiling (Before ANY imports)
import { profileCheckpoint } from './utils/startupProfiler'
profileCheckpoint('main_module_eval_start')
// STEP 2: Parallel Pre-Loading (MDM + Keychain)
// These fire BEFORE heavy module evaluation (~135ms)
import { startMdmRawRead } from './utils/mdm'
startMdmRawRead() // Spawns subprocess to read MDM config
import { startKeychainPrefetch } from './utils/keychainPrefetch'
startKeychainPrefetch() // Reads OAuth + API key from macOS Keychain
// STEP 3: Heavy Module Evaluation (~135ms of imports)
import { CommanderCommand } from '@commander-js/extra-typings'
import React from 'react'
import { feature } from 'bun:bundle' // Build-time feature gating
// ... 100+ more imports
The ordering here is critical for performance. By firing MDM reads and Keychain prefetch BEFORE the heavy imports, the I/O happens in parallel with JavaScript module evaluation, saving ~135ms on startup.
// Build-time dead code elimination
if (feature('COORDINATOR_MODE')) {
// This entire block is removed from the bundle
// if COORDINATOR_MODE is not enabled at build time
const { coordinatorMode } = require('./coordinator')
}
if (feature('KAIROS')) {
// Proactive assistant mode - conditionally loaded
const { kairosInit } = require('./assistant')
}
if (feature('VOICE_MODE')) {
// Voice input/output - Speech-to-Text support
const { voiceInit } = require('./services/voice')
}
Bun's feature() function enables build-time dead code elimination. If a feature flag is false at build time, the bundler completely removes the code block, reducing bundle size. This is different from runtime feature flags (GrowthBook) which check at execution time.
COORDINATOR_MODE
Multi-agent orchestration
KAIROS
Proactive assistant
VOICE_MODE
Speech-to-Text input
DREAM
Background maintenance
ULTRAPLAN
Advanced planning
UNDERCOVER
Stealth mode
init()Initializes the session: sets up telemetry, loads trust dialogs, prepares the working directory.
LifecyclefetchBootstrapData()Loads initial configuration from Anthropic's first-party API: model options, feature flags, remote settings.
NetworkgetTools()Assembles the complete tool list (45+ tools) with feature-gated conditional loading.
ToolsrenderAndRun()Starts the main interactive loop: renders the Ink terminal UI and enters the REPL (Read-Eval-Print Loop).
UIshowSetupScreens()Displays onboarding, trust dialogs, and configuration screens for first-time users.
OnboardingClone the repo and open src/main.tsx. Count how many imports happen before line 30. Can you spot the parallel pre-loading optimization?
git clone https://github.com/anthropics/claude-code.git
wc -l src/main.tsx
head -30 src/main.tsx