memaxo
MCP Servermemaxopublic

claude_code_re

对 Claude Code CLI 的静态分析与逆向工程,研究其架构和实现。

Repository Info

1
Stars
1
Forks
1
Watchers
0
Issues
JavaScript
Language
-
License

About This Server

对 Claude Code CLI 的静态分析与逆向工程,研究其架构和实现。

Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.

Documentation

Static Analysis of the Claude Code CLI (claude_code_re)

Overview

This repository contains files related to the static analysis and reverse engineering efforts performed on the minified cli.js file distributed as part of the Claude Code CLI tool by Anthropic.

Target: cli.js (Node.js script, approx. 8.2MB, ~260k lines, minified)

Note: This repository does not contain the original source code for the Claude Code CLI. All analysis is based solely on the publicly distributed, minified JavaScript bundle.

Purpose & Motivation

The primary goal of this project was to understand the architecture, core functionalities, and implementation patterns of a modern, sophisticated command-line AI assistant. Key areas of interest included:

  • Interaction with multiple AI backends (Anthropic API, AWS Bedrock, Google Vertex AI).
  • Implementation of a tool-use system within an LLM context.
  • Credential management and security considerations.
  • Building interactive terminal UIs (likely using React/Ink).
  • Handling large codebases and context management for LLMs.
  • Integration with development environments (e.g., MCP).

This effort was undertaken for educational and research purposes.

Methodology

Due to the large size and minified nature of the cli.js file, direct analysis of the entire codebase within standard tools or context windows was infeasible. The following methodology was employed:

  1. Formatting: The minified cli.js was first formatted using Prettier for basic readability and structure.
  2. Static Analysis: The primary analysis technique.
  3. Targeted Searching (grep): The grep command was used extensively with context flags (-C) to search for specific patterns, keywords, string literals (like API endpoints, tool names, library identifiers), and function call patterns within the large file without loading it entirely.
  4. Snippet Analysis: Code snippets returned by grep were manually analyzed to hypothesize functionality and identify key minified identifiers.
  5. Variable/Function Mapping: An ongoing effort was made to map minified identifiers (e.g., I, Z, P9, tO) to their likely original purpose based on context. This mapping is documented in VARIABLES.md.
  6. Documentation: Findings were systematically documented in separate files (FINDINGS.md, CODE_ANALYSIS.md, VARIABLES.md) to build a cohesive understanding.
  7. Planning: An initial plan (PLAN.md) guided the analysis phases.

Note: Dynamic analysis (debugging) was not the primary focus but could be a potential next step for deeper dives. No source maps were available.

Key Findings / Architecture Overview

The static analysis revealed a complex and feature-rich application:

  • Multi-Backend API Client: Uses a factory (tO) to instantiate clients for Anthropic, AWS Bedrock (P41), and Google Vertex AI (Y91).
  • Credential Management: Implements a layered approach using environment variables, macOS Keychain (q91), and configuration files (f0), supporting API Keys and Bearer Tokens. Includes OAuth flow (PB/Zm5).
  • Tool System: Defines various tools (Bash, Edit, LS, View, Agent, etc.) with a common interface, stored in an array (sl5). Tool execution involves validation, permission checks (kj2), and specific execution logic (cc5, O61).
  • UI Layer: Employs React/Ink (createElement) for rendering the interactive terminal interface.
  • Command-Line Parsing: Uses commander.js for argument parsing and command registration.
  • Execution Flow: Supports both interactive (REPL) and non-interactive modes, branching based on CLI arguments.
  • Configuration: Reads configuration from user and project files (f0).
  • Telemetry: Includes event tracking (x1).
  • MCP Integration: Contains significant code for Model Context Protocol communication.

(See FINDINGS.md and CODE_ANALYSIS.md for more details)

Repository Structure

  • cli.js: The original or formatted minified file being analyzed.
  • PLAN.md: The initial plan and progress tracker for the analysis.
  • FINDINGS.md: High-level summary of architectural discoveries and observations.
  • VARIABLES.md: Mapping of minified variable/function names to their hypothesized purpose.
  • CODE_ANALYSIS.md: Detailed analysis of specific, important code snippets identified via grep.

Current Status

The repository documents the core architecture, tool system, API interactions, credential handling, and execution flow as understood from the minified code. Further deep dives into specific algorithms or dynamic analysis could be pursued but were outside the initial scope.

Disclaimers

  • This repository contains an analysis of the Claude Code CLI, not the original source code.
  • The analysis is based solely on the publicly distributed, minified version of cli.js. Information derived may be incomplete or contain inaccuracies due to the nature of minification.
  • This work is independent and not affiliated with, endorsed by, or sponsored by Anthropic.
  • This analysis is intended for educational and research purposes only. Users should refer to Anthropic's official documentation and adhere to their Terms of Service and licensing agreements when using the actual Claude Code CLI tool.
  • No guarantees are made about the accuracy of the analysis or the functionality of any derived code snippets.

Quick Start

1

Clone the repository

git clone https://github.com/memaxo/claude_code_re
2

Install dependencies

cd claude_code_re
npm install
3

Follow the documentation

Check the repository's README.md file for specific installation and usage instructions.

Repository Details

Ownermemaxo
Repoclaude_code_re
LanguageJavaScript
License-
Last fetched8/10/2025

Recommended MCP Servers

💬

Discord MCP

Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.

integrationsdiscordchat
🔗

Knit MCP

Connect AI agents to 200+ SaaS applications and automate workflows.

integrationsautomationsaas
🕷️

Apify MCP Server

Deploy and interact with Apify actors for web scraping and data extraction.

apifycrawlerdata
🌐

BrowserStack MCP

BrowserStack MCP Server for automated testing across multiple browsers.

testingqabrowsers

Zapier MCP

A Zapier server that provides automation capabilities for various apps.

zapierautomation