Claude Code Source Mirror

repository·main·Indexed 26 days ago

https://github.com/yasasbanukaofficial/claude-code

A research-oriented mirror of the Claude Code source code, discovered via exposed sourcemaps. This repository allows for the study of Anthropic's official AI coding CLI, including its multi-agent orchestration (Swarm), internal systems like BUDDY, KAIROS, and ULTRAPLAN, and its implementation of the Model Context Protocol (MCP). It includes documentation on CLI handlers for authentication, auto-mode configuration, MCP server management, and plugin administration.

Tokens
11.5K
Snippets
6
Records
89
Agent score
87%

What's inside claude-code

  1. Overview of Claude Code Architecture

    main

    The project is structured around a massive main.tsx entry point using Commander.js and React/Ink for terminal rendering. Key architectural components include:

    • src/main.tsx: The CLI Entrypoint.
    • src/QueryEngine.ts: Core LLM logic.
    • src/Tool.ts: Base tool definitions.
    • src/tools/: Over 40 agent tools (e.g., Bash, Files, LSP, Web).
    • src/services/: Backend services (MCP, OAuth, Analytics, Dreams).
    • src/coordinator/: Multi-agent orchestration (Swarm).
    • src/bridge/: IDE Integration layer.
    • src/buddy/: The Tamagotchi-style companion system.
  2. Explore the source code using MCP

    main

    You can use the Model Context Protocol (MCP) to explore this repository's source code directly using Claude. Add the code-explorer MCP server by running the following command in your terminal:

    claude mcp add code-explorer -- npx -y claude-code-explorer-mcp
  3. Install and run the Claude Code source mirror

    main

    To explore the leaked Claude Code source code locally, ensure you have the Bun runtime (recommended) or Node.js v18+ and TypeScript installed globally. Follow these steps to set up and run the project:

    1. Clone the repository.
    2. Install dependencies using npm.
    3. Build the project.
    4. Run the compiled CLI using node.
    git clone https://github.com/your-username/claude-leaked.git
    cd claude-leaked
    npm install
    npm run build
    node dist/main.js
  4. Authenticate with Claude Code

    main

    Use the authentication flow to log in to your Anthropic account. You can choose between claude.ai (default) or the Anthropic Console using specific flags. If you are in an enterprise environment, you can also specify SSO.

    Authentication Methods:

    • Default/Claude.ai: Standard OAuth flow.
    • Console: Use the --console flag to authenticate via the Anthropic Console.
    • SSO: Use the --sso flag for Single Sign-On.

    Note: You cannot use --console and --claudeai simultaneously.

  5. Manage marketplaces via CLI

    main

    The ManageMarketplaces component provides a CLI-driven interface for managing marketplace configurations, including adding, removing, and updating marketplace settings.

    Available Actions

    • Add Marketplace: Adds a new marketplace to the system.
    • Remove Marketplace: Removes an existing marketplace.
    • Update Marketplace: Updates the configuration of an existing marketplace (supports update and toggle-auto-update actions).
    • View Marketplace Details: Displays information about a specific marketplace.
    • List Marketplaces: Shows all currently configured marketplaces.

    Usage via Input

    Users can interact with the marketplace management system by providing specific input characters:

    • y or Y: Confirm an action (e.g., confirming a removal or an update).
    • n or N: Cancel/Abort an action.
    • r or R: Trigger a refresh/reload of the marketplace list.
  6. Enable XAA (SEP-990) for MCP servers

    main

    To enable XAA (SEP-990) for an MCP server, use the --xaa flag. This requires the following prerequisites:

    1. The environment variable CLAUDE_CODE_ENABLE_XAA=1 must be set.
    2. You must have previously run claude mcp xaa setup.
    3. You must provide --client-id and either --client-secret or have the secret available via environment variables.

    Note: --xaa is only supported for http and sse transports.

  7. Authenticate via Environment Variables (Headless/CI)

    main

    For non-interactive environments, you can bypass the browser-based OAuth flow by providing a refresh token and its associated scopes via environment variables.

    Required Environment Variables:

    • CLAUDE_CODE_OAUTH_REFRESH_TOKEN: The OAuth refresh token.
    • CLAUDE_CODE_OAUTH_SCOPES: A space-separated list of scopes the token was issued with (e.g., user:inference or user:profile user:inference user:sessions:claude_code user:mcp_servers).
  8. Manage marketplaces in Claude Code

    main

    The ManageMarketplaces component provides a UI for interacting with configured marketplaces. It allows users to view existing marketplaces, add new ones, and remove them.

    Marketplace Actions

    • Add Marketplace: Opens a configuration dialog to specify marketplace details.
    • Remove Marketplace: Removes a selected marketplace from the configuration.
    • Update Marketplace: (Available when an update process is enabled) Triggers an automatic update of the marketplace and its installed plugins.

    Marketplace Details Displayed

    For each marketplace, the following information is shown:

    • Name: The identifier for the marketplace.
    • Source: The origin/source of the marketplace.
    • Plugin Count: The number of plugins currently installed.
    • Installed Plugins: A list of plugins, showing their name and manifest description.
    • Status: Indicates if the marketplace is currently being processed (e.g., updating).
    • Last Updated: The timestamp of the most recent update.

    Configuration Interface

    When adding or configuring a marketplace, the following fields are available via the ConfigureMarketplaceShift component:

    • accept: Set to select:accept (Action: select:accept, Context: Select, Fallback: Enter).
    • context: Set to Select (Action: select:select, Context: Select, Fallback: Enter).
    • description: Set to select (Action: select:select, Context: Select, Fallback: Enter).
    • confirm:no: (Action: confirm:no, Context: Confirmation, Fallback: Esc).
    • update: (Action: update, Context: Update).
    • remove: (Action: remove, Context: Remove).
  9. Update Claude Code

    main

    Use the update command to check for and install the latest version of Claude Code. The update process automatically detects your installation method (e.g., npm-local, npm-global, or native) and uses the appropriate mechanism to perform the update.

    Update Channels: Updates are checked against the channel specified in your initial settings, which defaults to latest.

    Common Update Scenarios:

    • Package Manager Managed: If Claude was installed via a system package manager, the tool will provide the specific command you need to run manually.

      • Homebrew: brew upgrade claude-code
      • Winget: winget upgrade Anthropic.ClaudeCode
      • APK: apk upgrade claude-code
      • Other (pacman, deb, rpm): Use your system's package manager directly.
    • Native Installation: If using a native installation, the tool attempts to update using the native updater. If an update is successful, the completion cache is automatically regenerated.

    • NPM (Local or Global): If installed via npm, the tool will attempt to run npm update or npm install -g automatically.

    Troubleshooting Update Failures:

    • Insufficient Permissions: If you encounter a no_permissions error:
      • For local installs: Try cd ~/.claude/local && npm update <package-url>
      • For global installs: Try running with sudo or consider switching to a native installation using claude install.
    • Installation in Progress: If another instance is performing an update, wait and try again later.
    • Network/Registry Issues: If the tool cannot reach the npm registry, check your internet connection, corporate proxy/firewall settings, or run with the --debug flag for more details.
  10. Authenticate GitHub App via OAuth flow

    main

    When installing the GitHub App, the CLI initiates an OAuth flow to create a long-lived token for GitHub Actions.

    If the browser does not open automatically, the CLI provides a sign-in URL. You can copy this URL or use the provided keyboard shortcut to copy it to your clipboard.

    OAuth States:

    • starting: Initializing the authentication process.
    • waiting_for_login: Waiting for the user to sign in via the provided URL.
    • processing: Authenticating the provided credentials.
    • success: Authentication token created successfully.
    • error: An error occurred during OAuth. If toRetry is true, you can press Enter to retry or any other key to cancel. If not, you can press any key to return to API key selection.
    • about_to_retry: Retrying the authentication process.