01. Startup Flow

Why main.tsx Matters

main.tsx is not just a render file. It acts like the process coordinator for the whole CLI. The top of the file already reveals product priorities: startup profiling, managed-device reads, keychain prefetching, feature gates, analytics setup, model selection, settings refresh, command loading, and tool setup.

Startup Pattern

  1. Run startup side-effects early to hide latency behind module loading.
  2. Load configuration, auth state, remote settings, quota state, and telemetry gates.
  3. Resolve the active tool set and command set.
  4. Build render context and initialize the terminal UI.
  5. Enter the main interaction loop or command mode.

What commands.ts Tells You

The command registry is wide and feature-gated. This shows that the product is not organized as a single chat command. It behaves more like a shell application with many operating modes: onboarding, doctor, memory, permissions, hooks, MCP, sessions, upgrade, review, compact, model switching, and more.

The heavy use of feature flags suggests one codebase serving multiple product variants and experiments.

Key Takeaway

The startup path is optimized like an application, not a demo. It overlaps I/O, prefetches credentials, prepares settings, and gates features before the main UI loop starts. That is a product engineering lesson: responsiveness begins before the first token is generated.

Source Navigation

Recommended Source Files

  • source/main.tsx
  • source/interactiveHelpers.tsx
  • source/entrypoints
  • source/services/api/bootstrap.ts
  • source/services/remoteManagedSettings/index.ts

Next Files to Read

  • source/commands.ts
  • source/state/AppStateStore.ts
  • source/components/TrustDialog/TrustDialog.tsx