VIEW
EXPLORER1,884 files
src
main.tsx4683L
QueryEngine.ts890L
Tool.ts140L
Task.ts220L
AppState.tsx360L
context.ts88L
commands.ts312L
query.ts280L
history.ts185L
cost-tracker.ts130L
tools
AgentTool
BashTool
PowerShellTool
FileEditTool
FileReadTool
FileWriteTool
GlobTool
GrepTool
WebFetchTool
WebSearchTool
TodoWriteTool
TaskCreateTool
TaskOutputTool
TaskGetTool
TaskListTool
TaskStopTool
TaskUpdateTool
SendMessageTool
TeamCreateTool
TeamDeleteTool
MCPTool
ListMcpResourcesTool
ReadMcpResourceTool
McpAuthTool
SkillTool
ScheduleCronTool
RemoteTriggerTool
EnterWorktreeTool
ExitWorktreeTool
EnterPlanModeTool
ExitPlanModeTool
REPLTool
LSPTool
NotebookEditTool
AskUserQuestionTool
BriefTool
ConfigTool
SleepTool
SyntheticOutputTool
ToolSearchTool
shared
utils.ts120L
services
api
mcp
analytics
compact
lsp
oauth
plugins
autoDream
bridge
bridgeMain.ts2809L
replBridge.ts2267L
remoteBridgeCore.ts958L
initReplBridge.ts545L
sessionRunner.ts512L
bridgeApi.ts482L
bridgeUI.ts467L
bridgeMessaging.ts423L
ContextVisualization.tsx486L
createSession.ts348L
replBridgeTransport.ts360L
trustedDevice.ts197L
bridgeEnabled.ts193L
envLessBridgeConfig.ts159L
inboundAttachments.ts159L
codeSessionApi.ts158L
bridgeDebug.ts124L
workSecret.ts122L
pollConfig.ts108L
bridgeStatusUtil.ts144L
debugUtils.ts130L
jwtUtils.ts231L
types.ts242L
inboundMessages.ts74L
bridgePointer.ts192L
sessionIdCompat.ts53L
capacityWake.ts50L
bridgePermissionCallbacks.ts39L
replBridgeHandle.ts31L
bridgeConfig.ts43L
flushGate.ts64L
pollConfigDefaults.ts77L
buddy
companion.ts410L
species.ts680L
soulGen.ts120L
stats.ts95L
coordinator
components
utils
commands
vim
ink
native-ts
hooks
constants
context
state
types
memdir
assistant
bootstrap
schemas
migrations
keybindings
skills
screens
server
remote
outputStyles
plugins
entrypoints
query
cli
tasks
voice
moreright
upstreamproxy
SELECTED
src/main.tsxsrc/main.tsx
1#!/usr/bin/env bun2// main.tsx β Claude Code CLI entry point (4,683 lines)3// Commander.js CLI + React/Ink terminal renderer45import { Command } from "commander";6import { render } from "ink";7import React from "react";8import { QueryEngine } from "./QueryEngine.js";9import { AppState } from "./state/AppState.js";10import { loadAllTools } from "./tools.js";11import { bootstrapState } from "./bootstrap/state.js";12import { initAnalytics } from "./services/analytics/index.js";1314const program = new Command("claude").description("Anthropic Claude Code").version(PKG_VERSION);1516// 70+ subcommands registered here:17program.addCommand(require("./commands/session/index.js").default);18program.addCommand(require("./commands/review/index.js").default);19// ... (68 more commands)2021program22 .option("--model <id>", "Override default model")23 .option("--dangerously-skip-permissions", "Bypass permission checks")24 .option("--auto-mode", "Non-interactive auto mode")25 .action(async (opts) => {26 const state = await bootstrapState(opts);27 const tools = loadAllTools(state); // Map<string, Tool>28 const engine = new QueryEngine({ tools, state });29 await initAnalytics(state);3031 // React/Ink renders the terminal UI (like React but in your terminal!)32 const { unmount } = render(<AppRoot engine={engine} state={state} />, { exitOnCtrlC: false });3334 process.on("SIGINT", () => { engine.abort(); unmount(); });35 process.on("SIGTERM", () => { engine.abort(); unmount(); });36 });3738program.parse(process.argv);
File: main.tsxLines: 38Lang: TypeScript
FILE EXPLAINERIntermediate
main.tsx
What this file does
The application's front door β the very first code that runs when you type `claude` in your terminal.
Plain-English Analogy
π« Think of it as an airport check-in system. You arrive (run `claude`), it reads your ticket (CLI args), checks your identity (auth), and routes you to the right gate (feature or interactive loop). Without it, the whole airport shuts down.
How It Works β Step by Step
1
Node.js executes this file
When you type `claude`, your shell finds the binary, which points Node to run main.tsx. This file owns the entire startup sequence.
2
Commander.js registers 70+ commands
Each subcommand (review, model, sessionβ¦) is imported as a module and added to the program object. Commander handles --flags, --help, and argument parsing automatically.
3
React/Ink renders the terminal UI
React isn't just for browsers. Ink is a framework that lets React render into terminal output using box/text layout (similar to flexbox). Every chat bubble and spinner is a React component.
4
QueryEngine is created with all tools
loadAllTools() collects all 40+ tool implementations into a Map<string, Tool>. The QueryEngine gets this map β it never imports tools directly, only the Tool interface.
5
The agent loop begins
The app enters a readline-style loop: read user input β send to QueryEngine β stream response back. SIGINT (Ctrl+C) triggers a clean shutdown that aborts any running tool calls.
Connections to Other Files
β¬ This file imports from:
QueryEngine.tsβ Creates the LLM orchestration engine with toolsAppState.tsxβ Initialises the reactive state storetools.tsβ Loads all 40+ tools into a registry Mapservices/analyticsβ Initialises GrowthBook feature gatesβ¬ Used by:
Node.js runtime (nothing imports this β it IS the entry point)Key Concepts to Study
Commander.js CLI frameworkReact / Ink terminal UIEntry Point PatternDependency InjectionProcess signal handling
Ask the AI β Smart Questions
Click any question to paste it into the chat β
Code Intelligence
β gemini-2.5-flash
182K LOC ctx
AI ANALYST
π I've indexed 182,039 lines across 1,884 TypeScript files from the claude_code_Template codebase.
Click any file in the explorer β the File Explainer (panel 3) will break it down for you in plain English. Then ask me anything here!
Gemini 2.5 Flash Β· 182,039 LOC indexed