···11-# Directory structure (`src/`)
22-33-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.
44-55-## Package root files
66-77-| File | Notes |
88-| --------------------------- | ----------------------------------------------------------------------------------------------- |
99-| `main.tsx` | CLI entry: Commander setup, `preAction` trust/settings/telemetry, routing to REPL or print mode |
1010-| `commands.ts` | Command registry |
1111-| `tools.ts` | Tool registry (see also `tools/` directory) |
1212-| `Tool.ts` | Tool types / shared tool definitions |
1313-| `QueryEngine.ts` | Model / API query pipeline |
1414-| `context.ts` | System and user context |
1515-| `cost-tracker.ts` | Token / cost tracking |
1616-| `costHook.ts` | Cost hook wiring |
1717-| `dialogLaunchers.tsx` | Ink dialogs (resume, settings, teleport, etc.) |
1818-| `history.ts` | Input history |
1919-| `ink.ts` | Ink root / render helpers |
2020-| `interactiveHelpers.tsx` | Interactive UI helpers |
2121-| `projectOnboardingState.ts` | Onboarding state |
2222-| `query.ts` | Query helpers |
2323-| `replLauncher.tsx` | REPL launch |
2424-| `setup.ts` | Setup flows |
2525-| `tasks.ts` | Task utilities / constants |
2626-| `Task.ts` | Task types |
2727-2828-## Top-level directories
2929-3030-| Directory | Role |
3131-| ---------------- | ----------------------------------------------------------------------- |
3232-| `assistant/` | Assistant / KAIROS paths (bundle feature-gated) |
3333-| `bootstrap/` | Early boot and global flags (cwd, remote mode, overrides) |
3434-| `bridge/` | IDE integration (VS Code, JetBrains, etc.) |
3535-| `buddy/` | Companion / buddy UI |
3636-| `cli/` | Non-interactive / print mode, transports, NDJSON, subcommand handlers |
3737-| `commands/` | Slash commands and related CLI command modules |
3838-| `components/` | Ink/React UI components |
3939-| `constants/` | Shared constants (OAuth, product URLs, etc.) |
4040-| `context/` | Context subsystems (stats, attachments, etc.) |
4141-| `coordinator/` | Multi-agent coordinator (feature-gated) |
4242-| `entrypoints/` | `init` and related startup entrypoints |
4343-| `hooks/` | React hooks for the terminal UI |
4444-| `ink/` | Ink layout, termio, events (terminal renderer layer) |
4545-| `keybindings/` | Keybinding definitions and providers |
4646-| `memdir/` | Memory directory / persistent memory |
4747-| `migrations/` | Settings and data migrations |
4848-| `moreright/` | Internal layout / UI helper |
4949-| `native-ts/` | Native TypeScript helpers |
5050-| `outputStyles/` | Output styling |
5151-| `plugins/` | Plugin loader and bundled plugins |
5252-| `query/` | Query pipeline modules |
5353-| `remote/` | Remote session / control |
5454-| `schemas/` | Zod (and related) schemas |
5555-| `screens/` | Full-screen flows (doctor, REPL shell, resume) |
5656-| `server/` | Server / socket modes |
5757-| `services/` | API client, MCP, compaction, LSP, analytics, OAuth, policy, etc. |
5858-| `skills/` | Skill loading and bundled skills |
5959-| `state/` | App state providers and reducers |
6060-| `tasks/` | Task implementations (local agent, shell, remote, dream, etc.) |
6161-| `tools/` | One subdirectory per agent-invokable tool |
6262-| `types/` | Shared TypeScript types (incl. generated) |
6363-| `upstreamproxy/` | Upstream proxy configuration |
6464-| `utils/` | Large catch-all: permissions, settings, swarm, shell, git, telemetry, … |
6565-| `vim/` | Vim-style editing in the terminal |
6666-| `voice/` | Voice input |
6767-6868-## `services/` (second level)
6969-7070-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.
7171-7272-## `tools/` (agent tools)
7373-7474-Each major capability is typically its own folder; see [Tool packages](tool-packages.md) for a full directory list.
7575-7676-## `utils/` (highlights)
7777-7878-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
···11-# Environment variables (code references)
22-33-!!! warning "Unofficial and incomplete"
44-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.
55-66-## User-facing and integration (examples found in source)
77-88-| Variable | Where used (indicative) |
99-| ---------------------------------- | ------------------------------------------------------------------------------------------- |
1010-| `ANTHROPIC_BASE_URL` | API client / proxy routing (`toolSearch.ts`, auth paths) |
1111-| `CLAUDE_CODE_GIT_BASH_PATH` | Windows Git Bash resolution (`windowsPaths.ts`) |
1212-| `CLAUDE_DEBUG` | Debug logging (`warningHandler.ts`) |
1313-| `CLAUDE_CODE_ENABLE_TELEMETRY` | OpenTelemetry enable (`telemetry/instrumentation.ts`) |
1414-| `CLAUDE_CODE_ENABLE_TASKS` | Tasks mode (`tasks.ts`) |
1515-| `CLAUDE_CODE_TASK_LIST_ID` | Default task list id (`tasks.ts`) |
1616-| `CLAUDE_CODE_PLAN_MODE_REQUIRED` | Plan mode gate (`teammate.ts`) |
1717-| `CLAUDE_CODE_WORKSPACE_HOST_PATHS` | Telemetry workspace mapping (`telemetry/events.ts`) |
1818-| `ENABLE_TOOL_SEARCH` | Tool search beta (`toolSearch.ts`) |
1919-| `GITHUB_ACTIONS` / `GITHUB_*` | CI metadata in analytics (`user.ts`) |
2020-| `HOME` | XDG / paths (`xdg.ts`) |
2121-| `MAX_THINKING_TOKENS` | Thinking toggle (`thinking.ts`) |
2222-| `NODE_ENV` | Dev/test branches |
2323-| `OTEL_*` | OpenTelemetry exporters and endpoints (`telemetry/instrumentation.ts`, `sessionTracing.ts`) |
2424-| `SHELL` | Shell spawning (`terminalPanel.ts`, `windowsPaths.ts`) |
2525-| `TMUX` / `TMUX_PANE` | Worktree / swarm backends (`worktree.ts`, `swarm/backends/detection.ts`) |
2626-| `TMPDIR` | Temp paths (`tmuxSocket.ts`) |
2727-| `USER_TYPE` | Internal Anthropic gating (`undercover.ts`, many modules) |
2828-2929-## Internal / experimental (often `USER_TYPE === 'ant'`)
3030-3131-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.
3232-3333-## Regenerate a full grep index
3434-3535-From the repo root:
3636-3737-```bash
3838-rg -o 'process\.env\.[A-Za-z0-9_]+' src --glob '*.ts' --glob '*.tsx' | sort -u
3939-```
4040-4141-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
···11-# Glossary
22-33-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).
44-55-| Term | Meaning (in this codebase) |
66-| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
77-| **Agent / teammate** | Secondary model actors coordinated with the main session; implemented largely in `utils/swarm/`. |
88-| **Compaction** | Reducing or rewriting transcript/history to fit context limits; `services/compact/`. |
99-| **Coordinator** | Internal multi-agent coordination feature gated by `COORDINATOR_MODE`; `coordinator/`. |
1010-| **GrowthBook** | Feature-flag / experiment client for product behaviors; `services/analytics/growthbook.ts`. |
1111-| **Headless / print** | Non-TUI mode with structured stdin/stdout; `cli/print.ts`, `QueryEngine.ts`. |
1212-| **KAIROS** | Bundle-time gate for assistant-oriented code paths; `assistant/`. |
1313-| **MCP** | Model Context Protocol; `services/mcp/`, MCP tools under `tools/`. |
1414-| **REPL** | Interactive terminal UI session; `screens/REPL.tsx`. |
1515-| **Session hooks** | User-configured shell hooks on lifecycle events; see `utils/sessionStart.ts` and official [Hooks](https://code.claude.com/docs/en/hooks). |
1616-| **Swarm** | Implementation umbrella for teammate spawning (tmux, iTerm, in-process); `utils/swarm/`. |
1717-| **Teleport** | Session handoff / remote resume flows; `utils/teleport/`, related API modules. |
1818-| **Tool loop** | Alternation between model streaming and tool execution until the turn completes; centered on `query.ts`. |
1919-| **Trust** | User acknowledgement of workspace risk before applying project config; wired from `main.tsx` / config utilities. |
2020-| **VOICE_MODE** | Compile-time gate for voice dictation in the REPL; `voice/`. |
···11-# Bun bundle and feature flags
22-33-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:
44-55-- `feature('KAIROS')` — lazy `require` of `assistant/` (assistant / Agent SDK–oriented paths).
66-- `feature('COORDINATOR_MODE')` — lazy `require` of `coordinator/coordinatorMode`.
77-- `feature('VOICE_MODE')` — conditional `useVoiceIntegration` in `REPL.tsx`.
88-99-## What `feature()` means here
1010-1111-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.
1212-1313-## Implications for “building from source”
1414-1515-A normal `tsc` or `bun build` **without** Anthropic’s bundler will not reproduce:
1616-1717-- The same dead-code elimination.
1818-- The same `bun:bundle` API semantics.
1919-- The same proprietary dependency closure.
2020-2121-That is one reason [Reproducibility and limits](../reproducibility.md) states you cannot rebuild the shipping binary from this mirror.
2222-2323-## See also
2424-2525-- [System design: layers](../system-design/layers.md)
2626-- [CLI entry reference](../reference/cli-entry.md)
-29
docs-site/docs/developer/editing-documentation.md
···11-# Editing this documentation
22-33-## Local setup
44-55-```bash
66-cd docs-site
77-python3 -m venv .venv
88-source .venv/bin/activate # Windows: .venv\Scripts\activate
99-pip install -r requirements.txt
1010-mkdocs serve
1111-```
1212-1313-Open `http://127.0.0.1:8000` and edit files under `docs-site/docs/`. The site reloads on save.
1414-1515-## Conventions
1616-1717-- Use **admonitions** for legal and safety notes (`!!! warning` for proprietary / leak context).
1818-- Prefer **relative links** between pages (`../reference/cli-entry.md` in source becomes sibling URLs when built).
1919-- 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/).
2020-2121-## After structural changes
2222-2323-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).
2424-2525-## Publishing
2626-2727-Pushing to `main` runs the GitHub Action that deploys to `gh-pages`. Ensure `site_url` in `mkdocs.yml` matches your GitHub Pages base URL.
2828-2929-See also: [Documentation and CI for your own projects](../guides/documentation-and-ci-for-docs.md).
-25
docs-site/docs/developer/index.md
···11-# Developer hub (this repository)
22-33-!!! warning "Not an open-source product repo"
44-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.
55-66-## What you can do
77-88-| Activity | How |
99-| ---------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
1010-| **Preview or extend docs** | [Editing documentation](editing-documentation.md) |
1111-| **Understand control flow** | [Navigating the source](navigating-the-source.md) |
1212-| **Learn build-time gates** | [Bun bundle and feature flags](bun-bundle-and-feature-flags.md) |
1313-| **Regenerate appendix data** | `scripts/gen-appendices.sh` at repo root (see [Appendix: environment variables](../appendix/environment-variables.md)) |
1414-1515-## What you cannot do (from this mirror alone)
1616-1717-- Run `npm install` / `bun build` for the full product (no root `package.json`, private graph, `bun:bundle` feature flags).
1818-- Execute a project-wide automated test suite for the CLI (no harness shipped in the reconstruction).
1919-2020-Details: [Reproducibility and limits](../reproducibility.md).
2121-2222-## Related
2323-2424-- [System design: layers](../system-design/layers.md)
2525-- [Official docs map](../official-docs-map.md)
-37
docs-site/docs/developer/navigating-the-source.md
···11-# Navigating the `src/` tree
22-33-!!! warning "Read-only study"
44-Use this guide to **read** the reconstruction. Do not treat the tree as a template for redistributing Anthropic’s product.
55-66-## Suggested reading order
77-88-1. **`main argv` and lifecycle** — `src/main.tsx` (Commander, `preAction`, mode routing).
99-2. **Interactive path** — `src/replLauncher.tsx`, `src/screens/REPL.tsx` (queue, `onQuery`, UI).
1010-3. **Headless path** — `src/cli/print.ts`, `src/cli/structuredIO.ts`, `src/QueryEngine.ts`.
1111-4. **Core loop** — `src/query.ts` (`queryLoop`), then `src/services/api/client.ts` / `claude.ts`.
1212-5. **Tools** — `src/tools.ts`, `src/Tool.ts`, then a single tool package e.g. `src/tools/BashTool/` and `src/services/tools/`.
1313-6. **MCP** — `src/services/mcp/` and `src/tools/MCPTool/`.
1414-1515-## Maps and indexes
1616-1717-- Top-level layout: [Appendix: directory structure](../appendix/directory-structure.md) (and repo `docs/directory-structure.md`).
1818-- Tool packages: [Appendix: tool packages](../appendix/tool-packages.md).
1919-- Official doc crosswalk: [Official docs map](../official-docs-map.md).
2020-2121-## Search tips
2222-2323-From the repository root:
2424-2525-```bash
2626-# Example: find where a symbol is used
2727-rg "queryLoop" src/query.ts src/ -n
2828-2929-# Example: MCP channel permissions
3030-rg "channelAllowlist" src/services/mcp -n
3131-```
3232-3333-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.
3434-3535-## Deeper subsystems
3636-3737-Use the [Reference](../reference/cli-entry.md) section for per-topic entry points (permissions, compaction, telemetry, bridge, etc.).
···11-# Building your own agentic coding CLI (greenfield)
22-33-!!! danger "Do not clone proprietary code"
44-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**.
55-66-## What “agentic CLI” means
77-88-A minimal agent loop:
99-1010-1. **Context** — project files, git status, user prompt.
1111-2. **Model** — calls a capable LLM API with tools/functions defined in schema form.
1212-3. **Tools** — read/write files, grep, run shell (with guardrails), call HTTP, etc.
1313-4. **Loop** — model requests tools → host executes → results appended → model continues until done.
1414-1515-Claude Code implements this pattern in TypeScript with extra product layers (trust, compaction, MCP, IDE bridge). Your project can be far smaller.
1616-1717-## Stack options (all legitimate OSS / vendor SDKs)
1818-1919-| Piece | Common choices |
2020-| ----------------- | -------------------------------------------------------------------------------------------------------------------- |
2121-| **Runtime** | Node.js, Bun, Deno, Go, Python |
2222-| **Terminal UI** | None (pure stdin/stdout), [Ink](https://github.com/vadimdemedes/ink) (React), blessed, bubbletea |
2323-| **CLI parsing** | Commander, yargs, clap (Rust), Typer (Python) |
2424-| **Anthropic API** | Official [Anthropic SDK](https://docs.anthropic.com/) and [Messages API](https://docs.anthropic.com/en/api/messages) |
2525-| **MCP** | [Model Context Protocol](https://modelcontextprotocol.io) SDKs and server examples |
2626-| **Sandboxes** | Containers, `firejail`, allow-listed commands, separate VMs (depends on threat model) |
2727-2828-## OSS / public projects to study (examples, not endorsements)
2929-3030-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.
3131-3232-## Relationship to this repository
3333-3434-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.
3535-3636-## Next
3737-3838-- [MCP and tool-loop patterns](mcp-and-tool-loop-patterns.md) — abstract loop without copying this tree.
3939-- [Documentation and CI](documentation-and-ci-for-docs.md) — ship docs like this site.
···11-# MCP and tool-loop patterns (abstract)
22-33-!!! note "Conceptual only"
44-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.
55-66-## Tool loop (functions / tools)
77-88-1. Define tools with **names, descriptions, and JSON Schema** (or equivalent) for arguments.
99-2. Send user + conversation + tool definitions to the model.
1010-3. If the model returns a **tool call**, validate arguments, **execute** on the host, append a **tool_result** message (or provider-specific equivalent).
1111-4. Repeat until the model finishes without further tool calls or a cap is hit.
1212-1313-In this reconstruction, much of that orchestration lives in `query.ts` and adjacent helpers, while tool implementations live under `tools/*` and `services/tools/`.
1414-1515-## MCP (Model Context Protocol)
1616-1717-**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.
1818-1919-For **your** project:
2020-2121-- Start from [MCP documentation](https://modelcontextprotocol.io) and official SDKs.
2222-- Implement **one** small MCP server (e.g. filesystem or git) before designing a full IDE-quality integration.
2323-2424-## Parallel: skills and plugins
2525-2626-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.
2727-2828-## See also
2929-3030-- [Building an agentic CLI overview](building-an-agentic-cli-overview.md)
3131-- [Official: MCP](https://code.claude.com/docs/en/mcp)
-33
docs-site/docs/index.md
···11-# Claude Code — recovered source internals
22-33-!!! warning "Proprietary software / leaked reconstruction"
44-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.
55-66-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)**.
77-88-## What Claude Code is (official product)
99-1010-From the [product overview](https://code.claude.com/docs/en/overview):
1111-1212-> 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.
1313-1414-The recovered codebase implements primarily the **terminal CLI** surface, plus shared logic for tools, MCP, permissions, compaction, IDE bridge hooks, and related services.
1515-1616-## How to use this site
1717-1818-| Section | Purpose |
1919-| ---------------------------------------------------- | ----------------------------------------------------------------------------------------- |
2020-| [Installation](installation.md) | Build **this documentation** locally; install the **real** Claude Code from Anthropic. |
2121-| [Reproducibility](reproducibility.md) | Why you **cannot** rebuild the shipping npm package from this tree alone. |
2222-| [System design](system-design/layers.md) | Layers, state/data flow, security and trust model. |
2323-| [Architecture](architecture.md) | Overview diagram and links into system design + reference. |
2424-| [Workflows](workflows.md) | Interactive REPL, print/headless, swarm, compaction paths. |
2525-| [Developer hub](developer/index.md) | Working on docs, navigating `src/`, Bun feature flags. |
2626-| [Guides](guides/building-an-agentic-cli-overview.md) | **Greenfield** agentic CLI and docs/CI patterns—not cloning this leak. |
2727-| [Official docs map](official-docs-map.md) | Every indexed doc page ↔ `src/` entry points. |
2828-| [Reference](reference/cli-entry.md) | Deeper dives per subsystem. |
2929-| [Appendix](appendix/directory-structure.md) | Directory layout, tool packages, environment variables, [glossary](appendix/glossary.md). |
3030-3131-## Repository
3232-3333-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
···11-# Installation
22-33-!!! warning "Two different things"
44-**A)** Building this **documentation site** (MkDocs) — instructions below.
55- **B)** Installing **Claude Code** the product — use Anthropic’s official installers only.
66-77-## Install Claude Code (official product)
88-99-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.
1010-1111-## Build this documentation site (local)
1212-1313-Requires Python 3.10+.
1414-1515-```bash
1616-cd docs-site
1717-python3 -m venv .venv
1818-source .venv/bin/activate # Windows: .venv\Scripts\activate
1919-pip install -r requirements.txt
2020-mkdocs serve
2121-```
2222-2323-Open `http://127.0.0.1:8000` to preview.
2424-2525-## Publish (GitHub Pages)
2626-2727-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).
2828-2929-1. In the GitHub repo: **Settings → Pages → Build and deployment → Branch `gh-pages` / `/ (root)`**.
3030-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.
3131-3232-The deploy step sets **`enable_jekyll: false`** so GitHub Pages serves static files correctly (adds `.nojekyll`).
3333-3434-## Advanced setup (official)
3535-3636-For system requirements, updates, and uninstallation of the **product**, see [Advanced setup](https://code.claude.com/docs/en/setup) in the official docs.
···11-# API client and OAuth
22-33-**Primary paths:** `src/services/api/`, `src/services/oauth/`, `src/utils/api.ts`, `src/utils/auth.ts`
44-55-`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.
66-77-`services/oauth/` implements the browser-based OAuth flow (auth code listener, token exchange, crypto).
88-99-**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
···11-# CLI entry and parsing
22-33-**Primary paths:** `src/main.tsx`, `src/cli/*`, `src/commands.ts`
44-55-`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.
66-77-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.
88-99-Feature-gated dynamic `require()` loads `coordinator/coordinatorMode.js` when `COORDINATOR_MODE` is true in the Bun bundle, and `assistant/` when `KAIROS` is true.
1010-1111-**See also:** [CLI reference](https://code.claude.com/docs/en/cli-reference), [Architecture](../architecture.md).
-9
docs-site/docs/reference/compaction.md
···11-# Compaction and session memory
22-33-**Primary paths:** `src/services/compact/`, `src/services/SessionMemory/`, `src/utils/tokenBudget.ts`
44-55-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.
66-77-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).
88-99-**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
···11-# LSP integration
22-33-**Primary paths:** `src/services/lsp/`, `src/tools/LSPTool/`
44-55-`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.
66-77-Passive feedback and config live alongside the manager (`passiveFeedback.ts`, `config.ts`).
88-99-**See also:** [Tools reference](https://code.claude.com/docs/en/tools-reference) (LSP tool), [Architecture](../architecture.md).
-11
docs-site/docs/reference/mcp.md
···11-# MCP (Model Context Protocol)
22-33-**Primary paths:** `src/services/mcp/`, `src/tools/MCPTool/`, `src/tools/McpAuthTool/`, `src/services/mcp/MCPConnectionManager.tsx`
44-55-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.
66-77-Channel-related files (`channelAllowlist`, `channelNotification`, `channelPermissions`) implement **push** notifications into a session, matching the [Channels](https://code.claude.com/docs/en/channels) documentation.
88-99-The React `MCPConnectionManager` wraps interactive sessions so the REPL can connect/disconnect servers and reflect status in the UI.
1010-1111-**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
···11-# Permissions and modes
22-33-**Primary paths:** `src/utils/permissions/`, `src/utils/permissions/permissionSetup.ts`, `src/utils/permissions/PermissionMode.ts`
44-55-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.
66-77-`permissionSetup.ts` and related modules implement gates for auto mode, dangerous permission stripping, and advisor integration.
88-99-**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
···11-# Plugins and skills
22-33-**Primary paths:** `src/plugins/`, `src/skills/`, `src/utils/plugins/`, `src/utils/skills/`, `src/tools/SkillTool/`, `src/services/plugins/`
44-55-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.
66-77-`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).
88-99-**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
···11-# Print mode, stream-json, and SDK control
22-33-**Primary paths:** `src/cli/print.ts`, `src/cli/structuredIO.ts`, `src/cli/transports/*`, `src/QueryEngine.ts`
44-55-`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.
66-77-`structuredIO.ts` parses and validates incoming events; transports (`WebSocketTransport`, `SSETransport`, `HybridTransport`, etc.) support remote SDK and CCR-style integrations.
88-99-This corresponds to [Headless](https://code.claude.com/docs/en/headless) and Agent SDK usage documented on the Anthropic platform.
1010-1111-**See also:** [Workflows](../workflows.md), [Query loop](query-engine.md).
-11
docs-site/docs/reference/query-engine.md
···11-# Query loop and streaming
22-33-**Primary paths:** `src/query.ts`, `src/QueryEngine.ts`, `src/utils/processUserInput/`
44-55-`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.
66-77-`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.
88-99-Shared input processing (slash commands embedded in prompts, tool permission context updates) lives under `utils/processUserInput/` and related modules.
1010-1111-**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
···11-# Remote sessions, teleport, IDE bridge, Chrome
22-33-**Primary paths:** `src/remote/`, `src/utils/teleport/`, `src/utils/deepLink/`, `src/bridge/`, `src/utils/claudeInChrome/`, `src/hooks/useDiffInIDE.ts`
44-55-**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.
66-77-**Deep links:** `deepLink/protocolHandler.ts` parses `claude-cli://` URIs and launches the binary in a terminal with the right cwd/repo context.
88-99-**IDE bridge:** `bridge/` communicates with VS Code and JetBrains extensions (diffs, context). Hooks like `useDiffInIDE.ts` open IDE-native diff UIs when available.
1010-1111-**Chrome:** `claudeInChrome/` implements native messaging and MCP servers for the [Chrome](https://code.claude.com/docs/en/chrome) beta workflow.
1212-1313-**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
···11-# REPL and terminal UI
22-33-**Primary paths:** `src/screens/REPL.tsx`, `src/components/`, `src/ink/`, `src/replLauncher.tsx`, `src/interactiveHelpers.tsx`
44-55-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.
66-77-`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.
88-99-`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.).
1010-1111-**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
···11-# Settings, policy, and remote management
22-33-**Primary paths:** `src/utils/settings/`, `src/services/policyLimits/`, `src/services/remoteManagedSettings/`, `src/schemas/`, `src/migrations/`
44-55-`settings.ts` and `settingsCache.ts` load merged global and project settings. `mdm/` contains macOS managed-device reads. `validation.ts` enforces schema and tool allowlists.
66-77-`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).
88-99-`migrations/` upgrades on-disk settings between versions.
1010-1111-**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
···11-# Analytics and telemetry
22-33-**Primary paths:** `src/services/analytics/`, `src/utils/telemetry/`
44-55-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.
66-77-**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
···11-# Tools registry and execution
22-33-**Primary paths:** `src/tools.ts`, `src/Tool.ts`, `src/tools/*`, `src/services/tools/`
44-55-`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`).
66-77-`services/tools/` contains orchestration: `toolExecution.ts`, `StreamingToolExecutor.ts`, `toolHooks.ts`, hooking tool lifecycle into analytics and permission systems.
88-99-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.
1010-1111-**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
···11-# Voice, Vim, and output styles
22-33-**Primary paths:** `src/voice/`, `src/vim/`, `src/outputStyles/`, `src/screens/REPL.tsx` (voice hook)
44-55-Voice dictation integrates through `useVoiceIntegration` in `REPL.tsx` when the bundle includes `VOICE_MODE`. `voice/` contains mode and streaming helpers.
66-77-`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.
88-99-`outputStyles/` adapts presentation for non-default “output styles” described in the [Output styles](https://code.claude.com/docs/en/output-styles) doc.
1010-1111-**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
···11-# Reproducibility and limits
22-33-!!! warning "You cannot rebuild the shipping CLI from this tree alone"
44-This folder is a **source reconstruction**, not a complete open-source project drop.
55-66-## What is missing for a full build
77-88-1. **No root `package.json`**
99- The published npm package bundles dependencies internally. This repo does not declare versions or scripts to reproduce that bundle.
1010-1111-2. **Bun-specific build features**
1212- 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.
1313-1414-3. **Private or unpublished packages**
1515- Imports may reference packages or paths that exist only inside Anthropic’s build graph.
1616-1717-4. **Native addons**
1818- Some flows (keychain, protocol handlers, optional NAPI modules) assume native binaries shipped beside the real `claude` executable.
1919-2020-## What you _can_ do with this tree
2121-2222-- **Read and trace** control flow: `main.tsx` → REPL or `cli/print.ts` → `query.ts` / `QueryEngine.ts` → `services/api` → tools.
2323-- **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).
2424-- **Study** MCP, permissions, compaction, hooks, and IDE bridge code against [official feature docs](https://code.claude.com/docs/en/features-overview).
2525-2626-## “Infrastructure” in the sense of this codebase
2727-2828-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.
2929-3030-## Legal
3131-3232-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
···11-# Architectural layers
22-33-!!! warning "Recovered proprietary source"
44-Descriptions are for **study** of the `src/` mirror only. This is not an open-source distribution of Claude Code.
55-66-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).
77-88-## Layer stack (conceptual)
99-1010-| Layer | Responsibility | Primary `src/` locations |
1111-| ------------------------ | ------------------------------------------------------------ | ---------------------------------------------------------------------------------------- |
1212-| **CLI shell** | argv parsing, global flags, subcommands, `preAction` startup | `main.tsx`, `commands/`, `cli/handlers/` |
1313-| **Session host** | Interactive TUI vs structured print/SDK transport | `replLauncher.tsx`, `screens/REPL.tsx`, `cli/print.ts`, `cli/structuredIO.ts` |
1414-| **Query core** | Turn loop, streaming, tool round-trips, context assembly | `query.ts`, `QueryEngine.ts`, `utils/processUserInput/` |
1515-| **Transport** | Anthropic (and provider) HTTP/streaming | `services/api/` |
1616-| **Tooling** | Registry, execution, hooks | `tools.ts`, `Tool.ts`, `tools/*`, `services/tools/` |
1717-| **Integrations** | MCP, LSP, OAuth, IDE bridge | `services/mcp/`, `services/lsp/`, `services/oauth/`, `bridge/` |
1818-| **Policy & persistence** | Settings, compaction, session storage, telemetry | `utils/settings/`, `services/compact/`, `utils/sessionStorage.ts`, `services/analytics/` |
1919-2020-## Dependency direction
2121-2222-```mermaid
2323-flowchart TB
2424- subgraph presentation [Presentation]
2525- Main[main.tsx]
2626- REPL[REPL.tsx]
2727- Print[cli/print.ts]
2828- end
2929- subgraph domain [Domain_core]
3030- Query[query.ts]
3131- QE[QueryEngine.ts]
3232- end
3333- subgraph ports [Ports]
3434- API[services/api]
3535- Tools[tools plus services/tools]
3636- MCP[services/mcp]
3737- end
3838- subgraph infra [Infrastructure]
3939- Settings[utils/settings]
4040- Compact[services/compact]
4141- Store[sessionStorage]
4242- end
4343- Main --> REPL
4444- Main --> Print
4545- REPL --> Query
4646- Print --> QE
4747- Query --> API
4848- Query --> Tools
4949- QE --> API
5050- QE --> Tools
5151- Tools --> MCP
5252- Query --> Compact
5353- QE --> Compact
5454- Query --> Settings
5555- Main --> Settings
5656-```
5757-5858-**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.
5959-6060-## Feature gates
6161-6262-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).
6363-6464-## See also
6565-6666-- [State and data flow](state-and-data-flow.md)
6767-- [Security and trust model](security-trust-model.md)
6868-- [Architecture overview](../architecture.md)
···11-# Security and trust model
22-33-!!! warning "Recovered proprietary source"
44-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.
55-66-## Trust and workspace
77-88-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.
99-1010-## Permission modes
1111-1212-`utils/permissions/` defines modes (manual approval, auto with classifiers, plan-only variants, etc.). `permissionSetup.ts` and related modules:
1313-1414-- Parse CLI flags (`--permission-mode`, internal aliases).
1515-- Strip or gate “dangerous” capabilities when using auto mode.
1616-- Feed **always-allow** tool lists into `toolPermissionContext`.
1717-1818-User-facing reference: [Permission modes](https://code.claude.com/docs/en/permission-modes).
1919-2020-## Bash and sandboxing
2121-2222-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.
2323-2424-## MCP and enterprise policy
2525-2626-- **Config** — `services/mcp/config.ts` parses MCP server lists, env expansion, deduplication, and enterprise allowlists.
2727-- **Channels** — `services/mcp/channelAllowlist.ts` and related modules gate inbound push notifications.
2828-2929-Official: [MCP](https://code.claude.com/docs/en/mcp), [Channels](https://code.claude.com/docs/en/channels).
3030-3131-## Hooks
3232-3333-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.
3434-3535-Official: [Hooks](https://code.claude.com/docs/en/hooks).
3636-3737-## Trust check order (conceptual)
3838-3939-```mermaid
4040-flowchart TD
4141- start[Process_start]
4242- config[Load_safe_config_order]
4343- trust[Workspace_trust]
4444- perms[Permission_mode_setup]
4545- hooks[Session_hooks]
4646- tools[Tool_execution]
4747- start --> config
4848- config --> trust
4949- trust --> perms
5050- perms --> hooks
5151- hooks --> tools
5252-```
5353-5454-Exact ordering evolves by version; correlate with `main.tsx` `preAction` and `entrypoints/init` when reading the mirror.
5555-5656-## See also
5757-5858-- [Permissions reference](../reference/permissions.md)
5959-- [MCP reference](../reference/mcp.md)
6060-- [Reproducibility and limits](../reproducibility.md)
···11-# Documentation
22-33-The **MkDocs site** (for GitHub Pages) lives in **`docs-site/`**.
44-55-- Source pages: `docs-site/docs/`
66-- Local preview: `cd docs-site && python3 -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt && mkdocs serve`
77-88-The file **`directory-structure.md`** in this folder remains a quick `src/` layout reference duplicated in the site under **Appendix → Directory structure**.
99-1010-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
···11-# `src/` directory structure
22-33-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.
44-55-## Package root files
66-77-| File | Notes |
88-| --------------------------- | ----------------------------------------------------------------------------------------------- |
99-| `main.tsx` | CLI entry: Commander setup, `preAction` trust/settings/telemetry, routing to REPL or print mode |
1010-| `commands.ts` | Command registry |
1111-| `tools.ts` | Tool registry (see also `tools/` directory) |
1212-| `Tool.ts` | Tool types / shared tool definitions |
1313-| `QueryEngine.ts` | Model / API query pipeline |
1414-| `context.ts` | System and user context |
1515-| `cost-tracker.ts` | Token / cost tracking |
1616-| `costHook.ts` | Cost hook wiring |
1717-| `dialogLaunchers.tsx` | Ink dialogs (resume, settings, teleport, etc.) |
1818-| `history.ts` | Input history |
1919-| `ink.ts` | Ink root / render helpers |
2020-| `interactiveHelpers.tsx` | Interactive UI helpers |
2121-| `projectOnboardingState.ts` | Onboarding state |
2222-| `query.ts` | Query helpers |
2323-| `replLauncher.tsx` | REPL launch |
2424-| `setup.ts` | Setup flows |
2525-| `tasks.ts` | Task utilities / constants |
2626-| `Task.ts` | Task types |
2727-2828-## Top-level directories
2929-3030-| Directory | Role |
3131-| ---------------- | ----------------------------------------------------------------------- |
3232-| `assistant/` | Assistant / KAIROS paths (bundle feature-gated) |
3333-| `bootstrap/` | Early boot and global flags (cwd, remote mode, overrides) |
3434-| `bridge/` | IDE integration (VS Code, JetBrains, etc.) |
3535-| `buddy/` | Companion / buddy UI |
3636-| `cli/` | Non-interactive / print mode, transports, NDJSON, subcommand handlers |
3737-| `commands/` | Slash commands and related CLI command modules |
3838-| `components/` | Ink/React UI components |
3939-| `constants/` | Shared constants (OAuth, product URLs, etc.) |
4040-| `context/` | Context subsystems (stats, attachments, etc.) |
4141-| `coordinator/` | Multi-agent coordinator (feature-gated) |
4242-| `entrypoints/` | `init` and related startup entrypoints |
4343-| `hooks/` | React hooks for the terminal UI |
4444-| `ink/` | Ink layout, termio, events (terminal renderer layer) |
4545-| `keybindings/` | Keybinding definitions and providers |
4646-| `memdir/` | Memory directory / persistent memory |
4747-| `migrations/` | Settings and data migrations |
4848-| `moreright/` | Internal layout / UI helper |
4949-| `native-ts/` | Native TypeScript helpers |
5050-| `outputStyles/` | Output styling |
5151-| `plugins/` | Plugin loader and bundled plugins |
5252-| `query/` | Query pipeline modules |
5353-| `remote/` | Remote session / control |
5454-| `schemas/` | Zod (and related) schemas |
5555-| `screens/` | Full-screen flows (doctor, REPL shell, resume) |
5656-| `server/` | Server / socket modes |
5757-| `services/` | API client, MCP, compaction, LSP, analytics, OAuth, policy, etc. |
5858-| `skills/` | Skill loading and bundled skills |
5959-| `state/` | App state providers and reducers |
6060-| `tasks/` | Task implementations (local agent, shell, remote, dream, etc.) |
6161-| `tools/` | One subdirectory per agent-invokable tool |
6262-| `types/` | Shared TypeScript types (incl. generated) |
6363-| `upstreamproxy/` | Upstream proxy configuration |
6464-| `utils/` | Large catch-all: permissions, settings, swarm, shell, git, telemetry, … |
6565-| `vim/` | Vim-style editing in the terminal |
6666-| `voice/` | Voice input |
6767-6868-## `services/` (second level)
6969-7070-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.
7171-7272-## `tools/` (agent tools)
7373-7474-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/`.
7575-7676-## `utils/` (highlights)
7777-7878-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
···11-#!/usr/bin/env bash
22-# Regenerate appendix artifacts for local analysis (optional).
33-# Run from repository root: bash scripts/gen-appendices.sh
44-set -euo pipefail
55-ROOT="$(cd "$(dirname "$0")/.." && pwd)"
66-OUT_DIR="$ROOT/docs-site/docs/appendix"
77-mkdir -p "$OUT_DIR"
88-99-echo "# Generated: unique process.env references (do not edit by hand)" > "$OUT_DIR/_generated-env-vars.txt"
1010-echo "" >> "$OUT_DIR/_generated-env-vars.txt"
1111-if command -v rg >/dev/null 2>&1; then
1212- 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
1313-else
1414- echo "ripgrep (rg) not found; skipped env extraction." >> "$OUT_DIR/_generated-env-vars.txt"
1515-fi
1616-1717-echo "Wrote $OUT_DIR/_generated-env-vars.txt (add to .gitignore if you do not want to commit)."
1818-1919-# Optional: print tool table rows for pasting into tool-packages.md
2020-echo ""
2121-echo "--- Tool package rows (markdown) ---"
2222-for d in "$ROOT/src/tools"/*/; do
2323- [[ -d "$d" ]] || continue
2424- b=$(basename "$d")
2525- echo "| \`$b\` | \`src/tools/$b/\` |"
2626-done | sort