Entry Points & Initialization
How the application starts up, parses arguments, and boots into a session.
The Boot Sequence
Shared from "Claude-Code" on Inkdown
How the application starts up, parses arguments, and boots into a session.
Location: src/main.tsx (2000+ lines, the largest file)
Startup optimization: Fires parallel subprocesses (MDM, keychain) at the very top of the file so they complete during module import time (~135ms window).
Feature flag gating: Uses feature('FLAG_NAME') from bun:bundle for dead code elimination. Many features are compiled out of the external build:
KAIROS — assistant modeCOORDINATOR_MODE — multi-agent orchestrationBRIDGE_MODE — remote controlVOICE_MODE — voice inputSSH_REMOTE — SSH remote sessionsDIRECT_CONNECT — direct connect serverURL/deep link handling: Processes cc:// and cc+unix:// URLs for direct connect, and --handle-uri for OS protocol handler integration.
SSH mode: Parses claude ssh <host> [dir] and stashes host/dir for the REPL to pick up. Supports --local, --dangerously-skip-permissions, --permission-mode, --resume, --continue, --model.
Client type detection: Determines how the app was launched:
cli — direct terminal usagesdk-cli — non-interactive SDK callgithub-action — running in GitHub Actionssdk-typescript / sdk-python — SDK usageclaude-vscode / claude-desktop — IDE integrationremote — remote session via WebSocketlocal-agent — Desktop's local agent modeCommander.js setup: Defines all CLI flags and subcommands.
Location: src/setup.ts (477 lines)
Called after CLI parsing, before the REPL renders. Sets up the session environment.
Node version check: Requires Node.js 18+
Session ID: Switches to custom session ID if provided
UDS Messaging Server (Unix Domain Sockets): Starts a local socket server for inter-process communication (Mac/Linux only). Used for swarm teammate communication.
Terminal backup restoration: If a previous setup was interrupted (iTerm2 or Terminal.app), restores original settings.
Set CWD: The most critical call — setCwd(cwd) must happen before anything else that depends on the working directory.
Hooks config snapshot: Captures the current hooks configuration to detect hidden modifications later.
Worktree creation (if --worktree flag):
Background jobs:
initSessionMemory() — registers memory extraction hooksinitContextCollapse() — initializes context collapse servicelockCurrentVersion() — prevents deletion by other processesPlugin prefetch: Loads plugin hooks and sets up hot reload
Attribution hooks (ant-only): Registers commit attribution tracking
Team memory sync watcher: Starts watching for team memory changes
Analytics beacon: Emits tengu_started event (earliest reliable "process started" signal)
API key prefetch: Prefetches if trust is already established
Release notes check: Pre-fetches data for the logo/release notes display
Bypass permissions verification: If --dangerously-skip-permissions, verifies sandbox/isolated environment (Docker, no internet, not root)
Previous session telemetry: Logs tengu_exit from the last session (cost, duration, tokens, FPS)
Location: src/migrations/
Run at startup to migrate user settings/config between versions. Current migration version: 11.
Migrations include:
migrateAutoUpdatesToSettings — moved auto-update setting to settings.jsonmigrateBypassPermissionsAcceptedToSettings — moved to settingsmigrateEnableAllProjectMcpServersToSettings — moved to settingsresetProToOpusDefault — changed default modelmigrateSonnet1mToSonnet45 — model string migrationmigrateLegacyOpusToCurrent — model string migrationmigrateSonnet45ToSonnet46 — model string migrationmigrateOpusToOpus1m — model string migrationmigrateReplBridgeEnabledToRemoteControlAtStartup — renamed settingresetAutoModeOptInForDefaultOffer — auto-mode resetmigrateFennecToOpus — ant-only model migrationmigrateChangelogFromConfig — async, fire-and-forgetLocation: src/entrypoints/
Different ways the application can be launched:
| File | Purpose |
|---|---|
cli.tsx | Standard CLI entry (interactive TUI) |
init.ts | Core initialization (auth, settings, telemetry) |
mcp.ts | MCP server mode (claude mcp serve) |
sandboxTypes.ts | Type definitions for sandboxed execution |
agentSdkTypes.ts | Type definitions for agent SDK |
sdk/ | SDK-specific entrypoints |
The init() function (called from the preAction hook) handles:
-p / --print)sdk-cli| File | Lines | Purpose |
|---|---|---|
src/main.tsx | ~2000 | CLI entry, Commander.js setup, feature flags |
src/setup.ts | 477 | Session initialization |
src/entrypoints/init.ts | ~200 | Core init (auth, settings, telemetry) |
src/entrypoints/cli.tsx | ~100 | Interactive CLI entry |
src/interactiveHelpers.tsx | ~300 | Render context, setup screens, exit handling |
src/replLauncher.tsx | ~200 | Launches the REPL component |
src/dialogLaunchers.tsx | ~100 | Dialog/wizard launchers |
src/migrations/ | varies | Startup migrations |