Skip to content

Main feature map for Claude Code

This document continues the static analysis of the extracted Claude Code runtime. Its goal is to answer a product/runtime question: what major capabilities are implemented by cli.js, and how do those capabilities connect?

The file is bundled/minified production JavaScript. The document therefore uses semantic aliases such as OuterBootstrap, CommanderRoot, HeadlessRunner, InteractiveSessionLoop, McpCoordinator, SessionRestorer, and RemoteControlBridge. Minified names are kept only as search anchors for this exact @anthropic-ai/claude-code@2.1.143 build.

Executive summary

cli.js is not a thin prompt wrapper. It is the main Claude Code agent runtime. It parses the command line, establishes process identity, loads settings and managed policy, initializes authentication and model/provider state, manages sessions, assembles tools, applies permissions, loads MCP servers and plugins, orchestrates custom agents and background agents, routes execution into interactive/headless/remote modes, and handles observability, updates, and shutdown.

Two useful lenses for the runtime are context engineering and harness engineering:

  • Context engineering decides what the model can see: system prompts, CLAUDE.md, settings, output styles, tools, agents, MCP prompts/resources, memories, file inputs, and session history.
  • Harness engineering decides how the model is embedded in a usable coding-agent runtime: modes, sessions, tools, permissions, hooks, streaming, retries, remote control, telemetry, and update behavior.

Source anchors

AreaSemantic aliasMinified anchor / exact stringApproximate locationRole
BootstrapOuterBootstrapasync function J9Aline ~19590, byte 0xddd998Handles version fast path and lazy-loads the main bundle.
Full mainTopLevelMainasync function O4Aline ~19524, byte 0xdbe79fInitializes environment identity, deep links, warnings, and calls w4A.
CommanderCommanderRootasync function w4Aline ~19525, byte 0xdbf0e0Builds root options, action body, preAction setup, and subcommands.
HeadlessHeadlessRunnerasync function T7A, function H89lines ~19324-19349, bytes 0xda31bb, 0xda50d0Runs print/SDK stream-JSON mode and drains control/message loops.
InteractiveInteractiveSessionLoopasync function pT$, async function aa4lines ~9586-9587, bytes 0xce6582, 0xcf7dceRuns the TUI/session loop and resume/search picker.
MCPMcpCoordinatorfunction fH9, function rR4lines ~19294, ~9173Connects runtime MCP servers and registers the mcp command tree.
SessionsSessionRestorerasync function jHH, async function OG8lines ~2773, ~9514Finds recent sessions and restores transcript state.
ToolsBuiltInToolNamesBash, Read, Edit, Write, Glob, Grep, WebFetch, WebSearch, TodoWrite, Skilllines ~446-1091Built-in tool-name constants and model-visible capability names.
HooksHookEventsPreToolUse, PostToolUse, SessionStart, SessionEnd, SubagentStart, TaskCreatedline ~185, byte 0x10b6b4Lifecycle hook and automation event surface.
OpsTrafficAndDebugGatesCLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC, CLAUDE_CODE_DEBUG_LOGS_DIRlines ~62, ~133Debug-log and telemetry/traffic policy boundaries.

Runtime system map

flowchart TB
Cli[cli.js bundled runtime] --> Bootstrap[Bootstrap and command surface]
Cli --> Modes[Runtime modes]
Cli --> Context[Context and model loop]
Cli --> Tools[Tools and permissions]
Cli --> Sessions[Sessions and persistence]
Cli --> Integrations[MCP / plugins / IDE / Chrome]
Cli --> Agents[Agents and automation]
Cli --> Ops[Diagnostics / telemetry / update]
Bootstrap --> Commands[auth / mcp / plugin / project / agents / doctor / update / install]
Modes --> TUI[Interactive TUI]
Modes --> Headless[Print / SDK stream JSON]
Modes --> Remote[Remote / teleport / Remote Control]
Context --> Prompt[CLAUDE.md / settings / system prompt / output styles]
Context --> Models[Auth / models / providers]
Context --> Stream[Provider request and streaming response]
Tools --> Builtins[Built-in coding tools]
Tools --> Policy[Allow/deny / permission mode / hooks]
Tools --> External[MCP tools / plugins / browser / IDE]
Sessions --> Jsonl[local-jsonl transcripts]
Sessions --> Resume[resume / continue / fork / rewind]
Sessions --> Bridge[remote session ingress]
Agents --> Custom[custom agents]
Agents --> Task[Task and background agent commands]
Agents --> Review[ultrareview / auto-mode]

Major feature matrix

Feature areaEntry point or triggerMain capabilitiesPrimary docs
Package/Bun startupNative Bun standalone executable, .bun graph entrypointLoads cli.js, pairs it with .jsc, embeds image/audio N-API modules.Package and Bun bootstrap
CLI command shellclaude, root flags, subcommandsVersion, root mode dispatch, auth, mcp, plugin, project, agents, doctor, update, install.Commands and flags
Interactive modeDefault TTY runSetup/login/trust screens, TUI root, resume picker, tools/agents/MCP load, and the interactive session loop.CLI main paths
Headless/SDK mode-p, --print, --sdk-url, non-TTY stdout, --init-onlyPrompt/stdin ingestion, stream-JSON input/output, permission/control frames, JSON/text result output.Headless streaming and resilience
Prompt/contextCLAUDE.md, .claude/settings.json, --system-prompt, --append-system-prompt, --add-dir, output stylesRuntime instruction sources, memory files, dynamic system prompt sections, slash-command/skill/agent context.Prompt, context, and memory
Models/auth/providersANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN, OAuth token FDs, provider env vars, --modelFirst-party/OAuth/API key auth, Bedrock/Vertex/Foundry/Anthropic AWS/Mantle provider selection, model aliases, thinking/budget flags.Models, providers, and auth
Built-in tools and permissionsTool constants plus --tools, --allowedTools, --disallowedTools, --permission-modeFile, shell, notebook, web, todo, skill, and task tools gated by filters, deny/allow rules, hooks, and permission modes.Built-in tools and permissions
MCP/plugins/hooksmcp, plugin, --mcp-config, --plugin-dir, hooks eventsMCP config/transport/lifecycle, plugin marketplaces/session plugins, hook events and command/HTTP hook policy.MCP, plugins, and hooks
Settings/policy/integrations.claude/settings.json, managed settings, --settings, --ide, --chrome, statusLineLayered settings, config roots, policy toggles, IDE/Chrome/file integration, API-key helper scripts.Settings, policy, and integrations
Sessions and transcripts--continue, --resume, --session-id, JSONL pathsLocal transcript roots, latest-session lookup, resume/continue, fork, no-persistence, rewind.Session resume and transcripts
Remote/teleport/control--remote, --teleport, remote-control, --rc, remote token env varsRemote session creation/attach, teleport hydration, Remote Control bridge, permission forwarding.Remote control and teleport
Agents and automationagents, --agents, task tool constants, subagent hook events, ultrareview, auto-modeBackground agents, custom agent JSON, task/subagent lifecycle, multi-agent review, permission classifier inspection.Agents, tasks, and subagents
Diagnostics/ops/media--debug-file, doctor, update, telemetry env vars, image/audio N-API modulesDebug logs, telemetry and traffic gates, native updater, doctor checks, media module extraction.Diagnostics and debug logs, Telemetry and tracing, Updater and doctor, Media native modules

Takeaways

The main capabilities in cli.js can be summarized as: bootstrap, modes, context, models, tools, integrations, sessions, remote control, agents, and operations.

More concretely:

  1. OuterBootstrap, TopLevelMain, and CommanderRoot form the startup and command-routing spine.
  2. HeadlessRunner/HeadlessControlLoop and InteractiveSessionLoop/InteractiveResumePicker are the two main execution spines: headless/SDK and interactive TUI.
  3. McpCoordinator, McpCommandRegistrar, and PluginCommandRegistrar show that MCP and plugins are first-class integration systems, not afterthoughts.
  4. Tool-name constants and permission flags show a guarded action runtime around file, shell, notebook, web, todo, skill, and task capabilities.
  5. SessionDiscovery, SessionRestore, JSONL transcript roots, remote tokens, bridge code, and teleport helpers show that durable sessions and remote handoff are core runtime modules.
  6. Debug/telemetry/update constants and embedded image/audio N-API modules round out the operational and media-support layer.

Use this document as the map; use the linked implementation pages for source anchors and edge cases.

Created and maintained by Yingting Huang.