the claude code sourcemaps leaked march 31
0
fork

Configure Feed

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

remove docs for clutter will be it a seperate repo and just add link for full documentation

-1414
-2
.gitattributes
··· 1 - # Auto detect text files and perform LF normalization 2 - * text=auto
-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
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.
-20
docs-site/docs/appendix/glossary.md
··· 1 - # Glossary 2 - 3 - Short definitions for terms used across this site and the `src/` tree. Authoritative product wording remains in [official Claude Code docs](https://code.claude.com/docs/en/overview). 4 - 5 - | Term | Meaning (in this codebase) | 6 - | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | 7 - | **Agent / teammate** | Secondary model actors coordinated with the main session; implemented largely in `utils/swarm/`. | 8 - | **Compaction** | Reducing or rewriting transcript/history to fit context limits; `services/compact/`. | 9 - | **Coordinator** | Internal multi-agent coordination feature gated by `COORDINATOR_MODE`; `coordinator/`. | 10 - | **GrowthBook** | Feature-flag / experiment client for product behaviors; `services/analytics/growthbook.ts`. | 11 - | **Headless / print** | Non-TUI mode with structured stdin/stdout; `cli/print.ts`, `QueryEngine.ts`. | 12 - | **KAIROS** | Bundle-time gate for assistant-oriented code paths; `assistant/`. | 13 - | **MCP** | Model Context Protocol; `services/mcp/`, MCP tools under `tools/`. | 14 - | **REPL** | Interactive terminal UI session; `screens/REPL.tsx`. | 15 - | **Session hooks** | User-configured shell hooks on lifecycle events; see `utils/sessionStart.ts` and official [Hooks](https://code.claude.com/docs/en/hooks). | 16 - | **Swarm** | Implementation umbrella for teammate spawning (tmux, iTerm, in-process); `utils/swarm/`. | 17 - | **Teleport** | Session handoff / remote resume flows; `utils/teleport/`, related API modules. | 18 - | **Tool loop** | Alternation between model streaming and tool execution until the turn completes; centered on `query.ts`. | 19 - | **Trust** | User acknowledgement of workspace risk before applying project config; wired from `main.tsx` / config utilities. | 20 - | **VOICE_MODE** | Compile-time gate for voice dictation in the REPL; `voice/`. |
-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.
-76
docs-site/docs/architecture.md
··· 1 - # Architecture overview 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 - ## System design (deeper dives) 41 - 42 - | Topic | Page | 43 - | --------------------------------- | ----------------------------------------------------------------- | 44 - | Layering and dependency direction | [Architectural layers](system-design/layers.md) | 45 - | State, messages, and persistence | [State and data flow](system-design/state-and-data-flow.md) | 46 - | Trust, permissions, MCP policy | [Security and trust model](system-design/security-trust-model.md) | 47 - 48 - ## Short orientation 49 - 50 - - **Entry** — `main.tsx`: Commander CLI, `preAction` (trust, settings, telemetry gates), side-effect imports (profiler, MDM, keychain prefetch). 51 - - **Interactive host** — `replLauncher.tsx`, `screens/REPL.tsx`, `utils/queueProcessor.ts`. 52 - - **Headless host** — `cli/print.ts`, `QueryEngine.ts`, `cli/structuredIO.ts`. 53 - - **Tools & MCP** — `tools.ts`, `tools/*`, `services/mcp/`, `services/tools/`. 54 - - **IDE / OS** — `bridge/`, `utils/deepLink/`, `utils/claudeInChrome/`. 55 - 56 - ## Key files (quick index) 57 - 58 - | Path | Role | 59 - | -------------------------------------------------- | ------------------------------------------- | 60 - | `main.tsx` | CLI entry, global options, `preAction` | 61 - | `screens/REPL.tsx` | Interactive session core | 62 - | `query.ts` | Streaming query loop, tool round-trips | 63 - | `QueryEngine.ts` | Headless query submission | 64 - | `cli/print.ts` | Print / stream-json / SDK control transport | 65 - | `tools.ts` / `Tool.ts` | Tool registry and types | 66 - | `services/api/client.ts`, `services/api/claude.ts` | HTTP / streaming API | 67 - | `utils/permissions/` | Permission modes and prompts | 68 - | `services/compact/` | Compaction pipeline | 69 - | `utils/sessionStart.ts` | Session / setup hooks | 70 - 71 - ## Further reading 72 - 73 - - [Workflows](workflows.md) — end-to-end sequences. 74 - - [Official docs map](official-docs-map.md) — product docs ↔ `src/`. 75 - - [Reference](reference/cli-entry.md) — subsystem reference pages. 76 - - [Glossary](appendix/glossary.md).
-26
docs-site/docs/developer/bun-bundle-and-feature-flags.md
··· 1 - # Bun bundle and feature flags 2 - 3 - The shipping Claude Code CLI is built with **Bun** and internal **`bun:bundle`** integration. In the recovered source, `src/main.tsx` uses compile-time feature gates such as: 4 - 5 - - `feature('KAIROS')` — lazy `require` of `assistant/` (assistant / Agent SDK–oriented paths). 6 - - `feature('COORDINATOR_MODE')` — lazy `require` of `coordinator/coordinatorMode`. 7 - - `feature('VOICE_MODE')` — conditional `useVoiceIntegration` in `REPL.tsx`. 8 - 9 - ## What `feature()` means here 10 - 11 - In Anthropic’s pipeline, `feature('…')` is almost certainly a **constant** resolved at bundle time: dead branches are stripped from the published `cli.js`. The reconstruction **contains all branches** as TypeScript, so you can read “internal” code paths that might not ship in every npm artifact. 12 - 13 - ## Implications for “building from source” 14 - 15 - A normal `tsc` or `bun build` **without** Anthropic’s bundler will not reproduce: 16 - 17 - - The same dead-code elimination. 18 - - The same `bun:bundle` API semantics. 19 - - The same proprietary dependency closure. 20 - 21 - That is one reason [Reproducibility and limits](../reproducibility.md) states you cannot rebuild the shipping binary from this mirror. 22 - 23 - ## See also 24 - 25 - - [System design: layers](../system-design/layers.md) 26 - - [CLI entry reference](../reference/cli-entry.md)
-29
docs-site/docs/developer/editing-documentation.md
··· 1 - # Editing this documentation 2 - 3 - ## Local setup 4 - 5 - ```bash 6 - cd docs-site 7 - python3 -m venv .venv 8 - source .venv/bin/activate # Windows: .venv\Scripts\activate 9 - pip install -r requirements.txt 10 - mkdocs serve 11 - ``` 12 - 13 - Open `http://127.0.0.1:8000` and edit files under `docs-site/docs/`. The site reloads on save. 14 - 15 - ## Conventions 16 - 17 - - Use **admonitions** for legal and safety notes (`!!! warning` for proprietary / leak context). 18 - - Prefer **relative links** between pages (`../reference/cli-entry.md` in source becomes sibling URLs when built). 19 - - Add **mermaid** only where diagrams clarify flow; keep [mermaid syntax](https://mermaid.js.org/) compatible with [Material diagrams](https://squidfunk.github.io/mkdocs-material/reference/diagrams/). 20 - 21 - ## After structural changes 22 - 23 - If you add a **new top-level topic** that appears in [Anthropic’s docs index](https://code.claude.com/docs/llms.txt), add a row to [Official docs map](../official-docs-map.md). 24 - 25 - ## Publishing 26 - 27 - Pushing to `main` runs the GitHub Action that deploys to `gh-pages`. Ensure `site_url` in `mkdocs.yml` matches your GitHub Pages base URL. 28 - 29 - See also: [Documentation and CI for your own projects](../guides/documentation-and-ci-for-docs.md).
-25
docs-site/docs/developer/index.md
··· 1 - # Developer hub (this repository) 2 - 3 - !!! warning "Not an open-source product repo" 4 - This tree is **reconstructed proprietary source**. You can maintain **documentation**, trace **read-only** flow in `src/`, and run small **helper scripts**. You **cannot** legally ship Claude Code from this mirror, and there is no supported way to compile the full CLI here. 5 - 6 - ## What you can do 7 - 8 - | Activity | How | 9 - | ---------------------------- | ---------------------------------------------------------------------------------------------------------------------- | 10 - | **Preview or extend docs** | [Editing documentation](editing-documentation.md) | 11 - | **Understand control flow** | [Navigating the source](navigating-the-source.md) | 12 - | **Learn build-time gates** | [Bun bundle and feature flags](bun-bundle-and-feature-flags.md) | 13 - | **Regenerate appendix data** | `scripts/gen-appendices.sh` at repo root (see [Appendix: environment variables](../appendix/environment-variables.md)) | 14 - 15 - ## What you cannot do (from this mirror alone) 16 - 17 - - Run `npm install` / `bun build` for the full product (no root `package.json`, private graph, `bun:bundle` feature flags). 18 - - Execute a project-wide automated test suite for the CLI (no harness shipped in the reconstruction). 19 - 20 - Details: [Reproducibility and limits](../reproducibility.md). 21 - 22 - ## Related 23 - 24 - - [System design: layers](../system-design/layers.md) 25 - - [Official docs map](../official-docs-map.md)
-37
docs-site/docs/developer/navigating-the-source.md
··· 1 - # Navigating the `src/` tree 2 - 3 - !!! warning "Read-only study" 4 - Use this guide to **read** the reconstruction. Do not treat the tree as a template for redistributing Anthropic’s product. 5 - 6 - ## Suggested reading order 7 - 8 - 1. **`main argv` and lifecycle** — `src/main.tsx` (Commander, `preAction`, mode routing). 9 - 2. **Interactive path** — `src/replLauncher.tsx`, `src/screens/REPL.tsx` (queue, `onQuery`, UI). 10 - 3. **Headless path** — `src/cli/print.ts`, `src/cli/structuredIO.ts`, `src/QueryEngine.ts`. 11 - 4. **Core loop** — `src/query.ts` (`queryLoop`), then `src/services/api/client.ts` / `claude.ts`. 12 - 5. **Tools** — `src/tools.ts`, `src/Tool.ts`, then a single tool package e.g. `src/tools/BashTool/` and `src/services/tools/`. 13 - 6. **MCP** — `src/services/mcp/` and `src/tools/MCPTool/`. 14 - 15 - ## Maps and indexes 16 - 17 - - Top-level layout: [Appendix: directory structure](../appendix/directory-structure.md) (and repo `docs/directory-structure.md`). 18 - - Tool packages: [Appendix: tool packages](../appendix/tool-packages.md). 19 - - Official doc crosswalk: [Official docs map](../official-docs-map.md). 20 - 21 - ## Search tips 22 - 23 - From the repository root: 24 - 25 - ```bash 26 - # Example: find where a symbol is used 27 - rg "queryLoop" src/query.ts src/ -n 28 - 29 - # Example: MCP channel permissions 30 - rg "channelAllowlist" src/services/mcp -n 31 - ``` 32 - 33 - IDE “go to definition” may be incomplete: there is **no** root `tsconfig.json` or `package.json` mirroring Anthropic’s build, so path aliases like `src/...` might not resolve everywhere. 34 - 35 - ## Deeper subsystems 36 - 37 - Use the [Reference](../reference/cli-entry.md) section for per-topic entry points (permissions, compaction, telemetry, bridge, etc.).
-39
docs-site/docs/guides/building-an-agentic-cli-overview.md
··· 1 - # Building your own agentic coding CLI (greenfield) 2 - 3 - !!! danger "Do not clone proprietary code" 4 - This page describes how to build **new** tooling from **public** APIs and OSS patterns. It is **not** instructions to copy or redistribute the leaked `src/` tree as “open-source Claude Code.” Anthropic’s Claude Code remains **proprietary**. 5 - 6 - ## What “agentic CLI” means 7 - 8 - A minimal agent loop: 9 - 10 - 1. **Context** — project files, git status, user prompt. 11 - 2. **Model** — calls a capable LLM API with tools/functions defined in schema form. 12 - 3. **Tools** — read/write files, grep, run shell (with guardrails), call HTTP, etc. 13 - 4. **Loop** — model requests tools → host executes → results appended → model continues until done. 14 - 15 - Claude Code implements this pattern in TypeScript with extra product layers (trust, compaction, MCP, IDE bridge). Your project can be far smaller. 16 - 17 - ## Stack options (all legitimate OSS / vendor SDKs) 18 - 19 - | Piece | Common choices | 20 - | ----------------- | -------------------------------------------------------------------------------------------------------------------- | 21 - | **Runtime** | Node.js, Bun, Deno, Go, Python | 22 - | **Terminal UI** | None (pure stdin/stdout), [Ink](https://github.com/vadimdemedes/ink) (React), blessed, bubbletea | 23 - | **CLI parsing** | Commander, yargs, clap (Rust), Typer (Python) | 24 - | **Anthropic API** | Official [Anthropic SDK](https://docs.anthropic.com/) and [Messages API](https://docs.anthropic.com/en/api/messages) | 25 - | **MCP** | [Model Context Protocol](https://modelcontextprotocol.io) SDKs and server examples | 26 - | **Sandboxes** | Containers, `firejail`, allow-listed commands, separate VMs (depends on threat model) | 27 - 28 - ## OSS / public projects to study (examples, not endorsements) 29 - 30 - Look for **actively maintained** agent or coding assistants under licenses you accept. Examples people often cite in the ecosystem include **Aider**, terminal agents built on **Continue** or **Codex-style** CLIs, and **MCP servers** in the official registry. **Compare licenses and security posture yourself**—do not assume parity with Claude Code. 31 - 32 - ## Relationship to this repository 33 - 34 - Use the `src/` mirror to **learn patterns** (how compaction, MCP, or permissions _can_ be structured). Re-implement ideas in **your own codebase** with your own naming and design; do not paste Anthropic’s source into a public repo. 35 - 36 - ## Next 37 - 38 - - [MCP and tool-loop patterns](mcp-and-tool-loop-patterns.md) — abstract loop without copying this tree. 39 - - [Documentation and CI](documentation-and-ci-for-docs.md) — ship docs like this site.
-29
docs-site/docs/guides/documentation-and-ci-for-docs.md
··· 1 - # Documentation and CI (pattern from this repo) 2 - 3 - You can reuse the **same mechanics** this project uses for **any** open-source or internal project docs—not Claude Code itself. 4 - 5 - ## Ingredients 6 - 7 - | Piece | Location here | 8 - | --------------- | --------------------------------------------------------------------------------------------------------------------- | 9 - | **Static site** | [MkDocs](https://www.mkdocs.org/) + [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/) | 10 - | **Sources** | `docs-site/docs/**/*.md`, `docs-site/mkdocs.yml` | 11 - | **Build** | `mkdocs build -f docs-site/mkdocs.yml` | 12 - | **Deploy** | GitHub Actions → `gh-pages` branch (e.g. [peaceiris/actions-gh-pages](https://github.com/peaceiris/actions-gh-pages)) | 13 - 14 - ## Checklist for a new repo 15 - 16 - 1. Add `docs-site/` with `mkdocs.yml`, `requirements.txt`, and Markdown under `docs/`. 17 - 2. Set `site_url` when GitHub Pages URL is known. 18 - 3. Add workflow: Python setup → `pip install -r docs-site/requirements.txt` → `mkdocs build` → deploy `docs-site/site`. 19 - 4. Enable **GitHub Pages** from `gh-pages` / root (or switch to GitHub’s native Pages Actions upload). 20 - 5. Use `enable_jekyll: false` (or commit `.nojekyll`) so Jekyll does not skip underscore paths. 21 - 22 - ## This fork’s live site 23 - 24 - Configured `site_url`: [https://mehmoodosman.github.io/claude-code-source-code/](https://mehmoodosman.github.io/claude-code-source-code/) 25 - 26 - ## See also 27 - 28 - - [Installation](../installation.md) — local preview commands 29 - - [Editing documentation](../developer/editing-documentation.md)
-31
docs-site/docs/guides/mcp-and-tool-loop-patterns.md
··· 1 - # MCP and tool-loop patterns (abstract) 2 - 3 - !!! note "Conceptual only" 4 - This page describes **common agent architectures**. It references `src/` modules only as **illustrations** of where similar ideas appear in Claude Code—not as code to copy. 5 - 6 - ## Tool loop (functions / tools) 7 - 8 - 1. Define tools with **names, descriptions, and JSON Schema** (or equivalent) for arguments. 9 - 2. Send user + conversation + tool definitions to the model. 10 - 3. If the model returns a **tool call**, validate arguments, **execute** on the host, append a **tool_result** message (or provider-specific equivalent). 11 - 4. Repeat until the model finishes without further tool calls or a cap is hit. 12 - 13 - In this reconstruction, much of that orchestration lives in `query.ts` and adjacent helpers, while tool implementations live under `tools/*` and `services/tools/`. 14 - 15 - ## MCP (Model Context Protocol) 16 - 17 - **MCP** standardizes how tools and resources are exposed by **servers** the host spawns and talks to over stdio or other transports. Claude Code’s `services/mcp/` implements configuration, transports, OAuth, and channel-style push—see **[MCP reference](../reference/mcp.md)** for file-level mapping. 18 - 19 - For **your** project: 20 - 21 - - Start from [MCP documentation](https://modelcontextprotocol.io) and official SDKs. 22 - - Implement **one** small MCP server (e.g. filesystem or git) before designing a full IDE-quality integration. 23 - 24 - ## Parallel: skills and plugins 25 - 26 - Claude Code layers **skills** (project-scoped instructions + commands) and **plugins** on top of the core loop. Greenfield designs might use: simple slash-commands, `SKILL.md` conventions, or dynamic imports—without reproducing this product’s plugin manifest. 27 - 28 - ## See also 29 - 30 - - [Building an agentic CLI overview](building-an-agentic-cli-overview.md) 31 - - [Official: MCP](https://code.claude.com/docs/en/mcp)
-33
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 - | [System design](system-design/layers.md) | Layers, state/data flow, security and trust model. | 23 - | [Architecture](architecture.md) | Overview diagram and links into system design + reference. | 24 - | [Workflows](workflows.md) | Interactive REPL, print/headless, swarm, compaction paths. | 25 - | [Developer hub](developer/index.md) | Working on docs, navigating `src/`, Bun feature flags. | 26 - | [Guides](guides/building-an-agentic-cli-overview.md) | **Greenfield** agentic CLI and docs/CI patterns—not cloning this leak. | 27 - | [Official docs map](official-docs-map.md) | Every indexed doc page ↔ `src/` entry points. | 28 - | [Reference](reference/cli-entry.md) | Deeper dives per subsystem. | 29 - | [Appendix](appendix/directory-structure.md) | Directory layout, tool packages, environment variables, [glossary](appendix/glossary.md). | 30 - 31 - ## Repository 32 - 33 - Source code lives under `src/` on GitHub ([mehmoodosman/claude-code-source-code](https://github.com/mehmoodosman/claude-code-source-code)). This site is published at **[https://mehmoodosman.github.io/claude-code-source-code/](https://mehmoodosman.github.io/claude-code-source-code/)** via GitHub Actions from `docs-site/`.
-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. Set `site_url` in `mkdocs.yml` to your real Pages URL (this fork uses `https://mehmoodosman.github.io/claude-code-source-code/`) and keep `repo_url` aligned with your GitHub owner so “edit” links and sitemaps stay correct. 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.
-68
docs-site/docs/system-design/layers.md
··· 1 - # Architectural layers 2 - 3 - !!! warning "Recovered proprietary source" 4 - Descriptions are for **study** of the `src/` mirror only. This is not an open-source distribution of Claude Code. 5 - 6 - The Claude Code CLI is organized as **downward dependencies**: the shell and UI call into the query core and services; core logic does not depend on React/Ink components for correctness (headless paths prove that). 7 - 8 - ## Layer stack (conceptual) 9 - 10 - | Layer | Responsibility | Primary `src/` locations | 11 - | ------------------------ | ------------------------------------------------------------ | ---------------------------------------------------------------------------------------- | 12 - | **CLI shell** | argv parsing, global flags, subcommands, `preAction` startup | `main.tsx`, `commands/`, `cli/handlers/` | 13 - | **Session host** | Interactive TUI vs structured print/SDK transport | `replLauncher.tsx`, `screens/REPL.tsx`, `cli/print.ts`, `cli/structuredIO.ts` | 14 - | **Query core** | Turn loop, streaming, tool round-trips, context assembly | `query.ts`, `QueryEngine.ts`, `utils/processUserInput/` | 15 - | **Transport** | Anthropic (and provider) HTTP/streaming | `services/api/` | 16 - | **Tooling** | Registry, execution, hooks | `tools.ts`, `Tool.ts`, `tools/*`, `services/tools/` | 17 - | **Integrations** | MCP, LSP, OAuth, IDE bridge | `services/mcp/`, `services/lsp/`, `services/oauth/`, `bridge/` | 18 - | **Policy & persistence** | Settings, compaction, session storage, telemetry | `utils/settings/`, `services/compact/`, `utils/sessionStorage.ts`, `services/analytics/` | 19 - 20 - ## Dependency direction 21 - 22 - ```mermaid 23 - flowchart TB 24 - subgraph presentation [Presentation] 25 - Main[main.tsx] 26 - REPL[REPL.tsx] 27 - Print[cli/print.ts] 28 - end 29 - subgraph domain [Domain_core] 30 - Query[query.ts] 31 - QE[QueryEngine.ts] 32 - end 33 - subgraph ports [Ports] 34 - API[services/api] 35 - Tools[tools plus services/tools] 36 - MCP[services/mcp] 37 - end 38 - subgraph infra [Infrastructure] 39 - Settings[utils/settings] 40 - Compact[services/compact] 41 - Store[sessionStorage] 42 - end 43 - Main --> REPL 44 - Main --> Print 45 - REPL --> Query 46 - Print --> QE 47 - Query --> API 48 - Query --> Tools 49 - QE --> API 50 - QE --> Tools 51 - Tools --> MCP 52 - Query --> Compact 53 - QE --> Compact 54 - Query --> Settings 55 - Main --> Settings 56 - ``` 57 - 58 - **Rule of thumb:** `components/` and `ink/` sit under the REPL branch; `cli/print.ts` bypasses most of that stack but still shares `QueryEngine`, tools, API, and compaction. 59 - 60 - ## Feature gates 61 - 62 - Some “layers” exist only in certain shipping builds: `assistant/` (KAIROS), `coordinator/` (`COORDINATOR_MODE`), voice (`VOICE_MODE`). See [Bun bundle and feature flags](../developer/bun-bundle-and-feature-flags.md). 63 - 64 - ## See also 65 - 66 - - [State and data flow](state-and-data-flow.md) 67 - - [Security and trust model](security-trust-model.md) 68 - - [Architecture overview](../architecture.md)
-60
docs-site/docs/system-design/security-trust-model.md
··· 1 - # Security and trust model 2 - 3 - !!! warning "Recovered proprietary source" 4 - This page summarizes **code structure**, not a formal security audit. Follow [official Security](https://code.claude.com/docs/en/security) and [Permissions](https://code.claude.com/docs/en/permissions) guidance for the product. 5 - 6 - ## Trust and workspace 7 - 8 - Before destructive work runs, startup paths in `main.tsx` consult trust and workspace state (global config helpers under `utils/config.ts`, managed env under `utils/managedEnv.ts`). The intent is to avoid applying repo-supplied config or hooks until the user has acknowledged risk—public discussion of past ordering bugs is summarized in vendor advisories; always run an **up-to-date** official Claude Code build for production use. 9 - 10 - ## Permission modes 11 - 12 - `utils/permissions/` defines modes (manual approval, auto with classifiers, plan-only variants, etc.). `permissionSetup.ts` and related modules: 13 - 14 - - Parse CLI flags (`--permission-mode`, internal aliases). 15 - - Strip or gate “dangerous” capabilities when using auto mode. 16 - - Feed **always-allow** tool lists into `toolPermissionContext`. 17 - 18 - User-facing reference: [Permission modes](https://code.claude.com/docs/en/permission-modes). 19 - 20 - ## Bash and sandboxing 21 - 22 - Shell execution flows through `utils/shell/` (bash and PowerShell providers, output limits, read-only validation) and `tools/BashTool/`. Enterprise and product docs describe [Sandboxing](https://code.claude.com/docs/en/sandboxing) behavior; the source tree implements isolation and validation at the tool layer. 23 - 24 - ## MCP and enterprise policy 25 - 26 - - **Config** — `services/mcp/config.ts` parses MCP server lists, env expansion, deduplication, and enterprise allowlists. 27 - - **Channels** — `services/mcp/channelAllowlist.ts` and related modules gate inbound push notifications. 28 - 29 - Official: [MCP](https://code.claude.com/docs/en/mcp), [Channels](https://code.claude.com/docs/en/channels). 30 - 31 - ## Hooks 32 - 33 - User-defined hooks (session start, post-tool, etc.) are wired through `utils/sessionStart.ts` and related runners; they execute shell commands with the privileges of the CLI process. Treat untrusted projects as **untrusted code** until you understand hook content. 34 - 35 - Official: [Hooks](https://code.claude.com/docs/en/hooks). 36 - 37 - ## Trust check order (conceptual) 38 - 39 - ```mermaid 40 - flowchart TD 41 - start[Process_start] 42 - config[Load_safe_config_order] 43 - trust[Workspace_trust] 44 - perms[Permission_mode_setup] 45 - hooks[Session_hooks] 46 - tools[Tool_execution] 47 - start --> config 48 - config --> trust 49 - trust --> perms 50 - perms --> hooks 51 - hooks --> tools 52 - ``` 53 - 54 - Exact ordering evolves by version; correlate with `main.tsx` `preAction` and `entrypoints/init` when reading the mirror. 55 - 56 - ## See also 57 - 58 - - [Permissions reference](../reference/permissions.md) 59 - - [MCP reference](../reference/mcp.md) 60 - - [Reproducibility and limits](../reproducibility.md)
-50
docs-site/docs/system-design/state-and-data-flow.md
··· 1 - # State and data flow 2 - 3 - !!! warning "Recovered proprietary source" 4 - For authoritative product behavior, use [official Claude Code docs](https://code.claude.com/docs/en/overview). 5 - 6 - ## End-to-end message path (interactive) 7 - 8 - 1. **Input** — User text, slash commands, teammate notifications, or task items reach `screens/REPL.tsx`. 9 - 2. **Queue** — `utils/queueProcessor.ts` serializes or batches commands and calls `executeInput`. 10 - 3. **Query** — `query.ts` `queryLoop` streams the model, surfaces `tool_use` blocks, and applies permission checks using `toolPermissionContext` from app state. 11 - 4. **Execution** — `services/tools/` (e.g. `StreamingToolExecutor`, `toolExecution.ts`) dispatches to modules under `tools/*` or MCP-backed tools. 12 - 5. **Persistence** — Transcript updates, session metadata, and compaction boundaries flow through `utils/sessionStorage.ts`, conversation recovery helpers, and related hooks. 13 - 14 - ## State ownership 15 - 16 - | Concern | Typical modules | 17 - | ----------------------- | ------------------------------------------------------------------------------------------ | 18 - | **Global app state** | `state/` (providers, stores such as `AppStateStore.ts`) | 19 - | **Context / stats** | `context/` | 20 - | **Messages** | `utils/messages.ts`, message types under `types/message` (and generated types) | 21 - | **Permissions** | `utils/permissions/`, fields on tool permission context updated from CLI and REPL | 22 - | **File / edit history** | Wired through process-user-input and tool hooks (see compaction and attribution utilities) | 23 - 24 - ## Simplified sequence (one turn) 25 - 26 - ```mermaid 27 - sequenceDiagram 28 - participant UI as REPL_or_print 29 - participant Q as queryLoop 30 - participant API as services_api 31 - participant Exec as tool_executor 32 - participant Store as session_storage 33 - UI->>Q: user_or_control_messages 34 - Q->>API: stream_completion 35 - API-->>Q: assistant_tool_use 36 - Q->>Exec: run_tool 37 - Exec-->>Q: tool_result 38 - Q->>Store: persist_transcript_updates 39 - Q-->>UI: render_updates 40 - ``` 41 - 42 - ## Headless differences 43 - 44 - In print/SDK paths: `QueryEngine.ts` builds a `processUserInputContext` with `isNonInteractiveSession: true`, streams SDK-style messages, and bridges permission prompts over structured I/O instead of Ink dialogs. The **same** underlying message and tool model is reused. 45 - 46 - ## See also 47 - 48 - - [Workflows](../workflows.md) 49 - - [Query loop and streaming](../reference/query-engine.md) 50 - - [Compaction](../reference/compaction.md)
-83
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 - ``` 78 - 79 - ## See also 80 - 81 - - [Architecture overview](architecture.md) 82 - - [State and data flow](system-design/state-and-data-flow.md) 83 - - [Official docs map](official-docs-map.md)
-100
docs-site/mkdocs.yml
··· 1 - site_url: https://mehmoodosman.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 - repo_url: https://github.com/mehmoodosman/claude-code-source-code 7 - repo_name: claude-code-source-code 8 - edit_uri: edit/main/docs-site/docs/ 9 - 10 - theme: 11 - name: material 12 - palette: 13 - - media: "(prefers-color-scheme: light)" 14 - scheme: default 15 - primary: indigo 16 - accent: indigo 17 - toggle: 18 - icon: material/brightness-7 19 - name: Switch to dark mode 20 - - media: "(prefers-color-scheme: dark)" 21 - scheme: slate 22 - primary: indigo 23 - accent: indigo 24 - toggle: 25 - icon: material/brightness-4 26 - name: Switch to light mode 27 - features: 28 - - navigation.tabs 29 - - navigation.sections 30 - - navigation.expand 31 - - navigation.top 32 - - search.suggest 33 - - search.highlight 34 - - content.code.copy 35 - 36 - markdown_extensions: 37 - - admonition 38 - - pymdownx.details 39 - - pymdownx.superfences: 40 - custom_fences: 41 - - name: mermaid 42 - class: mermaid 43 - format: !!python/name:pymdownx.superfences.fence_code_format 44 - - pymdownx.tabbed: 45 - alternate_style: true 46 - - tables 47 - - toc: 48 - permalink: true 49 - 50 - nav: 51 - - Home: index.md 52 - - Getting started: 53 - - installation.md 54 - - reproducibility.md 55 - - System design: 56 - - system-design/layers.md 57 - - system-design/state-and-data-flow.md 58 - - system-design/security-trust-model.md 59 - - Architecture: 60 - - architecture.md 61 - - workflows.md 62 - - Developer: 63 - - developer/index.md 64 - - developer/editing-documentation.md 65 - - developer/navigating-the-source.md 66 - - developer/bun-bundle-and-feature-flags.md 67 - - Guides: 68 - - guides/building-an-agentic-cli-overview.md 69 - - guides/mcp-and-tool-loop-patterns.md 70 - - guides/documentation-and-ci-for-docs.md 71 - - Official docs map: official-docs-map.md 72 - - Reference: 73 - - reference/cli-entry.md 74 - - reference/repl-ui.md 75 - - reference/query-engine.md 76 - - reference/tools.md 77 - - reference/mcp.md 78 - - reference/lsp.md 79 - - reference/permissions.md 80 - - reference/compaction.md 81 - - reference/settings-policy.md 82 - - reference/plugins-skills.md 83 - - reference/print-sdk.md 84 - - reference/api-client.md 85 - - reference/telemetry.md 86 - - reference/voice-vim-output.md 87 - - reference/remote-bridge.md 88 - - Appendix: 89 - - appendix/directory-structure.md 90 - - appendix/tool-packages.md 91 - - appendix/environment-variables.md 92 - - appendix/glossary.md 93 - 94 - plugins: 95 - - search 96 - 97 - extra: 98 - social: 99 - - icon: fontawesome/brands/github 100 - link: https://github.com/mehmoodosman/claude-code-source-code
-1
docs-site/requirements.txt
··· 1 - mkdocs-material>=9.5.0,<10
-10
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**. 9 - 10 - The published site also includes **System design**, **Developer**, **Guides** (greenfield agent CLI + docs CI), and **Glossary**; see navigation in `docs-site/mkdocs.yml`.
-78
docs/directory-structure.md
··· 1 - # `src/` directory structure 2 - 3 - This document mirrors the **top levels** of the recovered `src/` tree in this repository (as of the leak reconstruction). Deeper nesting is omitted except where it helps navigation. 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, for example: `BashTool`, `FileReadTool`, `FileWriteTool`, `FileEditTool`, `GlobTool`, `GrepTool`, `WebSearchTool`, `WebFetchTool`, `MCPTool`, `AgentTool`, `TodoWriteTool`, `TaskCreateTool`, `TaskListTool`, `EnterWorktreeTool`, `ExitWorktreeTool`, `LSPTool`, `SkillTool`, `REPLTool`, … plus `shared/` and `testing/`. 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.
-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