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 modes, shapes model context, exposes tools, persists sessions, supports remote control, runs agents, 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 Hosted agent ops] 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 Hosted agent ops" 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, 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 tools, permissions, MCP, plugins, hooks, settings policy, IDE/Chrome/file integrations. |
| Sessions, persistence, and remote | Local JSONL transcripts, resume/continue/fork/rewind, remote sessions, teleport, and Remote Control. |
| Hosted agent ops | Debug logs, telemetry/traffic policy, doctor/update, hosted review signals, and native image/audio modules. |
| Agents and automation | Custom/background agents, task/subagent tools, lifecycle hooks, slash commands, and auto-mode. |
| Research atlas | Artifact maps, bytecode caveats, decoded chunk audits, and promotion rules for future source reads. |
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 |
| 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 |
| Hook names, lifecycle events, and stream/control frames | Hooks and events reference |
| 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 |
| Resume/continue/fork state restoration | Session resume and transcripts |
| Session API, event, storage, and remote-control reference | Session API, events, and storage |
| Session data models, transcript records, and frame schemas | Data models and frame schemas |
| 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 |
| Task/subagent runtime behavior | Agents, tasks, and subagents |
| Agent task scheduling, completion, and cron | Agent runtime, scheduling, and completion |
| Voice capture, transcription stream, and prompt injection | Audio capture and voice mode |
Source policy
- Treat
claude-code-pkg/src/entrypoints/cli.jsas the primary readable artifact for reverse-engineering claims. - 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.