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 alias | Minified anchor | Scope |
|---|---|---|
| Wiki home | N/A — navigation page | Orients readers to the canonical sections and reading paths. |
| Section indexes | N/A — see linked section README pages | Curated reader routes through source-anchored implementation pages. |
| Topic implementation pages | See page-level source anchor tables | Bundle-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
| Section | Purpose |
|---|---|
| Start here | Minimal orientation: what the bundle is, how to read anchors, and the first path through the runtime. |
| Runtime lifecycle | Package/Bun bootstrap, CLI flags, root command routing, headless/interactive modes, terminal renderer/input, accessibility, model-ended conversation termination, and subcommands. |
| Context and model loop | Prompt/context sources, memory/settings, model/provider/auth selection, and headless stream-JSON turns. |
| Tools, integrations, and security | Built-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 remote | Local 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 support | Debug logs, telemetry/traffic policy, enterprise gateway, doctor/update, safe-mode recovery, hosted review signals, and native image/audio modules. |
| Agents and automation | Custom/background/observer agents, worktree isolation, cross-agent messaging, experimental Agent Teams, task/subagent tools, lifecycle hooks, slash commands, and auto-mode. |
| Research atlas | Generated module/string inventories, source-anchor methodology, domain ledgers, full-system coverage review, documentation-structure decisions, and promotion rules. |
Recommended reading paths
Cross-cutting implementation matrix
Mechanism-level deep dives
| Mechanism | Start here |
|---|---|
| Semantic aliases, minified anchors, and terminology | Glossary and aliases |
| System module boundaries and data/control flow | System architecture |
| Runtime protocol families across modules, agents, bridges, and remote servers | Runtime communication protocols |
| Command-line flags, subcommands, and aliases | Command-line reference |
Classic/fullscreen rendering, raw input, resize, suspend, and /tui relaunch | Terminal UI renderer and input lifecycle |
| Terminal accessibility renderer selection | Accessibility and screen-reader mode |
Model-ended conversation lifecycle and /clear recovery | Conversation termination |
| Configuration-isolation recovery | Safe mode and recovery |
| Per-module architecture deep dives | Runtime 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 loop | Headless streaming and resilience |
| Prompt/template extraction catalog | Prompt template catalog |
| Major prompt assembly scenarios | Prompt assembly scenarios |
| Context compaction, memory selection, checkpoints, and rewind | Context, memory, compaction, checkpoints, and rewind |
| Dynamic model selection, provider calls, usage, quota, and billing | Model selection, calls, usage, quota, and billing |
| Tool runtime, events, shell execution, SDK/LSP/Web, context exclusion, settings, and persistence | Tool runtime, events, and integration flows |
| Tool names, schema owners, and tool-family reference | Tool inventory and schemas |
| Tool authorization and execution boundary | Built-in tools and permissions |
| Hosted page publication, versioning, and live updates | Artifact publishing and live pages |
| Collaborative design RPC and design-system synchronization | Claude Design and design-system sync |
| Hook names, lifecycle events, and stream/control frames | Hooks and events reference |
| Status-line JSON, refresh, local-command, and rendering lifecycle | Status line runtime and command protocol |
| Known settings roots, keys, and policy groups | Settings schema reference |
| Command sandbox design and platform isolation | Sandbox and isolation |
| MCP runtime connection and elicitation | MCP, plugins, and hooks |
| Plugin manifests, dependencies, enablement, defaults, user options, and reload | Plugin lifecycle and configuration |
| Chrome extension/native-host bridge, browser tools, tab groups, and permissions | Browser automation and Claude in Chrome |
| IDE discovery/dynamic MCP and plugin LSP diagnostic delivery | IDE integration and LSP diagnostics |
| macOS computer control, app tiers, and session lock | Computer-use MCP |
| Resume/continue/fork state restoration | Session resume and transcripts |
| Session API, event, storage, and remote-control reference | Session API, events, and storage |
| Session-bound shared Project knowledge | Hosted Projects and knowledge |
| Local usage-derived onboarding guide and hosted share lifecycle | Team onboarding and share flows |
| Session data models, transcript records, and frame schemas | Data models and frame schemas |
| Remote-runner HTTPS proxy, working sync, filestore, and staged MCP lanes | Remote-environment egress and file staging |
| Diagnostics and debug logs | Diagnostics and debug logs |
| Telemetry and tracing | Telemetry and tracing |
| Feature gates | Feature gates reference |
| Updater and doctor | Updater and doctor |
| Environment variable reference | Environment variables reference |
| Enterprise OIDC/inference/policy/spend/OTLP gateway | Enterprise gateway server |
| Task/subagent runtime behavior | Agents, tasks, and subagents |
| Session/agent worktree creation, locking, persistence, and safe cleanup | Worktree isolation and handoffs |
| Agent message routing, transport, receive timing, replies, and completion | Agent messaging and communication |
| Agent Teams spawn, storage, messaging, permissions, and cleanup | Agent Teams |
| Observer pairing, digesting, resume, and reports | Observer agents |
| Agent steering, interruption, cancellation, and completion | Agent steering, interruption, and completion |
| Timed prompt scheduling and cron | Cron and scheduled tasks |
| Deterministic multi-agent orchestration | Dynamic workflows |
| Voice capture, transcription stream, and prompt injection | Audio capture and voice mode |
| Repository-wide coverage decisions and rejected false gaps | Full-system documentation coverage review |
| Executable-string discoveries, promotions, aliases, noise, and native limits | Disassembled string-surface review |
| Canonical page ownership, filename decisions, duplicate merges, and intentional non-merges | Documentation structure and duplication review |
Source policy
- Treat raw
cli.jsas artifact identity andcli.renamed.jsas 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
.jscbytecode 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.