Skip to content

Claude Code reverse-engineering wiki

This wiki reverse-engineers @anthropic-ai/claude-code to explain how Claude Code works, with source-anchored implementation notes. The primary readable artifact for this analysis is:

claude-code-pkg/src/entrypoints/cli.js

The wiki is organized around reverse-engineered internals questions: how the Bun standalone runtime starts, routes command-line and accessibility/recovery/termination modes, shapes model context, exposes local and hosted tools, controls approved macOS applications, persists sessions and Project/onboarding knowledge, supports remote control, runs subagents and observers, and exposes operational/debug/native surfaces.

Because cli.renamed.js is a renamed view of a bundled/minified artifact, symbol names are unstable across builds. Source anchors are intended for searching the analyzed bundle, not as public API names. Implementation pages use Semantic alias as the first source-anchor table column, followed by the anchor string or symbol grep target and a one-line meaning.

Semantic alias and minified anchor mapping

This home page is a navigation index, not a direct cli.renamed.js implementation analysis. Concrete topic pages map stable semantic aliases to version-specific minified anchors.

Semantic aliasMinified anchorScope
Wiki homeN/A — navigation pageOrients readers to the canonical sections and reading paths.
Section indexesN/A — see linked section README pagesCurated reader routes through source-anchored implementation pages.
Topic implementation pagesSee page-level source anchor tablesBundle-specific anchors live in focused implementation documents.

Internals wiki map

flowchart TD
Home[Wiki home] --> Start[00 Start here]
Home --> Runtime[01 Runtime lifecycle]
Home --> Loop[02 Context and model loop]
Home --> Tools[03 Tools, integrations, and security]
Home --> Sessions[04 Sessions, persistence, and remote]
Home --> Hosted[05 Operations and native support]
Home --> Agents[06 Agents and automation]
Home --> Atlas[99 Research atlas]
Start --> Runtime
Runtime --> Loop
Loop --> Tools
Runtime --> Sessions
Sessions --> Hosted
Loop --> Agents
Atlas --> Start
click Home "./" "Open wiki home"
click Start "./00-start-here/" "Open Start here"
click Runtime "./01-runtime-lifecycle/" "Open Runtime lifecycle"
click Loop "./02-context-model-loop/" "Open Context and model loop"
click Tools "./03-tools-integrations-security/" "Open Tools, integrations, and security"
click Sessions "./04-sessions-persistence-remote/" "Open Sessions, persistence, and remote"
click Hosted "./05-hosted-agent-ops/" "Open Operations and native support"
click Agents "./06-agents-automation/" "Open Agents and automation"
click Atlas "./99-research-atlas/" "Open Research atlas"

Canonical sections

SectionPurpose
Start hereMinimal orientation: what the bundle is, how to read anchors, and the first path through the runtime.
Runtime lifecyclePackage/Bun bootstrap, CLI flags, root command routing, headless/interactive modes, terminal renderer/input, accessibility, model-ended conversation termination, and subcommands.
Context and model loopPrompt/context sources, memory/settings, model/provider/auth selection, and headless stream-JSON turns.
Tools, integrations, and securityBuilt-in and hosted tools, permissions, MCP, plugin lifecycle/configuration, Chrome automation, IDE/LSP, hooks, status-line commands, computer-use MCP, settings policy, Artifact, and Claude Design.
Sessions, persistence, and remoteLocal JSONL transcripts, resume/continue/fork/rewind, attached Project knowledge, team onboarding/share flows, hosted sessions, teleport, Remote Control, and remote-runner egress/file staging.
Operations and native supportDebug logs, telemetry/traffic policy, enterprise gateway, doctor/update, safe-mode recovery, hosted review signals, and native image/audio modules.
Agents and automationCustom/background/observer agents, worktree isolation, cross-agent messaging, experimental Agent Teams, task/subagent tools, lifecycle hooks, slash commands, and auto-mode.
Research atlasGenerated module/string inventories, source-anchor methodology, domain ledgers, full-system coverage review, documentation-structure decisions, and promotion rules.
GoalRead this path
Get oriented quicklyStart hereGlossary and aliasesMain feature mapSystem architectureCLI main paths
Answer protocol and boundary questionsSystem architectureRuntime communication protocolsRemote control and teleport
Understand one complete local runCLI main pathsTerminal UI renderer and input lifecyclePrompt, context, and memoryPrompt assembly scenarios
Understand context budgets and model billingContext, memory, compaction, checkpoints, and rewindModel selection, calls, usage, quota, and billingHeadless streaming and resilience
Understand scriptable/headless modeCommand-line referenceHeadless streaming and resilienceContext and model loop architecture
Understand accessibility and recovery modesAccessibility and screen-reader modeSafe mode and recoverySettings, policy, and integrations
Use canonical reference tablesCommand-line referenceTool inventory and schemasHooks and events referenceSettings schema referenceEnvironment variables reference
Understand durable sessions and remote controlSessions, persistence, and remoteSession resume and transcriptsConversation terminationRemote control and teleportSession API, events, and storage
Understand hosted-runner networking and filesRemote control and teleportRemote-environment egress and file stagingSandbox and isolation
Operate the enterprise gatewayEnterprise gateway serverModels, providers, and authSettings, policy, and integrationsTelemetry and tracing
Review trust boundariesTools, integrations, and securityTool runtime, events, and integration flowsBuilt-in tools and permissionsSandbox and isolationMCP, plugins, and hooksPlugin lifecycle and configurationBrowser automation and Claude in Chrome
Understand hosted knowledge and creationHosted Projects and knowledgeTeam onboarding and share flowsArtifact publishing and live pagesClaude Design and design-system sync
Understand voice/audio dictationOperations and native supportMedia native modulesAudio capture and voice mode
Study agents and automationAgents and automationAgents, tasks, and subagentsWorktree isolation and handoffsAgent messaging and communicationAgent TeamsObserver agentsAgent steering, interruption, and completionDynamic workflows

Cross-cutting implementation matrix

ConcernPrimary internals sectionSupporting sections
Runtime mode selectionRuntime lifecycleCommand-line reference, Accessibility and screen-reader mode, Safe mode and recovery
Terminal rendering and inputTerminal UI renderer and input lifecycleAccessibility and screen-reader mode, Command-line reference
Communication protocolsRuntime communication protocolsAgent messaging and communication, MCP, plugins, and hooks, Remote control and teleport
Context engineeringContext and model loopContext, memory, compaction, checkpoints, and rewind, Agents and automation, Tools, integrations, and security
Model usage, quota, and billingModel selection, calls, usage, quota, and billingModels, providers, and auth, Headless streaming and resilience
Tool executionTool inventory and schemasBuilt-in tools and permissions, Artifact publishing and live pages, Claude Design and design-system sync
Native application controlComputer-use MCPMCP, plugins, and hooks, Built-in tools and permissions
Browser automationBrowser automation and Claude in ChromeBuilt-in tools and permissions, MCP, plugins, and hooks, Computer-use MCP
IDE and language serversIDE integration and LSP diagnosticsPlugin lifecycle and configuration, Tool runtime, events, and integration flows
Plugin extension lifecyclePlugin lifecycle and configurationMCP, plugins, and hooks, Settings, policy, and integrations, Skills system
Session/event lifecycleSession API, events, and storageData models and frame schemas, Hooks and events reference, Operations and native support
Conversation terminationConversation terminationSession resume and transcripts, Tool inventory and schemas
Remote/hosted operationHosted Projects and knowledgeArtifact publishing and live pages, Claude Design and design-system sync, Remote control and teleport
Remote-runner egress and filesRemote-environment egress and file stagingSandbox and isolation, MCP, plugins, and hooks
Enterprise inference gatewayEnterprise gateway serverModels, providers, and auth, Telemetry and tracing, Settings, policy, and integrations
Permissions and policyTools, integrations, and securityContext and model loop, Operations and native support
Settings, hooks, status line, and environment referencesSettings schema referenceHooks and events reference, Status line runtime and command protocol, Environment variables reference, Settings, policy, and integrations, Plugin lifecycle and configuration
Sandbox and isolationSandbox and isolationBuilt-in tools and permissions, Settings, policy, and integrations
Voice/audio dictationAudio capture and voice modeMedia native modules, Prompt, context, and memory
Subagents and automationAgents, tasks, and subagentsAgent steering, interruption, and completion, Tools, integrations, and security, Sessions, persistence, and remote
Worktree isolationWorktree isolation and handoffsAgents, tasks, and subagents, Session resume and transcripts, Hooks and events reference
Agent messaging and repliesAgent messaging and communicationRuntime communication protocols, Agent Teams, Agent steering, interruption, and completion
Experimental Agent TeamsAgent TeamsAgents, tasks, and subagents, Runtime communication protocols, Sandbox and isolation
Observer supervisionObserver agentsAgents, tasks, and subagents, Data models and frame schemas
Artifact/source triageResearch atlasBundle module map, generated data under 99-research-atlas/data/

Mechanism-level deep dives

MechanismStart here
Semantic aliases, minified anchors, and terminologyGlossary and aliases
System module boundaries and data/control flowSystem architecture
Runtime protocol families across modules, agents, bridges, and remote serversRuntime communication protocols
Command-line flags, subcommands, and aliasesCommand-line reference
Classic/fullscreen rendering, raw input, resize, suspend, and /tui relaunchTerminal UI renderer and input lifecycle
Terminal accessibility renderer selectionAccessibility and screen-reader mode
Model-ended conversation lifecycle and /clear recoveryConversation termination
Configuration-isolation recoverySafe mode and recovery
Per-module architecture deep divesRuntime lifecycle architecture, Context and model loop architecture, Tool runtime and security architecture, Session and remote-control architecture, Operations and native-support architecture, Agent and automation architecture
Headless stream/control event loopHeadless streaming and resilience
Prompt/template extraction catalogPrompt template catalog
Major prompt assembly scenariosPrompt assembly scenarios
Context compaction, memory selection, checkpoints, and rewindContext, memory, compaction, checkpoints, and rewind
Dynamic model selection, provider calls, usage, quota, and billingModel selection, calls, usage, quota, and billing
Tool runtime, events, shell execution, SDK/LSP/Web, context exclusion, settings, and persistenceTool runtime, events, and integration flows
Tool names, schema owners, and tool-family referenceTool inventory and schemas
Tool authorization and execution boundaryBuilt-in tools and permissions
Hosted page publication, versioning, and live updatesArtifact publishing and live pages
Collaborative design RPC and design-system synchronizationClaude Design and design-system sync
Hook names, lifecycle events, and stream/control framesHooks and events reference
Status-line JSON, refresh, local-command, and rendering lifecycleStatus line runtime and command protocol
Known settings roots, keys, and policy groupsSettings schema reference
Command sandbox design and platform isolationSandbox and isolation
MCP runtime connection and elicitationMCP, plugins, and hooks
Plugin manifests, dependencies, enablement, defaults, user options, and reloadPlugin lifecycle and configuration
Chrome extension/native-host bridge, browser tools, tab groups, and permissionsBrowser automation and Claude in Chrome
IDE discovery/dynamic MCP and plugin LSP diagnostic deliveryIDE integration and LSP diagnostics
macOS computer control, app tiers, and session lockComputer-use MCP
Resume/continue/fork state restorationSession resume and transcripts
Session API, event, storage, and remote-control referenceSession API, events, and storage
Session-bound shared Project knowledgeHosted Projects and knowledge
Local usage-derived onboarding guide and hosted share lifecycleTeam onboarding and share flows
Session data models, transcript records, and frame schemasData models and frame schemas
Remote-runner HTTPS proxy, working sync, filestore, and staged MCP lanesRemote-environment egress and file staging
Diagnostics and debug logsDiagnostics and debug logs
Telemetry and tracingTelemetry and tracing
Feature gatesFeature gates reference
Updater and doctorUpdater and doctor
Environment variable referenceEnvironment variables reference
Enterprise OIDC/inference/policy/spend/OTLP gatewayEnterprise gateway server
Task/subagent runtime behaviorAgents, tasks, and subagents
Session/agent worktree creation, locking, persistence, and safe cleanupWorktree isolation and handoffs
Agent message routing, transport, receive timing, replies, and completionAgent messaging and communication
Agent Teams spawn, storage, messaging, permissions, and cleanupAgent Teams
Observer pairing, digesting, resume, and reportsObserver agents
Agent steering, interruption, cancellation, and completionAgent steering, interruption, and completion
Timed prompt scheduling and cronCron and scheduled tasks
Deterministic multi-agent orchestrationDynamic workflows
Voice capture, transcription stream, and prompt injectionAudio capture and voice mode
Repository-wide coverage decisions and rejected false gapsFull-system documentation coverage review
Executable-string discoveries, promotions, aliases, noise, and native limitsDisassembled string-surface review
Canonical page ownership, filename decisions, duplicate merges, and intentional non-mergesDocumentation structure and duplication review

Source policy

  • Treat raw cli.js as artifact identity and cli.renamed.js as the primary behavioral reading surface; every semantic rename remains traceable to the same retained bundle.
  • Use approximate line numbers plus byte offsets because the file is bundled and many logical modules sit on very long lines.
  • Preserve exact strings, flags, environment variables, and symbols in source-anchor tables.
  • Do not treat .jsc bytecode dumps as recoverable JavaScript source.
  • Keep broad synthesis pages, implementation pages, and reference pages distinct; promote confirmed findings into the focused section page that owns the behavior.

Important caveat

These pages are reverse-engineering notes over a bundled/minified production artifact, not recovered clean source. Semantic names in prose and diagrams are explanatory aliases. Generated/minified symbols are retained only when useful as search anchors for the analyzed bundle.

Created and maintained by Yingting Huang.