Claude Code Source Recovery (v2.1.88)

repository·master·Indexed 25 days ago

https://github.com/ponponon/claude_code_src

A source code recovery project for @anthropic-ai/claude-code version 2.1.88. This repository uses recovered source maps to reconstruct the original TypeScript codebase, providing insights into the CLI architecture, command systems, React + Ink terminal UI components, and Model Context Protocol (MCP) implementations.

Tokens
13.3K
Snippets
5
Records
87
Agent score
79%

What's inside claude_code_src

  1. Understand the Claude Code source structure

    master

    This repository is a reconstruction of the @anthropic-ai/claude-code v2.1.88 source code, recovered from source maps. The project follows a modular architecture organized under the src/ directory:

    • src/entrypoints/: Contains CLI entry points and initialization logic.
    • src/commands/: The command system, including commands like login, mcp, review, and tasks.
    • src/components/: Terminal UI components built using React + Ink.
    • src/services/: Core business logic, including strategies, synchronization, and remote capabilities.
    • src/hooks/: State management for interactive terminal sessions.
    • src/utils/: Utility functions for authentication, file operations, and process management.
    • src/ink/: Custom infrastructure for terminal rendering.
  2. Core design patterns in Claude Code

    master

    The recovered source code reveals several key architectural patterns used in the Claude Code CLI:

    • Command Loading Mechanism: A hybrid system that supports built-in commands, dynamic skills, plugins, and MCP (Model Context Protocol) commands.
    • Terminal UI: Uses React components to construct complex, interactive interfaces within the terminal.
    • MCP Integration: Deep implementation and application of the Model Context Protocol within the CLI.
    • Feature Flags: Extensive use of feature flags for feature trimming and build-time control logic.
  3. Attempting to run the recovered source

    master

    Since this is a source recovery project and not a pre-built package, you cannot run it immediately. To attempt to make the code functional, you must follow these steps:

    1. Add a package.json and configure the necessary dependencies.
    2. Implement/complete the build toolchain.
    3. Handle bun:bundle macros and feature flags.
    4. Verify the execution of core commands.
  4. Install Claude Code v2.1.88 via Tencent Mirror

    master

    Because version 2.1.88 of @anthropic-ai/claude-code was removed from the official npm registry, a standard npm install will fail. You can install this specific version using the Tencent Cloud mirror cache by pointing directly to the .tgz file.

    Note: This installation method relies on the availability of the mirror cache and may not be permanent.

    npm install -g https://mirrors.cloud.tencent.com/npm/@anthropic-ai/claude-code/-/claude-code-2.1.88.tgz
  5. Browse the Plugin Marketplace UI

    master

    The BrowseMarketplace component provides a user interface for exploring available plugins within the Claude Code environment. It displays a list of plugins, their metadata (name, version, description, and category), and provides specific actions for each plugin.

    Plugin Actions

    • Install: If a plugin is not already installed, this action triggers the installation process.
    • Uninstall: If a plugin is already installed, this action allows the user to remove it.
    • Configure: For certain plugins, a configuration option is available to adjust settings.
    • Command Management: Displays available commands associated with a plugin.
    • Agent Management: Displays agents associated with a plugin.
    • Hooks: Displays available hooks for the plugin.
    • MCP Servers: Displays Model Context Protocol (MCP) servers associated with the plugin.

    UI States

    • Loading: Shows a loading indicator while plugins are being fetched.
    • Empty: Displays a message when no plugins are available.
    • Error: Displays an error message if the plugin retrieval fails.
    • Scroll Down: An indicator that more plugins are available below the current view.
  6. Plugin discovery UI components

    master

    The plugin discovery interface is composed of several key UI elements:

    • SearchBox: Used for entering queries to find plugins.
    • Plugin Details View: Displays information about a selected plugin, including its name, marketplace name, version, and description.
    • Plugin Options Flow: A specialized view for handling plugin installation or project-based installation (e.g., install-user or install-project).
    • Plugin List: A scrollable list of available plugins.
    • Warning Banner: Displays warnings if there are errors during the plugin loading process.
  7. Understand the GitHub App OAuth flow in Claude Code

    master

    The GitHub App installation process uses an OAuth flow to create a long-lived authentication token for GitHub Actions. The UI manages several states during this lifecycle:

    • starting: The initial state where the process begins.
    • waiting_for_login: The system waits for the user to sign in via a browser. If the browser doesn't open automatically, a URL is provided for manual use.
    • processing: The system is currently verifying the authentication.
    • success: The authentication token has been created successfully and is ready for use in GitHub Actions.
    • error: An error occurred during the OAuth process. If the error is retryable, the user can press Enter to try again.
    • about_to_retry: A transient state shown while the system attempts to retry the authentication.

    If the flow enters a waiting_for_login state and the user needs to manually paste a code, a text input prompt is displayed.

  8. Manual OAuth code entry format

    master

    When performing a manual OAuth authentication flow (e.g., when the browser-based flow fails or a prompt appears), the system expects a specific input format. The user must provide the full authorization code string, which includes the authorization code and the state, separated by a hash symbol (#).

    Expected Format: authorizationCode#state

    If the input does not contain both parts, the authentication will fail with an 'Invalid code' error.

  9. Enable XAA (SEP-990) for MCP servers

    master

    To use XAA (SEP-990) for an MCP server, you must first run claude mcp xaa setup. When adding the server, include the --xaa flag. This mode requires both --client-id and --client-secret (or the MCP_CLIENT_SECRET environment variable) to be provided for the MCP server's Authorization Server (AS).

    Note: XAA is only supported for http and sse transports; it will be ignored for stdio servers.

  10. How Claude Code detects installation methods

    master

    Claude Code uses a diagnostic process to determine how it was installed, which dictates how it handles updates and configuration. This prevents conflicts between different installation types.

    Installation Types

    • native: Installed via the native installer (preferred).
    • npm-local: Installed as a local npm package (typically in ~/.claude/local).
    • npm-global: Installed globally via npm.
    • package-manager: Managed by system tools like Homebrew, winget, or apk.
    • development: A local development build (cannot be updated via the update command).

    Configuration Syncing

    If your global configuration's installMethod does not match the detected installationType, the CLI will automatically update your configuration to reflect the current reality to ensure future updates use the correct mechanism.

  11. Understand Ultrareview billing and quotas

    master

    Ultrareview usage is subject to quota and billing rules based on your subscription plan:

    • Team and Enterprise Subscribers: Ultrareview is included; no free-review quota or extra usage dialogs are shown.
    • Consumer Plans (Pro/Max):
      • You have a limited number of free reviews. The tool will notify you of your remaining quota (e.g., This is free ultrareview 1 of 5.).
      • Once free reviews are exhausted, you can enable Extra Usage to continue reviewing.
      • If your Extra Usage balance is very low (less than 10 credits), the tool will warn you.

    If you are on a consumer plan and have exhausted your free quota, you will be prompted to confirm billing for Extra Usage. Once confirmed in a session, subsequent /ultrareview calls in that same session will proceed without re-prompting.

  12. Manage installed plugins

    master

    The marketplace management system allows for interacting with installed plugins:

    • Install Plugins: Use the install action with a plugin name (e.g., install('plugin-name')) to add a plugin from a marketplace.
    • Remove Plugins: Use the remove action with a plugin name (e.g., remove('plugin-name')) to uninstall a plugin.
    • Update Plugins: Use the update action to update a specific plugin to its latest version.

    Note: The install action requires the plugin to be present in the marketplace's available plugins list.