the claude code sourcemaps leaked march 31
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add documentation

+941 -2
+44
.github/workflows/pages.yml
··· 1 + name: Deploy documentation to GitHub Pages 2 + 3 + on: 4 + push: 5 + branches: 6 + - main 7 + paths: 8 + - "docs-site/**" 9 + - ".github/workflows/pages.yml" 10 + - "README.md" 11 + workflow_dispatch: 12 + 13 + permissions: 14 + contents: write 15 + 16 + concurrency: 17 + group: pages-deploy 18 + cancel-in-progress: true 19 + 20 + jobs: 21 + deploy: 22 + runs-on: ubuntu-latest 23 + steps: 24 + - uses: actions/checkout@v4 25 + 26 + - uses: actions/setup-python@v5 27 + with: 28 + python-version: "3.12" 29 + cache: pip 30 + cache-dependency-path: docs-site/requirements.txt 31 + 32 + - name: Install MkDocs Material 33 + run: pip install -r docs-site/requirements.txt 34 + 35 + - name: Build site 36 + run: mkdocs build -f docs-site/mkdocs.yml 37 + 38 + - name: Deploy to gh-pages branch 39 + uses: peaceiris/actions-gh-pages@v4 40 + with: 41 + github_token: ${{ secrets.GITHUB_TOKEN }} 42 + publish_dir: ./docs-site/site 43 + force_orphan: true 44 + enable_jekyll: false
+3 -1
.gitignore
··· 1 - .DS_Store 1 + .DS_Store 2 + docs-site/.venv/ 3 + docs-site/site/
+25 -1
README.md
··· 119 119 120 120 Execution paths converge on shared **state** (`state/`, `bootstrap/`), **permissions** (`utils/permissions/`), and **session storage** (`utils/sessionStorage.js`, hooks in `utils/sessionStart.js`). Non-interactive and SDK-style use share much of the same stack as the full-screen REPL, with different front-ends for I/O. 121 121 122 + ## Documentation (GitHub Pages) 123 + 124 + Full internals documentation (architecture, workflows, official-docs cross-reference, subsystem reference, appendices) is built with **MkDocs Material** from [`docs-site/`](docs-site/). 125 + 126 + - **Live site:** after you enable GitHub Pages on the `gh-pages` branch, the site is served at 127 + `https://<your-github-user>.github.io/claude-code-source-code/` 128 + (replace with your fork’s user/org and repo name). 129 + - **Local preview:** `cd docs-site && python3 -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt && mkdocs serve` 130 + - **Publish:** pushing to `main` runs [`.github/workflows/pages.yml`](.github/workflows/pages.yml) and deploys to `gh-pages`. 131 + 132 + Update `site_url` and `repo_url` in [`docs-site/mkdocs.yml`](docs-site/mkdocs.yml) after the first deploy so canonical URLs match your fork. 133 + 134 + **Contributing to docs:** edit Markdown under `docs-site/docs/`; keep the [official docs map](docs-site/docs/official-docs-map.md) in sync with [Anthropic’s docs index](https://code.claude.com/docs/llms.txt) when adding major features. 135 + 136 + ### Next steps (first-time publish) 137 + 138 + 1. **Commit and push** this repository to GitHub (`main` must contain `docs-site/` and `.github/workflows/pages.yml`). 139 + 2. **Allow the workflow to run** — GitHub Actions → _Deploy documentation to GitHub Pages_ → confirm it completes (or run **Run workflow** manually). 140 + 3. **Turn on Pages** — Repository **Settings → Pages** → **Build and deployment** → Source: **Deploy from a branch** → Branch **`gh-pages`** / folder **`/ (root)`**. (If you prefer the newer “GitHub Actions” source, switch the workflow to `actions/upload-pages-artifact` + `deploy-pages` instead of peaceiris.) 141 + 4. **Set `site_url`** in [`docs-site/mkdocs.yml`](docs-site/mkdocs.yml) to your live URL (e.g. `https://YOUR_USER.github.io/claude-code-source-code/`) and push again so sitemaps and search use the correct base. 142 + 5. **Fork-specific URLs** — Update `repo_url`, `edit_uri`, and the `extra.social` GitHub link in `mkdocs.yml` if this is not `marium/claude-code-source-code`. 143 + 122 144 ## Repository layout 123 145 124 146 - **`src/`** — Application source (thousands of modules) as recovered from the bundle map. 125 - - **`docs/`** — Human-readable layout reference ([directory-structure.md](docs/directory-structure.md)). 147 + - **`docs-site/`** — MkDocs source for the GitHub Pages documentation site. 148 + - **`docs/`** — Short pointer plus [`directory-structure.md`](docs/directory-structure.md) (`src/` layout reference). 149 + - **`scripts/`** — Optional helpers (e.g. `gen-appendices.sh`). 126 150 - There is **no `package.json` in this clone**; building would require the original toolchain (Bun, internal `bun:bundle` features, and private deps). Treat this tree as a **read-only architectural reference**.
+3
docs-site/.gitignore
··· 1 + .venv/ 2 + site/ 3 + docs/appendix/_generated-env-vars.txt
+78
docs-site/docs/appendix/directory-structure.md
··· 1 + # Directory structure (`src/`) 2 + 3 + This mirrors the **top levels** of the recovered `src/` tree. The repo also keeps `docs/directory-structure.md` at the repository root for browsing without MkDocs. 4 + 5 + ## Package root files 6 + 7 + | File | Notes | 8 + | --------------------------- | ----------------------------------------------------------------------------------------------- | 9 + | `main.tsx` | CLI entry: Commander setup, `preAction` trust/settings/telemetry, routing to REPL or print mode | 10 + | `commands.ts` | Command registry | 11 + | `tools.ts` | Tool registry (see also `tools/` directory) | 12 + | `Tool.ts` | Tool types / shared tool definitions | 13 + | `QueryEngine.ts` | Model / API query pipeline | 14 + | `context.ts` | System and user context | 15 + | `cost-tracker.ts` | Token / cost tracking | 16 + | `costHook.ts` | Cost hook wiring | 17 + | `dialogLaunchers.tsx` | Ink dialogs (resume, settings, teleport, etc.) | 18 + | `history.ts` | Input history | 19 + | `ink.ts` | Ink root / render helpers | 20 + | `interactiveHelpers.tsx` | Interactive UI helpers | 21 + | `projectOnboardingState.ts` | Onboarding state | 22 + | `query.ts` | Query helpers | 23 + | `replLauncher.tsx` | REPL launch | 24 + | `setup.ts` | Setup flows | 25 + | `tasks.ts` | Task utilities / constants | 26 + | `Task.ts` | Task types | 27 + 28 + ## Top-level directories 29 + 30 + | Directory | Role | 31 + | ---------------- | ----------------------------------------------------------------------- | 32 + | `assistant/` | Assistant / KAIROS paths (bundle feature-gated) | 33 + | `bootstrap/` | Early boot and global flags (cwd, remote mode, overrides) | 34 + | `bridge/` | IDE integration (VS Code, JetBrains, etc.) | 35 + | `buddy/` | Companion / buddy UI | 36 + | `cli/` | Non-interactive / print mode, transports, NDJSON, subcommand handlers | 37 + | `commands/` | Slash commands and related CLI command modules | 38 + | `components/` | Ink/React UI components | 39 + | `constants/` | Shared constants (OAuth, product URLs, etc.) | 40 + | `context/` | Context subsystems (stats, attachments, etc.) | 41 + | `coordinator/` | Multi-agent coordinator (feature-gated) | 42 + | `entrypoints/` | `init` and related startup entrypoints | 43 + | `hooks/` | React hooks for the terminal UI | 44 + | `ink/` | Ink layout, termio, events (terminal renderer layer) | 45 + | `keybindings/` | Keybinding definitions and providers | 46 + | `memdir/` | Memory directory / persistent memory | 47 + | `migrations/` | Settings and data migrations | 48 + | `moreright/` | Internal layout / UI helper | 49 + | `native-ts/` | Native TypeScript helpers | 50 + | `outputStyles/` | Output styling | 51 + | `plugins/` | Plugin loader and bundled plugins | 52 + | `query/` | Query pipeline modules | 53 + | `remote/` | Remote session / control | 54 + | `schemas/` | Zod (and related) schemas | 55 + | `screens/` | Full-screen flows (doctor, REPL shell, resume) | 56 + | `server/` | Server / socket modes | 57 + | `services/` | API client, MCP, compaction, LSP, analytics, OAuth, policy, etc. | 58 + | `skills/` | Skill loading and bundled skills | 59 + | `state/` | App state providers and reducers | 60 + | `tasks/` | Task implementations (local agent, shell, remote, dream, etc.) | 61 + | `tools/` | One subdirectory per agent-invokable tool | 62 + | `types/` | Shared TypeScript types (incl. generated) | 63 + | `upstreamproxy/` | Upstream proxy configuration | 64 + | `utils/` | Large catch-all: permissions, settings, swarm, shell, git, telemetry, … | 65 + | `vim/` | Vim-style editing in the terminal | 66 + | `voice/` | Voice input | 67 + 68 + ## `services/` (second level) 69 + 70 + Includes among others: `api/`, `mcp/`, `compact/`, `lsp/`, `oauth/`, `analytics/`, `policyLimits/`, `remoteManagedSettings/`, `plugins/`, `tools/` (service-side tool orchestration), `teamMemorySync/`, `settingsSync/`, `tips/`, `SessionMemory/`, `autoDream/`, `extractMemories/`, plus standalone `.ts` / `.tsx` files for limits, voice, notifier, etc. 71 + 72 + ## `tools/` (agent tools) 73 + 74 + Each major capability is typically its own folder; see [Tool packages](tool-packages.md) for a full directory list. 75 + 76 + ## `utils/` (highlights) 77 + 78 + Not exhaustive: `swarm/` (teammates, tmux/iTerm backends), `settings/` (incl. `mdm/`), `permissions/`, `shell/`, `telemetry/`, `teleport/`, `deepLink/`, `claudeInChrome/`, `computerUse/`, `messages/`, `sessionStorage.ts`, `sessionStart.ts`, `git.ts`, `config.ts`, `auth.ts`, and hundreds of focused modules.
+41
docs-site/docs/appendix/environment-variables.md
··· 1 + # Environment variables (code references) 2 + 3 + !!! warning "Unofficial and incomplete" 4 + This list is **not** a substitute for the official [Environment variables](https://code.claude.com/docs/en/env-vars) reference. It only shows names that appear in the recovered `src/` tree as `process.env.*` (or standard vars like `HOME`). Behavior and stability are defined by Anthropic’s product, not this mirror. 5 + 6 + ## User-facing and integration (examples found in source) 7 + 8 + | Variable | Where used (indicative) | 9 + | ---------------------------------- | ------------------------------------------------------------------------------------------- | 10 + | `ANTHROPIC_BASE_URL` | API client / proxy routing (`toolSearch.ts`, auth paths) | 11 + | `CLAUDE_CODE_GIT_BASH_PATH` | Windows Git Bash resolution (`windowsPaths.ts`) | 12 + | `CLAUDE_DEBUG` | Debug logging (`warningHandler.ts`) | 13 + | `CLAUDE_CODE_ENABLE_TELEMETRY` | OpenTelemetry enable (`telemetry/instrumentation.ts`) | 14 + | `CLAUDE_CODE_ENABLE_TASKS` | Tasks mode (`tasks.ts`) | 15 + | `CLAUDE_CODE_TASK_LIST_ID` | Default task list id (`tasks.ts`) | 16 + | `CLAUDE_CODE_PLAN_MODE_REQUIRED` | Plan mode gate (`teammate.ts`) | 17 + | `CLAUDE_CODE_WORKSPACE_HOST_PATHS` | Telemetry workspace mapping (`telemetry/events.ts`) | 18 + | `ENABLE_TOOL_SEARCH` | Tool search beta (`toolSearch.ts`) | 19 + | `GITHUB_ACTIONS` / `GITHUB_*` | CI metadata in analytics (`user.ts`) | 20 + | `HOME` | XDG / paths (`xdg.ts`) | 21 + | `MAX_THINKING_TOKENS` | Thinking toggle (`thinking.ts`) | 22 + | `NODE_ENV` | Dev/test branches | 23 + | `OTEL_*` | OpenTelemetry exporters and endpoints (`telemetry/instrumentation.ts`, `sessionTracing.ts`) | 24 + | `SHELL` | Shell spawning (`terminalPanel.ts`, `windowsPaths.ts`) | 25 + | `TMUX` / `TMUX_PANE` | Worktree / swarm backends (`worktree.ts`, `swarm/backends/detection.ts`) | 26 + | `TMPDIR` | Temp paths (`tmuxSocket.ts`) | 27 + | `USER_TYPE` | Internal Anthropic gating (`undercover.ts`, many modules) | 28 + 29 + ## Internal / experimental (often `USER_TYPE === 'ant'`) 30 + 31 + Variables such as `CLAUDE_CODE_UNDERCOVER`, `ANT_OTEL_*`, `ANT_CLAUDE_CODE_METRICS_ENDPOINT`, `BETA_TRACING_ENDPOINT`, `CCR_FORCE_BUNDLE`, `CCR_ENABLE_BUNDLE`, and similar appear for **employee or beta** builds. Treat them as undocumented implementation details. 32 + 33 + ## Regenerate a full grep index 34 + 35 + From the repo root: 36 + 37 + ```bash 38 + rg -o 'process\.env\.[A-Za-z0-9_]+' src --glob '*.ts' --glob '*.tsx' | sort -u 39 + ``` 40 + 41 + The script `scripts/gen-appendices.sh` can write the output to `docs-site/docs/appendix/_generated-env-vars.txt` (gitignored) for local analysis.
+50
docs-site/docs/appendix/tool-packages.md
··· 1 + # Tool packages under `src/tools/` 2 + 3 + Each row is a package directory implementing or supporting an agent tool. Names align with the public [Tools reference](https://code.claude.com/docs/en/tools-reference) where applicable. 4 + 5 + | Package | Path | 6 + | ---------------------- | --------------------------------- | 7 + | `AgentTool` | `src/tools/AgentTool/` | 8 + | `AskUserQuestionTool` | `src/tools/AskUserQuestionTool/` | 9 + | `BashTool` | `src/tools/BashTool/` | 10 + | `BriefTool` | `src/tools/BriefTool/` | 11 + | `ConfigTool` | `src/tools/ConfigTool/` | 12 + | `EnterPlanModeTool` | `src/tools/EnterPlanModeTool/` | 13 + | `EnterWorktreeTool` | `src/tools/EnterWorktreeTool/` | 14 + | `ExitPlanModeTool` | `src/tools/ExitPlanModeTool/` | 15 + | `ExitWorktreeTool` | `src/tools/ExitWorktreeTool/` | 16 + | `FileEditTool` | `src/tools/FileEditTool/` | 17 + | `FileReadTool` | `src/tools/FileReadTool/` | 18 + | `FileWriteTool` | `src/tools/FileWriteTool/` | 19 + | `GlobTool` | `src/tools/GlobTool/` | 20 + | `GrepTool` | `src/tools/GrepTool/` | 21 + | `LSPTool` | `src/tools/LSPTool/` | 22 + | `ListMcpResourcesTool` | `src/tools/ListMcpResourcesTool/` | 23 + | `MCPTool` | `src/tools/MCPTool/` | 24 + | `McpAuthTool` | `src/tools/McpAuthTool/` | 25 + | `NotebookEditTool` | `src/tools/NotebookEditTool/` | 26 + | `PowerShellTool` | `src/tools/PowerShellTool/` | 27 + | `REPLTool` | `src/tools/REPLTool/` | 28 + | `ReadMcpResourceTool` | `src/tools/ReadMcpResourceTool/` | 29 + | `RemoteTriggerTool` | `src/tools/RemoteTriggerTool/` | 30 + | `ScheduleCronTool` | `src/tools/ScheduleCronTool/` | 31 + | `SendMessageTool` | `src/tools/SendMessageTool/` | 32 + | `SkillTool` | `src/tools/SkillTool/` | 33 + | `SleepTool` | `src/tools/SleepTool/` | 34 + | `SyntheticOutputTool` | `src/tools/SyntheticOutputTool/` | 35 + | `TaskCreateTool` | `src/tools/TaskCreateTool/` | 36 + | `TaskGetTool` | `src/tools/TaskGetTool/` | 37 + | `TaskListTool` | `src/tools/TaskListTool/` | 38 + | `TaskOutputTool` | `src/tools/TaskOutputTool/` | 39 + | `TaskStopTool` | `src/tools/TaskStopTool/` | 40 + | `TaskUpdateTool` | `src/tools/TaskUpdateTool/` | 41 + | `TeamCreateTool` | `src/tools/TeamCreateTool/` | 42 + | `TeamDeleteTool` | `src/tools/TeamDeleteTool/` | 43 + | `TodoWriteTool` | `src/tools/TodoWriteTool/` | 44 + | `ToolSearchTool` | `src/tools/ToolSearchTool/` | 45 + | `WebFetchTool` | `src/tools/WebFetchTool/` | 46 + | `WebSearchTool` | `src/tools/WebSearchTool/` | 47 + | `shared` | `src/tools/shared/` | 48 + | `testing` | `src/tools/testing/` | 49 + 50 + To regenerate this table, run `scripts/gen-appendices.sh` from the repository root.
+93
docs-site/docs/architecture.md
··· 1 + # Architecture 2 + 3 + !!! warning "Recovered source" 4 + Paths refer to `src/` in this repository. Line-level accuracy is best-effort from the source map reconstruction. 5 + 6 + ## High-level flow 7 + 8 + ```mermaid 9 + flowchart LR 10 + subgraph entry [Entry] 11 + mainTsx[main.tsx] 12 + end 13 + subgraph modes [Modes] 14 + repl[REPL.tsx] 15 + print[cli/print.ts] 16 + assistant[assistant KAIROS gate] 17 + end 18 + subgraph core [Core loop] 19 + queryLoop[query.ts queryLoop] 20 + qe[QueryEngine.ts] 21 + toolsReg[tools.ts getTools] 22 + end 23 + subgraph services [Services] 24 + api[services/api] 25 + mcp[services/mcp] 26 + compact[services/compact] 27 + end 28 + mainTsx --> repl 29 + mainTsx --> print 30 + mainTsx -.-> assistant 31 + repl --> queryLoop 32 + print --> qe 33 + queryLoop --> api 34 + qe --> api 35 + toolsReg --> mcp 36 + queryLoop --> compact 37 + qe --> compact 38 + ``` 39 + 40 + ## Entry and startup 41 + 42 + `src/main.tsx` is the **Commander**-based CLI. Before the command handler runs, module evaluation triggers: 43 + 44 + - Startup profiling checkpoints (`utils/startupProfiler.ts`) 45 + - MDM raw reads in parallel (`utils/settings/mdm/rawRead.ts`) 46 + - macOS keychain prefetch (`utils/secureStorage/keychainPrefetch.ts`) 47 + 48 + The `preAction` hook loads trust, settings, telemetry gates, MCP prefetch, policy limits, and related startup work before interactive or print mode begins. 49 + 50 + ## Interactive mode 51 + 52 + - `replLauncher.tsx` mounts the Ink/React app. 53 + - `screens/REPL.tsx` owns the main session UI, input queue, model turns, tool execution UI, teammate hooks, voice (when compiled in), and scheduled-task integration. 54 + - `utils/queueProcessor.ts` drains slash commands, bash-mode lines, and batched prompts into `executeInput`. 55 + 56 + ## Headless / print / SDK-style I/O 57 + 58 + - `cli/print.ts` implements structured stdin/stdout loops (`runHeadlessStreaming`, NDJSON-style control). 59 + - `QueryEngine.ts` supports non-REPL paths where messages are submitted programmatically and tool permission context is updated without full UI. 60 + 61 + ## Tools and MCP 62 + 63 + - `tools.ts` aggregates built-in tools (filtered by permission context) and merges MCP-derived tools. 64 + - `services/mcp/` implements config parsing, transports, OAuth, channel permissions, and the in-process MCP client used by `MCPConnectionManager` in the UI. 65 + 66 + ## Compaction and memory 67 + 68 + - `services/compact/` implements context window management aligned with user-facing [context window](https://code.claude.com/docs/en/context-window) and [costs](https://code.claude.com/docs/en/costs) documentation. 69 + 70 + ## Multi-agent (swarm / teammates) 71 + 72 + - `utils/swarm/` contains backends (tmux, iTerm, in-process), spawn utilities, permission sync, and `inProcessRunner.ts` teammate loop. 73 + 74 + ## IDE integration 75 + 76 + - `bridge/` plus hooks such as `hooks/useDiffInIDE.ts` connect to VS Code / JetBrains surfaces described in official [VS Code](https://code.claude.com/docs/en/vs-code) and [JetBrains](https://code.claude.com/docs/en/jetbrains) docs. 77 + 78 + ## Key files (quick index) 79 + 80 + | Path | Role | 81 + | -------------------------------------------------- | ------------------------------------------- | 82 + | `main.tsx` | CLI entry, global options, `preAction` | 83 + | `screens/REPL.tsx` | Interactive session core | 84 + | `query.ts` | Streaming query loop, tool round-trips | 85 + | `QueryEngine.ts` | Headless query submission | 86 + | `cli/print.ts` | Print / stream-json / SDK control transport | 87 + | `tools.ts` / `Tool.ts` | Tool registry and types | 88 + | `services/api/client.ts`, `services/api/claude.ts` | HTTP / streaming API | 89 + | `utils/permissions/` | Permission modes and prompts | 90 + | `services/compact/` | Compaction pipeline | 91 + | `utils/sessionStart.ts` | Session / setup hooks | 92 + 93 + See also [Workflows](workflows.md) and the [official docs map](official-docs-map.md).
+30
docs-site/docs/index.md
··· 1 + # Claude Code — recovered source internals 2 + 3 + !!! warning "Proprietary software / leaked reconstruction" 4 + This repository contains **reconstructed TypeScript source** from a published npm bundle source map (March 2026). The software is **Anthropic’s proprietary product**. These docs are for **education and architecture study** only. Building or redistributing a competing product may violate law or Anthropic’s terms. This site is **not** official documentation and **not** Anthropic support. 5 + 6 + This documentation maps the **`src/`** tree of the Claude Code CLI to **how the product behaves**, with cross-links to **[official Claude Code documentation](https://code.claude.com/docs/en/overview)**. 7 + 8 + ## What Claude Code is (official product) 9 + 10 + From the [product overview](https://code.claude.com/docs/en/overview): 11 + 12 + > Claude Code is an agentic coding tool that reads your codebase, edits files, runs commands, and integrates with your development tools. Available in your terminal, IDE, desktop app, and browser. 13 + 14 + The recovered codebase implements primarily the **terminal CLI** surface, plus shared logic for tools, MCP, permissions, compaction, IDE bridge hooks, and related services. 15 + 16 + ## How to use this site 17 + 18 + | Section | Purpose | 19 + | ------------------------------------------- | -------------------------------------------------------------------------------------- | 20 + | [Installation](installation.md) | Build **this documentation** locally; install the **real** Claude Code from Anthropic. | 21 + | [Reproducibility](reproducibility.md) | Why you **cannot** rebuild the shipping npm package from this tree alone. | 22 + | [Architecture](architecture.md) | High-level components and data flow. | 23 + | [Workflows](workflows.md) | Interactive REPL, print/headless, swarm, compaction paths. | 24 + | [Official docs map](official-docs-map.md) | Every indexed doc page ↔ `src/` entry points. | 25 + | [Reference](reference/cli-entry.md) | Deeper dives per subsystem. | 26 + | [Appendix](appendix/directory-structure.md) | Directory layout, tool packages, environment variables. | 27 + 28 + ## Repository 29 + 30 + Source code lives under `src/` in the GitHub repository. The published MkDocs site is built from `docs-site/` via GitHub Actions. After enabling Pages on the `gh-pages` branch, the URL is typically `https://<user>.github.io/<repo>/` (see the root `README.md`).
+36
docs-site/docs/installation.md
··· 1 + # Installation 2 + 3 + !!! warning "Two different things" 4 + **A)** Building this **documentation site** (MkDocs) — instructions below. 5 + **B)** Installing **Claude Code** the product — use Anthropic’s official installers only. 6 + 7 + ## Install Claude Code (official product) 8 + 9 + Follow the [Claude Code overview](https://code.claude.com/docs/en/overview): native install script, Homebrew, WinGet, VS Code extension, JetBrains plugin, desktop app, or web. This recovered repository **does not** ship a supported way to compile or install the product from source. 10 + 11 + ## Build this documentation site (local) 12 + 13 + Requires Python 3.10+. 14 + 15 + ```bash 16 + cd docs-site 17 + python3 -m venv .venv 18 + source .venv/bin/activate # Windows: .venv\Scripts\activate 19 + pip install -r requirements.txt 20 + mkdocs serve 21 + ``` 22 + 23 + Open `http://127.0.0.1:8000` to preview. 24 + 25 + ## Publish (GitHub Pages) 26 + 27 + On push to `main`, the workflow `.github/workflows/pages.yml` builds the site and pushes to the `gh-pages` branch (also runs when `README.md` or the workflow file changes). 28 + 29 + 1. In the GitHub repo: **Settings → Pages → Build and deployment → Branch `gh-pages` / `/ (root)`**. 30 + 2. After the first deploy, set `site_url` in `docs-site/mkdocs.yml` to your real Pages URL (e.g. `https://<user>.github.io/<repo>/`) so canonical links and search work correctly. Also update `repo_url` if your fork uses a different owner or name. 31 + 32 + The deploy step sets **`enable_jekyll: false`** so GitHub Pages serves static files correctly (adds `.nojekyll`). 33 + 34 + ## Advanced setup (official) 35 + 36 + For system requirements, updates, and uninstallation of the **product**, see [Advanced setup](https://code.claude.com/docs/en/setup) in the official docs.
+154
docs-site/docs/official-docs-map.md
··· 1 + # Official Claude Code docs ↔ `src/` map 2 + 3 + This table links each page listed in the [official docs index (`llms.txt`)](https://code.claude.com/docs/llms.txt) to **primary** paths under `src/`. Many features span multiple folders; only entry points and main implementations are shown. Rows marked _user guide_ have no single code anchor. 4 + 5 + !!! tip "Canonical user documentation" 6 + For behavior, flags, and configuration, always prefer **[code.claude.com/docs](https://code.claude.com/docs/en/overview)**. This map is for **code navigation** in the recovered tree. 7 + 8 + ## Product, platforms, and onboarding 9 + 10 + | Official doc | Primary `src/` paths | Notes | 11 + | ------------------------------------------------------------------------------- | ------------------------------------------- | ------------------------------------------- | 12 + | [Overview](https://code.claude.com/docs/en/overview.md) | `main.tsx`, `screens/REPL.tsx` | Product surfaces; CLI is one implementation | 13 + | [Quickstart](https://code.claude.com/docs/en/quickstart.md) | _user guide_ | | 14 + | [Platforms and integrations](https://code.claude.com/docs/en/platforms.md) | `bridge/`, `cli/`, `remote/` | | 15 + | [Common workflows](https://code.claude.com/docs/en/common-workflows.md) | _user guide_ | | 16 + | [Best practices](https://code.claude.com/docs/en/best-practices.md) | _user guide_ | | 17 + | [Changelog](https://code.claude.com/docs/en/changelog.md) | _release notes_ | | 18 + | [Troubleshooting](https://code.claude.com/docs/en/troubleshooting.md) | _user guide_ | | 19 + | [Legal and compliance](https://code.claude.com/docs/en/legal-and-compliance.md) | _policy_ | | 20 + | [Data usage](https://code.claude.com/docs/en/data-usage.md) | _policy_ | | 21 + | [Security](https://code.claude.com/docs/en/security.md) | `utils/permissions/`, `utils/shell/` | Safeguards; not exhaustive | 22 + | [Zero data retention](https://code.claude.com/docs/en/zero-data-retention.md) | `services/policyLimits/`, `utils/settings/` | Enterprise policy hooks | 23 + 24 + ## CLI, terminal, and interaction 25 + 26 + | Official doc | Primary `src/` paths | Notes | 27 + | ----------------------------------------------------------------------- | ------------------------------------------------- | --------------------------------------------------------------------------- | 28 + | [CLI reference](https://code.claude.com/docs/en/cli-reference.md) | `main.tsx`, `commands/` | Flags and subcommands | 29 + | [Interactive mode](https://code.claude.com/docs/en/interactive-mode.md) | `screens/REPL.tsx`, `keybindings/`, `components/` | Shortcuts, input modes (`hooks/` here is React hooks, not user shell hooks) | 30 + | [Terminal config](https://code.claude.com/docs/en/terminal-config.md) | `utils/terminal.ts`, `ink/` | | 31 + | [Keybindings](https://code.claude.com/docs/en/keybindings.md) | `keybindings/` | | 32 + | [Status line](https://code.claude.com/docs/en/statusline.md) | `utils/status.tsx`, `components/` | | 33 + | [Fullscreen rendering](https://code.claude.com/docs/en/fullscreen.md) | `ink/`, `components/` | | 34 + | [Voice dictation](https://code.claude.com/docs/en/voice-dictation.md) | `voice/`, `screens/REPL.tsx` | Gated by `VOICE_MODE` in bundle | 35 + | [Built-in commands](https://code.claude.com/docs/en/commands.md) | `commands/` | Slash commands | 36 + | [Output styles](https://code.claude.com/docs/en/output-styles.md) | `outputStyles/` | | 37 + 38 + ## Agent loop, tools, and context 39 + 40 + | Official doc | Primary `src/` paths | Notes | 41 + | --------------------------------------------------------------------------------- | ---------------------------------------------------------- | ------------------------- | 42 + | [How Claude Code works](https://code.claude.com/docs/en/how-claude-code-works.md) | `query.ts`, `tools.ts`, `services/tools/` | Agentic loop | 43 + | [Headless / programmatic](https://code.claude.com/docs/en/headless.md) | `cli/print.ts`, `QueryEngine.ts` | Stream-json / SDK control | 44 + | [Tools reference](https://code.claude.com/docs/en/tools-reference.md) | `tools/*`, `Tool.ts`, `services/lsp/` | Includes LSP tool | 45 + | [Context window](https://code.claude.com/docs/en/context-window.md) | `services/compact/`, `utils/tokenBudget.ts` | | 46 + | [Checkpointing](https://code.claude.com/docs/en/checkpointing.md) | `utils/sessionStorage.ts`, `utils/conversationRecovery.ts` | | 47 + | [Costs](https://code.claude.com/docs/en/costs.md) | `cost-tracker.ts`, `services/api/usage.ts` | Token usage and limits | 48 + | [Sandboxing](https://code.claude.com/docs/en/sandboxing.md) | `utils/shell/`, `tools/BashTool/` | Bash isolation | 49 + | [Computer use](https://code.claude.com/docs/en/computer-use.md) | `utils/computerUse/` | CLI computer-use MCP | 50 + | [Fast mode](https://code.claude.com/docs/en/fast-mode.md) | `utils/fastMode.ts` | | 51 + 52 + ## MCP, channels, and extensions 53 + 54 + | Official doc | Primary `src/` paths | Notes | 55 + | ----------------------------------------------------------------------------- | ---------------------------------------------- | ----------------------------- | 56 + | [MCP](https://code.claude.com/docs/en/mcp.md) | `services/mcp/`, `tools/MCPTool/` | | 57 + | [Channels](https://code.claude.com/docs/en/channels.md) | `services/mcp/channel*.ts` | Inbound push | 58 + | [Channels reference](https://code.claude.com/docs/en/channels-reference.md) | `services/mcp/` | Contract / capabilities | 59 + | [Hooks guide](https://code.claude.com/docs/en/hooks-guide.md) | `utils/sessionStart.ts`, hook runners | | 60 + | [Hooks reference](https://code.claude.com/docs/en/hooks.md) | `utils/sessionStart.ts`, `schemas/` | JSON schemas | 61 + | [Plugins](https://code.claude.com/docs/en/plugins.md) | `plugins/`, `utils/plugins/` | | 62 + | [Plugins reference](https://code.claude.com/docs/en/plugins-reference.md) | `plugins/`, `services/plugins/` | | 63 + | [Discover plugins](https://code.claude.com/docs/en/discover-plugins.md) | `services/plugins/pluginCliCommands.ts` | | 64 + | [Plugin marketplaces](https://code.claude.com/docs/en/plugin-marketplaces.md) | `utils/plugins/` | | 65 + | [Skills](https://code.claude.com/docs/en/skills.md) | `skills/`, `utils/skills/`, `tools/SkillTool/` | | 66 + | [Features overview](https://code.claude.com/docs/en/features-overview.md) | _cross-cutting_ | CLAUDE.md, skills, MCP, hooks | 67 + 68 + ## Memory, project config, and `.claude` 69 + 70 + | Official doc | Primary `src/` paths | Notes | 71 + | -------------------------------------------------------------------------------- | -------------------------------- | --------------------- | 72 + | [Memory / CLAUDE.md](https://code.claude.com/docs/en/memory.md) | `utils/claudemd.ts`, `memdir/` | | 73 + | [Explore .claude directory](https://code.claude.com/docs/en/claude-directory.md) | `utils/settings/`, `migrations/` | Settings, hooks paths | 74 + 75 + ## Permissions and models 76 + 77 + | Official doc | Primary `src/` paths | Notes | 78 + | ----------------------------------------------------------------------- | -------------------------------------- | -------------------- | 79 + | [Permissions](https://code.claude.com/docs/en/permissions.md) | `utils/permissions/` | | 80 + | [Permission modes](https://code.claude.com/docs/en/permission-modes.md) | `utils/permissions/permissionSetup.ts` | Auto / plan / etc. | 81 + | [Model configuration](https://code.claude.com/docs/en/model-config.md) | `utils/model/` | Aliases, deprecation | 82 + 83 + ## Multi-agent and scheduling 84 + 85 + | Official doc | Primary `src/` paths | Notes | 86 + | ----------------------------------------------------------------------------- | ------------------------------------ | ------------------------------- | 87 + | [Agent teams](https://code.claude.com/docs/en/agent-teams.md) | `utils/swarm/`, `screens/REPL.tsx` | | 88 + | [Subagents](https://code.claude.com/docs/en/sub-agents.md) | `tools/AgentTool/` | | 89 + | [Scheduled tasks](https://code.claude.com/docs/en/scheduled-tasks.md) | `utils/cron*.ts`, `screens/REPL.tsx` | `/loop`, cron tools | 90 + | [Web scheduled tasks](https://code.claude.com/docs/en/web-scheduled-tasks.md) | `services/api/`, `remote/` | Cloud scheduling (client hooks) | 91 + 92 + ## IDEs, Chrome, remote, desktop 93 + 94 + | Official doc | Primary `src/` paths | Notes | 95 + | ----------------------------------------------------------------------------------- | -------------------------------------------------------------- | ----------------------- | 96 + | [VS Code](https://code.claude.com/docs/en/vs-code.md) | `bridge/`, `hooks/useDiffInIDE.ts` | | 97 + | [JetBrains](https://code.claude.com/docs/en/jetbrains.md) | `bridge/` | | 98 + | [Chrome](https://code.claude.com/docs/en/chrome.md) | `utils/claudeInChrome/` | Extension / native host | 99 + | [Remote control](https://code.claude.com/docs/en/remote-control.md) | `remote/`, `utils/teleport/`, `services/api/sessionIngress.ts` | | 100 + | [Claude Code on the web](https://code.claude.com/docs/en/claude-code-on-the-web.md) | `services/api/`, `bootstrap/` | Cloud session client | 101 + | [Desktop](https://code.claude.com/docs/en/desktop.md) | `utils/deepLink/`, `dialogLaunchers.tsx` | Handoff / deep links | 102 + | [Desktop quickstart](https://code.claude.com/docs/en/desktop-quickstart.md) | _user guide_ | | 103 + 104 + ## Authentication and cloud providers 105 + 106 + | Official doc | Primary `src/` paths | Notes | 107 + | ------------------------------------------------------------------------------ | ----------------------------------------- | ----------------- | 108 + | [Authentication](https://code.claude.com/docs/en/authentication.md) | `utils/auth.ts`, `services/oauth/` | | 109 + | [Amazon Bedrock](https://code.claude.com/docs/en/amazon-bedrock.md) | `utils/aws.ts`, `utils/auth.ts` | | 110 + | [Google Vertex AI](https://code.claude.com/docs/en/google-vertex-ai.md) | `utils/auth.ts`, `services/api/` | | 111 + | [Microsoft Foundry](https://code.claude.com/docs/en/microsoft-foundry.md) | `services/api/`, `utils/auth.ts` | | 112 + | [LLM gateway](https://code.claude.com/docs/en/llm-gateway.md) | `upstreamproxy/`, `services/api/` | | 113 + | [Enterprise network config](https://code.claude.com/docs/en/network-config.md) | `utils/caCerts.ts`, `utils/managedEnv.ts` | Proxy / mTLS / CA | 114 + 115 + ## Settings, policy, and enterprise 116 + 117 + | Official doc | Primary `src/` paths | Notes | 118 + | ---------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- | ------- | 119 + | [Settings](https://code.claude.com/docs/en/settings.md) | `utils/settings/` | | 120 + | [Environment variables](https://code.claude.com/docs/en/env-vars.md) | _grep `process.env`_ — [appendix](appendix/environment-variables.md) | | 121 + | [Server-managed settings](https://code.claude.com/docs/en/server-managed-settings.md) | `services/remoteManagedSettings/` | | 122 + | [Third-party integrations / enterprise](https://code.claude.com/docs/en/third-party-integrations.md) | `bridge/`, `services/mcp/`, `utils/settings/mdm/` | | 123 + | [Development containers](https://code.claude.com/docs/en/devcontainer.md) | _user guide_ | | 124 + | [GitHub Enterprise Server](https://code.claude.com/docs/en/github-enterprise-server.md) | `utils/github/` | Partial | 125 + 126 + ## CI/CD, review, and chat integrations 127 + 128 + | Official doc | Primary `src/` paths | Notes | 129 + | ------------------------------------------------------------------- | ---------------------------------------------- | ---------------------- | 130 + | [GitHub Actions](https://code.claude.com/docs/en/github-actions.md) | _minimal in CLI_ | CI uses product binary | 131 + | [GitLab CI/CD](https://code.claude.com/docs/en/gitlab-ci-cd.md) | _minimal in CLI_ | | 132 + | [Code review](https://code.claude.com/docs/en/code-review.md) | _service-side / GitHub app_ | | 133 + | [Slack](https://code.claude.com/docs/en/slack.md) | `utils/suggestions/slackChannelSuggestions.ts` | Integrations | 134 + 135 + ## Analytics, monitoring, LSP 136 + 137 + | Official doc | Primary `src/` paths | Notes | 138 + | --------------------------------------------------------------------------------- | ----------------------------------------- | ----- | 139 + | [Analytics](https://code.claude.com/docs/en/analytics.md) | `services/analytics/` | | 140 + | [Monitoring / OpenTelemetry](https://code.claude.com/docs/en/monitoring-usage.md) | `utils/telemetry/`, `services/analytics/` | | 141 + 142 + ## Advanced setup 143 + 144 + | Official doc | Primary `src/` paths | Notes | 145 + | ------------------------------------------------------------------------------------ | -------------------- | -------------------------------------------------- | 146 + | [Advanced setup](https://code.claude.com/docs/en/setup.md) | _user guide_ | Install / uninstall product | 147 + | [Vim mode](https://code.claude.com/docs/en/interactive-mode.md) | `vim/` | See interactive mode; vim implementation in `vim/` | 148 + | [Coordinator / internal multi-agent](https://code.claude.com/docs/en/agent-teams.md) | `coordinator/` | Bundle feature `COORDINATOR_MODE` | 149 + | [Assistant mode / Agent SDK daemon](https://code.claude.com/docs/en/headless.md) | `assistant/` | Bundle feature `KAIROS` | 150 + 151 + </think> 152 + 153 + <|tool▁calls▁begin|><|tool▁call▁begin|> 154 + Read
+9
docs-site/docs/reference/api-client.md
··· 1 + # API client and OAuth 2 + 3 + **Primary paths:** `src/services/api/`, `src/services/oauth/`, `src/utils/api.ts`, `src/utils/auth.ts` 4 + 5 + `services/api/client.ts` and `claude.ts` implement HTTP and streaming calls to Anthropic APIs (including retries, errors, session ingress, files API, usage, bootstrap). Provider-specific paths (Bedrock, Vertex, Foundry) are gated through auth and endpoint configuration in `utils/aws.ts`, `utils/auth.ts`, and related modules. 6 + 7 + `services/oauth/` implements the browser-based OAuth flow (auth code listener, token exchange, crypto). 8 + 9 + **See also:** [Authentication](https://code.claude.com/docs/en/authentication), [Amazon Bedrock](https://code.claude.com/docs/en/amazon-bedrock), [Google Vertex AI](https://code.claude.com/docs/en/google-vertex-ai).
+11
docs-site/docs/reference/cli-entry.md
··· 1 + # CLI entry and parsing 2 + 3 + **Primary paths:** `src/main.tsx`, `src/cli/*`, `src/commands.ts` 4 + 5 + `main.tsx` registers the `claude` Commander program: global options (model, permissions, worktree, teammate flags, MCP, teleport, etc.), subcommands (MCP, plugins, agents, auth utilities), and a `preAction` hook that runs trust checks, settings load, telemetry initialization, prefetch (MCP URLs, referral, fast mode), and policy gates before any handler executes. 6 + 7 + Side effects at **module top** intentionally run before other imports: startup profiler, MDM subprocess reads (`utils/settings/mdm/rawRead.ts`), and macOS keychain prefetch to overlap I/O with the rest of module evaluation. 8 + 9 + Feature-gated dynamic `require()` loads `coordinator/coordinatorMode.js` when `COORDINATOR_MODE` is true in the Bun bundle, and `assistant/` when `KAIROS` is true. 10 + 11 + **See also:** [CLI reference](https://code.claude.com/docs/en/cli-reference), [Architecture](../architecture.md).
+9
docs-site/docs/reference/compaction.md
··· 1 + # Compaction and session memory 2 + 3 + **Primary paths:** `src/services/compact/`, `src/services/SessionMemory/`, `src/utils/tokenBudget.ts` 4 + 5 + Compaction reduces transcript size when approaching context limits: `compact.ts`, `autoCompact.ts`, `microCompact.ts`, `sessionMemoryCompact.ts`, grouping, prompts, and post-compact cleanup. Time-based and API microcompact paths support different strategies. 6 + 7 + Session memory modules add long-lived summaries and structured memory aligned with product behavior described under [memory](https://code.claude.com/docs/en/memory) and [context window](https://code.claude.com/docs/en/context-window). 8 + 9 + **See also:** [Context window](https://code.claude.com/docs/en/context-window), [Costs](https://code.claude.com/docs/en/costs), [Checkpointing](https://code.claude.com/docs/en/checkpointing).
+9
docs-site/docs/reference/lsp.md
··· 1 + # LSP integration 2 + 3 + **Primary paths:** `src/services/lsp/`, `src/tools/LSPTool/` 4 + 5 + `LSPServerManager.ts`, `LSPClient.ts`, and related modules manage language server processes and diagnostics. The agent invokes LSP capabilities through `LSPTool`, which bridges model tool calls to LSP requests. 6 + 7 + Passive feedback and config live alongside the manager (`passiveFeedback.ts`, `config.ts`). 8 + 9 + **See also:** [Tools reference](https://code.claude.com/docs/en/tools-reference) (LSP tool), [Architecture](../architecture.md).
+11
docs-site/docs/reference/mcp.md
··· 1 + # MCP (Model Context Protocol) 2 + 3 + **Primary paths:** `src/services/mcp/`, `src/tools/MCPTool/`, `src/tools/McpAuthTool/`, `src/services/mcp/MCPConnectionManager.tsx` 4 + 5 + The MCP subsystem parses config (files, env expansion, enterprise allowlists), establishes **stdio** and **in-process** transports, handles OAuth for MCP servers, normalizes server metadata, and exposes tools and resources to the model. 6 + 7 + Channel-related files (`channelAllowlist`, `channelNotification`, `channelPermissions`) implement **push** notifications into a session, matching the [Channels](https://code.claude.com/docs/en/channels) documentation. 8 + 9 + The React `MCPConnectionManager` wraps interactive sessions so the REPL can connect/disconnect servers and reflect status in the UI. 10 + 11 + **See also:** [MCP](https://code.claude.com/docs/en/mcp), [Channels reference](https://code.claude.com/docs/en/channels-reference).
+9
docs-site/docs/reference/permissions.md
··· 1 + # Permissions and modes 2 + 3 + **Primary paths:** `src/utils/permissions/`, `src/utils/permissions/permissionSetup.ts`, `src/utils/permissions/PermissionMode.ts` 4 + 5 + Permission modes (manual, auto with classifiers, plan-only, etc.) are parsed from CLI flags and settings, then stored in `toolPermissionContext` on app state. Tool execution consults this context before running bash, file writes, MCP calls, etc. 6 + 7 + `permissionSetup.ts` and related modules implement gates for auto mode, dangerous permission stripping, and advisor integration. 8 + 9 + **See also:** [Permissions](https://code.claude.com/docs/en/permissions), [Permission modes](https://code.claude.com/docs/en/permission-modes), [Sandboxing](https://code.claude.com/docs/en/sandboxing).
+9
docs-site/docs/reference/plugins-skills.md
··· 1 + # Plugins and skills 2 + 3 + **Primary paths:** `src/plugins/`, `src/skills/`, `src/utils/plugins/`, `src/utils/skills/`, `src/tools/SkillTool/`, `src/services/plugins/` 4 + 5 + Bundled plugins ship under `plugins/bundled/`; `PluginInstallationManager` and CLI commands under `services/plugins/` support install/update scopes. Skills load from project and user directories; `skillChangeDetector` watches for changes. 6 + 7 + `SkillTool` exposes skill invocation to the model. Hooks and commands defined by plugins align with [Plugins](https://code.claude.com/docs/en/plugins) and [Skills](https://code.claude.com/docs/en/skills). 8 + 9 + **See also:** [Plugins reference](https://code.claude.com/docs/en/plugins-reference), [Discover plugins](https://code.claude.com/docs/en/discover-plugins).
+11
docs-site/docs/reference/print-sdk.md
··· 1 + # Print mode, stream-json, and SDK control 2 + 3 + **Primary paths:** `src/cli/print.ts`, `src/cli/structuredIO.ts`, `src/cli/transports/*`, `src/QueryEngine.ts` 4 + 5 + `print.ts` implements non-interactive execution: structured stdin lines, streaming stdout (including partial messages), tool permission prompts bridged over the protocol, and verbose/debug modes. 6 + 7 + `structuredIO.ts` parses and validates incoming events; transports (`WebSocketTransport`, `SSETransport`, `HybridTransport`, etc.) support remote SDK and CCR-style integrations. 8 + 9 + This corresponds to [Headless](https://code.claude.com/docs/en/headless) and Agent SDK usage documented on the Anthropic platform. 10 + 11 + **See also:** [Workflows](../workflows.md), [Query loop](query-engine.md).
+11
docs-site/docs/reference/query-engine.md
··· 1 + # Query loop and streaming 2 + 3 + **Primary paths:** `src/query.ts`, `src/QueryEngine.ts`, `src/utils/processUserInput/` 4 + 5 + `query.ts` defines `queryLoop`, the async generator that drives a single conversation turn: streams assistant content, handles tool calls, merges tool results back into context, and coordinates with compaction and permission checks. 6 + 7 + `QueryEngine.ts` exposes `submitMessage` for **non-interactive** flows: it prepares `processUserInputContext` with `isNonInteractiveSession: true`, runs skill/plugin caches, and streams SDK-style messages—used from headless and SDK control transports. 8 + 9 + Shared input processing (slash commands embedded in prompts, tool permission context updates) lives under `utils/processUserInput/` and related modules. 10 + 11 + **See also:** [How Claude Code works](https://code.claude.com/docs/en/how-claude-code-works), [Headless](https://code.claude.com/docs/en/headless).
+13
docs-site/docs/reference/remote-bridge.md
··· 1 + # Remote sessions, teleport, IDE bridge, Chrome 2 + 3 + **Primary paths:** `src/remote/`, `src/utils/teleport/`, `src/utils/deepLink/`, `src/bridge/`, `src/utils/claudeInChrome/`, `src/hooks/useDiffInIDE.ts` 4 + 5 + **Remote / teleport:** `teleport/` handles session bundles, environment selection, and API calls to resume or hand off sessions—aligned with [Remote control](https://code.claude.com/docs/en/remote-control) and web/desktop flows. 6 + 7 + **Deep links:** `deepLink/protocolHandler.ts` parses `claude-cli://` URIs and launches the binary in a terminal with the right cwd/repo context. 8 + 9 + **IDE bridge:** `bridge/` communicates with VS Code and JetBrains extensions (diffs, context). Hooks like `useDiffInIDE.ts` open IDE-native diff UIs when available. 10 + 11 + **Chrome:** `claudeInChrome/` implements native messaging and MCP servers for the [Chrome](https://code.claude.com/docs/en/chrome) beta workflow. 12 + 13 + **See also:** [VS Code](https://code.claude.com/docs/en/vs-code), [JetBrains](https://code.claude.com/docs/en/jetbrains), [Desktop](https://code.claude.com/docs/en/desktop).
+11
docs-site/docs/reference/repl-ui.md
··· 1 + # REPL and terminal UI 2 + 3 + **Primary paths:** `src/screens/REPL.tsx`, `src/components/`, `src/ink/`, `src/replLauncher.tsx`, `src/interactiveHelpers.tsx` 4 + 5 + The interactive session is a **React + Ink** application. `replLauncher.tsx` mounts the Ink root and wraps the tree with providers for app state, keybindings, MCP connections, and plugin context. 6 + 7 + `REPL.tsx` is large and central: it manages the transcript, loading state, `onQuery` invocations, tool use UI, permission prompts, teammate inbox polling, mailbox bridge, voice integration when `VOICE_MODE` is compiled in, scheduled cron integration, and queue processing between turns. 8 + 9 + `ink/` contains layout primitives, terminal I/O helpers, and event wiring specific to the TUI. `components/` holds feature UI (modals, tool output, plan mode, etc.). 10 + 11 + **See also:** [Interactive mode](https://code.claude.com/docs/en/interactive-mode), [Fullscreen](https://code.claude.com/docs/en/fullscreen), [Workflows](../workflows.md).
+11
docs-site/docs/reference/settings-policy.md
··· 1 + # Settings, policy, and remote management 2 + 3 + **Primary paths:** `src/utils/settings/`, `src/services/policyLimits/`, `src/services/remoteManagedSettings/`, `src/schemas/`, `src/migrations/` 4 + 5 + `settings.ts` and `settingsCache.ts` load merged global and project settings. `mdm/` contains macOS managed-device reads. `validation.ts` enforces schema and tool allowlists. 6 + 7 + `policyLimits/` loads enterprise caps (models, spend, features). `remoteManagedSettings/` syncs server-delivered configuration described in [Server-managed settings](https://code.claude.com/docs/en/server-managed-settings). 8 + 9 + `migrations/` upgrades on-disk settings between versions. 10 + 11 + **See also:** [Settings](https://code.claude.com/docs/en/settings), [Environment variables](https://code.claude.com/docs/en/env-vars).
+7
docs-site/docs/reference/telemetry.md
··· 1 + # Analytics and telemetry 2 + 3 + **Primary paths:** `src/services/analytics/`, `src/utils/telemetry/` 4 + 5 + Event logging, GrowthBook/feature flags, Datadog and first-party exporters, session tracing (including Perfetto-oriented paths), and plugin/skill load telemetry live here. Analytics respects disable flags and trust gating initialized after user consent. 6 + 7 + **See also:** [Analytics](https://code.claude.com/docs/en/analytics), [Monitoring](https://code.claude.com/docs/en/monitoring-usage).
+11
docs-site/docs/reference/tools.md
··· 1 + # Tools registry and execution 2 + 3 + **Primary paths:** `src/tools.ts`, `src/Tool.ts`, `src/tools/*`, `src/services/tools/` 4 + 5 + `tools.ts` exposes `getTools(permissionContext)` and helpers to merge **built-in** tools with **MCP-derived** tools. Built-ins live as one package per directory under `tools/` (e.g. `BashTool`, `FileReadTool`, `GlobTool`, `WebSearchTool`, `AgentTool`). 6 + 7 + `services/tools/` contains orchestration: `toolExecution.ts`, `StreamingToolExecutor.ts`, `toolHooks.ts`, hooking tool lifecycle into analytics and permission systems. 8 + 9 + Tool schemas and permission requirements align with the public [Tools reference](https://code.claude.com/docs/en/tools-reference); this tree is the implementation of those capabilities. 10 + 11 + **See also:** [Tools reference](https://code.claude.com/docs/en/tools-reference), [Appendix: tool packages](../appendix/tool-packages.md).
+11
docs-site/docs/reference/voice-vim-output.md
··· 1 + # Voice, Vim, and output styles 2 + 3 + **Primary paths:** `src/voice/`, `src/vim/`, `src/outputStyles/`, `src/screens/REPL.tsx` (voice hook) 4 + 5 + Voice dictation integrates through `useVoiceIntegration` in `REPL.tsx` when the bundle includes `VOICE_MODE`. `voice/` contains mode and streaming helpers. 6 + 7 + `vim/` implements modal editing for the prompt (motions, operators, text objects) consistent with [Interactive mode](https://code.claude.com/docs/en/interactive-mode) keyboard behavior. 8 + 9 + `outputStyles/` adapts presentation for non-default “output styles” described in the [Output styles](https://code.claude.com/docs/en/output-styles) doc. 10 + 11 + **See also:** [Voice dictation](https://code.claude.com/docs/en/voice-dictation), [Keybindings](https://code.claude.com/docs/en/keybindings).
+32
docs-site/docs/reproducibility.md
··· 1 + # Reproducibility and limits 2 + 3 + !!! warning "You cannot rebuild the shipping CLI from this tree alone" 4 + This folder is a **source reconstruction**, not a complete open-source project drop. 5 + 6 + ## What is missing for a full build 7 + 8 + 1. **No root `package.json`** 9 + The published npm package bundles dependencies internally. This repo does not declare versions or scripts to reproduce that bundle. 10 + 11 + 2. **Bun-specific build features** 12 + The entry module uses `bun:bundle` APIs such as `feature('KAIROS')`, `feature('COORDINATOR_MODE')`, `feature('VOICE_MODE')`, etc. Those are compile-time gates in Anthropic’s **internal** bundling pipeline, not something you can flip in a stock TypeScript compile. 13 + 14 + 3. **Private or unpublished packages** 15 + Imports may reference packages or paths that exist only inside Anthropic’s build graph. 16 + 17 + 4. **Native addons** 18 + Some flows (keychain, protocol handlers, optional NAPI modules) assume native binaries shipped beside the real `claude` executable. 19 + 20 + ## What you _can_ do with this tree 21 + 22 + - **Read and trace** control flow: `main.tsx` → REPL or `cli/print.ts` → `query.ts` / `QueryEngine.ts` → `services/api` → tools. 23 + - **Compare behavior** to the public [CLI reference](https://code.claude.com/docs/en/cli-reference) and [how Claude Code works](https://code.claude.com/docs/en/how-claude-code-works). 24 + - **Study** MCP, permissions, compaction, hooks, and IDE bridge code against [official feature docs](https://code.claude.com/docs/en/features-overview). 25 + 26 + ## “Infrastructure” in the sense of this codebase 27 + 28 + There is **no** separate microservice repo here: the CLI is a **single process** (plus child processes for bash, MCP servers, etc.) that talks to **Anthropic’s cloud APIs** and optional **MCP** servers over stdio/WebSocket. Enterprise features (remote-managed settings, policy limits, OAuth) are implemented as **client-side** modules under `src/services/` and `src/utils/settings/`, not as deployable server code in this tree. 29 + 30 + ## Legal 31 + 32 + Rebuilding or redistributing the product for end users is outside the scope of these docs and may infringe Anthropic’s rights. Use this material for **analysis** only unless you have explicit permission.
+77
docs-site/docs/workflows.md
··· 1 + # End-to-end workflows 2 + 3 + !!! warning "Recovered source" 4 + Behavior described here is inferred from `src/`; the shipping product may differ by version or build flags. 5 + 6 + ## Interactive terminal session 7 + 8 + 1. **Process start** — `main.tsx` evaluates side-effect imports (profiler, MDM, keychain prefetch), then parses argv with Commander. 9 + 2. **`preAction` hook** — Trust dialog state, global config, remote-managed settings, policy limits, GrowthBook/feature flags, OAuth/API key paths, MCP official registry prefetch, plugin initialization, and similar steps run before the subcommand handler. 10 + 3. **REPL launch** — `replLauncher.tsx` creates the Ink root and renders providers (`AppState`, keybindings, MCP manager, etc.) and mounts `screens/REPL.tsx`. 11 + 4. **Input** — User typing, paste, voice (if `VOICE_MODE`), teammate messages, and task notifications enqueue work. 12 + 5. **Queue** — `utils/queueProcessor.ts` dequeues slash commands and bash lines individually; batches other same-mode items and calls `executeInput`. 13 + 6. **Query** — `query.ts` `queryLoop` streams model output, schedules tool calls, applies permission checks, and updates transcript state. 14 + 7. **Tools** — `services/tools/toolExecution.ts` / `StreamingToolExecutor` and per-tool modules under `tools/*` perform filesystem, shell, web, MCP, and agent operations. 15 + 8. **Compaction** — When context limits approach, `services/compact/*` reduces history per compaction policy. 16 + 17 + **Official parallels:** [Interactive mode](https://code.claude.com/docs/en/interactive-mode), [How Claude Code works](https://code.claude.com/docs/en/how-claude-code-works). 18 + 19 + ## Print mode / stream-json / programmatic control 20 + 21 + 1. **Routing** — `main.tsx` selects the print/headless path instead of the full REPL when `-p` / related flags are used. 22 + 2. **Structured I/O** — `cli/structuredIO.ts` parses lines into typed events; `cli/print.ts` `runHeadlessStreaming` runs the async loop that consumes user/control messages and emits stdout messages. 23 + 3. **Engine** — `QueryEngine.submitMessage` builds `processUserInputContext` for non-interactive sessions and streams SDK-style messages. 24 + 25 + **Official parallels:** [Run Claude Code programmatically](https://code.claude.com/docs/en/headless), [Agent SDK overview](https://platform.claude.com/docs/en/agent-sdk/overview) (external platform docs). 26 + 27 + ## Teammates / agent teams 28 + 29 + 1. **Spawn** — Swarm backends (`utils/swarm/backends/*`) create tmux panes, iTerm panes, or in-process runners. 30 + 2. **Teammate loop** — `utils/swarm/inProcessRunner.ts` runs a `while` loop: build prompt messages, check compaction/token limits, call into shared query/tool paths, sync permissions via `leaderPermissionBridge`, etc. 31 + 3. **REPL integration** — `REPL.tsx` wires `useInboxPoller`, `useMailboxBridge`, and `handleIncomingPrompt` so teammate messages become user turns. 32 + 33 + **Official parallels:** [Agent teams](https://code.claude.com/docs/en/agent-teams), [Subagents](https://code.claude.com/docs/en/sub-agents). 34 + 35 + ## Hooks (user-configured) 36 + 37 + 1. **Session start** — `utils/sessionStart.ts` `processSessionStartHooks` / `processSetupHooks` run after configuration is known; wired from startup paths in `main.tsx` and related modules. 38 + 2. **Per-event hooks** — Additional hook types align with the schema described in the official [Hooks reference](https://code.claude.com/docs/en/hooks); implementation is spread across hook runners and tool lifecycle code. 39 + 40 + **Official parallels:** [Hooks guide](https://code.claude.com/docs/en/hooks-guide), [Hooks reference](https://code.claude.com/docs/en/hooks). 41 + 42 + ## Compaction and context 43 + 44 + 1. **Triggers** — Token estimation and session memory modules decide when to compact. 45 + 2. **Pipeline** — `services/compact/compact.ts`, `autoCompact.ts`, `microCompact.ts`, and related files rewrite or summarize message history. 46 + 3. **Post-compact** — Cleanup hooks update UI and storage. 47 + 48 + **Official parallels:** [Context window](https://code.claude.com/docs/en/context-window), [Checkpointing](https://code.claude.com/docs/en/checkpointing), [Costs](https://code.claude.com/docs/en/costs). 49 + 50 + ## MCP and external tools 51 + 52 + 1. **Config** — `services/mcp/config.ts`, env expansion, enterprise allowlists. 53 + 2. **Connection** — `MCPConnectionManager.tsx`, stdio and SDK transports. 54 + 3. **Tool surface** — `tools/MCPTool`, `ReadMcpResourceTool`, `ListMcpResourcesTool`, `McpAuthTool`. 55 + 56 + **Official parallels:** [MCP](https://code.claude.com/docs/en/mcp), [Channels](https://code.claude.com/docs/en/channels). 57 + 58 + ## Optional sequence (interactive turn) 59 + 60 + ```mermaid 61 + sequenceDiagram 62 + participant User 63 + participant REPL as REPL.tsx 64 + participant Queue as queueProcessor 65 + participant Query as queryLoop 66 + participant API as services/api 67 + participant Tool as tools/* 68 + User->>REPL: input / slash command 69 + REPL->>Queue: enqueue 70 + Queue->>REPL: executeInput 71 + REPL->>Query: onQuery messages 72 + Query->>API: stream completion 73 + API-->>Query: tool_use 74 + Query->>Tool: execute 75 + Tool-->>Query: result 76 + Query-->>REPL: update transcript 77 + ```
+87
docs-site/mkdocs.yml
··· 1 + # Set site_url after first GitHub Pages deploy, e.g. https://YOUR_USER.github.io/claude-code-source-code/ 2 + site_name: Claude Code internals (recovered source) 3 + site_description: Architecture and code reference for the reconstructed Claude Code CLI tree, cross-linked to official Anthropic docs. 4 + site_author: Repository maintainers 5 + 6 + # Update for your fork: 7 + repo_url: https://github.com/marium/claude-code-source-code 8 + repo_name: claude-code-source-code 9 + edit_uri: edit/main/docs-site/docs/ 10 + 11 + theme: 12 + name: material 13 + palette: 14 + - media: "(prefers-color-scheme: light)" 15 + scheme: default 16 + primary: indigo 17 + accent: indigo 18 + toggle: 19 + icon: material/brightness-7 20 + name: Switch to dark mode 21 + - media: "(prefers-color-scheme: dark)" 22 + scheme: slate 23 + primary: indigo 24 + accent: indigo 25 + toggle: 26 + icon: material/brightness-4 27 + name: Switch to light mode 28 + features: 29 + - navigation.tabs 30 + - navigation.sections 31 + - navigation.expand 32 + - navigation.top 33 + - search.suggest 34 + - search.highlight 35 + - content.code.copy 36 + 37 + markdown_extensions: 38 + - admonition 39 + - pymdownx.details 40 + - pymdownx.superfences: 41 + custom_fences: 42 + - name: mermaid 43 + class: mermaid 44 + format: !!python/name:pymdownx.superfences.fence_code_format 45 + - pymdownx.tabbed: 46 + alternate_style: true 47 + - tables 48 + - toc: 49 + permalink: true 50 + 51 + nav: 52 + - Home: index.md 53 + - Getting started: 54 + - installation.md 55 + - reproducibility.md 56 + - Architecture: 57 + - architecture.md 58 + - workflows.md 59 + - Official docs map: official-docs-map.md 60 + - Reference: 61 + - reference/cli-entry.md 62 + - reference/repl-ui.md 63 + - reference/query-engine.md 64 + - reference/tools.md 65 + - reference/mcp.md 66 + - reference/lsp.md 67 + - reference/permissions.md 68 + - reference/compaction.md 69 + - reference/settings-policy.md 70 + - reference/plugins-skills.md 71 + - reference/print-sdk.md 72 + - reference/api-client.md 73 + - reference/telemetry.md 74 + - reference/voice-vim-output.md 75 + - reference/remote-bridge.md 76 + - Appendix: 77 + - appendix/directory-structure.md 78 + - appendix/tool-packages.md 79 + - appendix/environment-variables.md 80 + 81 + plugins: 82 + - search 83 + 84 + extra: 85 + social: 86 + - icon: fontawesome/brands/github 87 + link: https://github.com/marium/claude-code-source-code
+1
docs-site/requirements.txt
··· 1 + mkdocs-material>=9.5.0,<10
+8
docs/README.md
··· 1 + # Documentation 2 + 3 + The **MkDocs site** (for GitHub Pages) lives in **`docs-site/`**. 4 + 5 + - Source pages: `docs-site/docs/` 6 + - Local preview: `cd docs-site && python3 -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt && mkdocs serve` 7 + 8 + The file **`directory-structure.md`** in this folder remains a quick `src/` layout reference duplicated in the site under **Appendix → Directory structure**.
+26
scripts/gen-appendices.sh
··· 1 + #!/usr/bin/env bash 2 + # Regenerate appendix artifacts for local analysis (optional). 3 + # Run from repository root: bash scripts/gen-appendices.sh 4 + set -euo pipefail 5 + ROOT="$(cd "$(dirname "$0")/.." && pwd)" 6 + OUT_DIR="$ROOT/docs-site/docs/appendix" 7 + mkdir -p "$OUT_DIR" 8 + 9 + echo "# Generated: unique process.env references (do not edit by hand)" > "$OUT_DIR/_generated-env-vars.txt" 10 + echo "" >> "$OUT_DIR/_generated-env-vars.txt" 11 + if command -v rg >/dev/null 2>&1; then 12 + rg -o 'process\.env\.[A-Za-z0-9_]+' "$ROOT/src" --glob '*.ts' --glob '*.tsx' 2>/dev/null | sort -u >> "$OUT_DIR/_generated-env-vars.txt" || true 13 + else 14 + echo "ripgrep (rg) not found; skipped env extraction." >> "$OUT_DIR/_generated-env-vars.txt" 15 + fi 16 + 17 + echo "Wrote $OUT_DIR/_generated-env-vars.txt (add to .gitignore if you do not want to commit)." 18 + 19 + # Optional: print tool table rows for pasting into tool-packages.md 20 + echo "" 21 + echo "--- Tool package rows (markdown) ---" 22 + for d in "$ROOT/src/tools"/*/; do 23 + [[ -d "$d" ]] || continue 24 + b=$(basename "$d") 25 + echo "| \`$b\` | \`src/tools/$b/\` |" 26 + done | sort