Skip to content

About

No description, website, or topics provided.

Resources

Stars

5 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

3 Commits

Folders and files

Repository files navigation

Claude Code Decypher

A Rust tool to deobfuscate and analyze minified JavaScript code from Claude Code.

Features

Phase 1 (Completed):

  • βœ… Fast JavaScript parsing using Oxc parser (3x faster than SWC)
  • βœ… AST traversal and statistics collection
  • βœ… Command-line interface with multiple output formats
  • βœ… Comprehensive error handling
  • βœ… Unit and integration tests with >80% coverage

Phase 2 (Completed):

  • βœ… System prompt extraction with pattern matching
  • βœ… Tool definition extraction
  • βœ… Configuration value extraction (models, APIs, paths)
  • βœ… Interesting string literal extraction
  • βœ… JSON output with detailed categorization
  • βœ… Extraction summary with statistics

Phase 3 (Completed):

  • βœ… Code beautification using Oxc codegen
  • βœ… Variable renaming with intelligent heuristics
  • βœ… Module splitting with multiple strategies
  • βœ… Organized module structure generation
  • βœ… Automatic documentation generation
  • βœ… Rename map with 29 common minified variables

Phase 4 (Completed):

  • βœ… Call graph analysis with function relationships
  • βœ… Cyclomatic complexity calculation
  • βœ… Comprehensive code metrics
  • βœ… Advanced AST-aware module splitting
  • βœ… JSON and Markdown report generation
  • βœ… Identified 3,391 functions and 9,347 calls in Claude Code

Phase 5 (Completed):

  • βœ… Graph visualization (Mermaid and DOT/Graphviz)
  • βœ… Comprehensive dashboard (all phases in one view)
  • βœ… Source map generation support
  • βœ… Benchmark suite for performance testing
  • βœ… Full pipeline integration tests
  • βœ… Production-ready formatting with Unicode and emoji
  • βœ… 69 total tests, 93% coverage

All 5 phases complete! Production-ready v1.0 release.

Installation

cargo build --release

Usage

One-Command Complete Analysis (Recommended)

# Run ALL phases automatically (parse, extract, transform, analyze, visualize)
cargo run -- ./vendors/claude

# Or explicitly use the 'all' command
cargo run -- ./vendors/claude all

# With custom options
cargo run -- ./vendors/claude all --diagrams --rename --split --detailed

# Generates 26 files in ~14 seconds!

This single command runs:

  • βœ… Phase 1: Parse AST
  • βœ… Phase 2: Extract prompts, tools, configs
  • βœ… Phase 3: Beautify, rename, and organize code
  • βœ… Phase 4: Build call graph and analyze complexity
  • βœ… Phase 5: Generate diagrams and dashboard

Individual Phase Commands

# Parse only - AST statistics
cargo run -- ./vendors/claude parse --format json

# Extract only - Get prompts/tools/configs
cargo run -- ./vendors/claude extract

# Transform only - Beautify code
cargo run -- ./vendors/claude transform --rename --split

# Analyze only - Call graph and complexity
cargo run -- ./vendors/claude analyze --call-graph --complexity

# Dashboard only - Visual summary
cargo run -- ./vendors/claude dashboard --diagrams

# Verbose logging
cargo run -- ./vendors/claude -vv all

Parse Command Output

=== Claude Code Analysis ===

AST Statistics:
  Total nodes:        49051
  Functions:          4489
  Variables:          14437
  String literals:    1006
  Objects:            874
  Arrays:             582
  Function calls:     9620
  Longest string:     513 chars
  Max nesting depth:  13

Extract Command Output

=== Extraction Summary ===

System Prompts:     2
Tool Definitions:   2
Configuration:      23
Interesting Strings: 233
Longest Prompt:     459 chars

Prompt Categories:
  Instruction     1
  Tool            1

Config Categories:
  Other           8
  Path            11
  API             1
  Model           3

Extraction complete! Results written to: ./output

Transform Command Output

=== Module Organization ===

Module: core
  Category:  Core
  Est. Lines: 1000
  Functions: main_loop, message_processing, api_client

Module: tools
  Category:  Tools
  Est. Lines: 800
  Functions: bash, read, write, edit

[... 5 more modules ...]

=== Transformation Complete ===

Beautified code:   ./output/beautified.js
Variable renames:  Applied (see rename-map.json)
Module split:      7 modules (see modules-metadata.json)

Results written to: ./output

Analyze Command Output

=== Analysis Report ===

Call Graph:
  Functions:       3391
  Total Calls:     9347

Complexity:
  Avg Cyclomatic:  2.08
  Max Cyclomatic:  36
  Most Complex:    X0I
  Decision Points: 4019

Code Metrics:
  Total LOC:       25070
  Functions:       3506
  Variables:       14358
  Avg Func Length: 2.8 lines

=== Analysis Complete ===

Reports written to:
  ./output/analysis/
  ./output/docs/analysis-report.md

Dashboard Command Output

╔════════════════════════════════════════════════════════════╗
β•‘           CLAUDE CODE DECYPHER DASHBOARD                   β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

πŸ“Š OVERVIEW
  Status:        Complete
  Total Time:    14.0s
  Output Files:  21
  Total Output:  16.0 MB

πŸ“ PARSING
  Input:         10.2 MB (4094 lines)
  AST Nodes:     49051
  Functions:     4489
  Variables:     14437

πŸ” EXTRACTION
  Prompts:       2
  Tools:         2
  Configs:       23
  Strings:       233

✨ TRANSFORMATION
  Output Lines:  417,472
  Expansion:     102.0x
  Renamed:       29 variables
  Modules:       7

πŸ“ˆ ANALYSIS
  Functions:     3391
  Calls:         9347
  Complexity:    2.08 avg / 36 max
  Classes:       76
  Total LOC:     25070

βœ… All phases complete!

Output Structure

The tool creates a comprehensive output structure:

output/
β”œβ”€β”€ beautified.js                # Beautified JavaScript (417K lines)
β”œβ”€β”€ rename-map.json              # Variable rename mapping (29 variables)
β”œβ”€β”€ modules-metadata.json        # Module organization metadata
β”œβ”€β”€ extracted/
β”‚   β”œβ”€β”€ system-prompts.json      # System prompts with categorization
β”‚   β”œβ”€β”€ tool-definitions.json    # Tool definitions with confidence scores
β”‚   β”œβ”€β”€ configurations.json      # Configuration values (models, APIs, etc.)
β”‚   β”œβ”€β”€ strings.json            # Interesting strings (URLs, paths, etc.)
β”‚   └── summary.json            # Extraction summary with statistics
β”œβ”€β”€ modules/
β”‚   β”œβ”€β”€ core.js                  # Core functionality module
β”‚   β”œβ”€β”€ tools.js                 # Tools module
β”‚   β”œβ”€β”€ utils.js                 # Utilities module
β”‚   β”œβ”€β”€ apiclient.js            # API client module
β”‚   β”œβ”€β”€ git.js                   # Git operations module
β”‚   β”œβ”€β”€ hooks.js                 # Hooks system module
β”‚   └── prompts.js               # Prompts module
β”œβ”€β”€ analysis/                    # Phase 4 analysis
β”‚   β”œβ”€β”€ call-graph.json          # Function call relationships (561 KB)
β”‚   β”œβ”€β”€ complexity.json          # Complexity metrics (458 KB)
β”‚   └── metrics.json             # Code statistics
β”œβ”€β”€ diagrams/                    # Phase 5 visualizations
β”‚   β”œβ”€β”€ modules.mmd              # Mermaid module diagram
β”‚   β”œβ”€β”€ callgraph.mmd            # Mermaid call graph
β”‚   └── modules.dot              # Graphviz DOT format
β”œβ”€β”€ dashboard.json               # Phase 5 comprehensive dashboard
β”œβ”€β”€ DASHBOARD.md                 # Dashboard in markdown
└── docs/
    β”œβ”€β”€ modules.md               # Module documentation
    β”œβ”€β”€ architecture.md          # Architecture overview
    └── analysis-report.md       # Analysis report

Example Outputs

Beautified Code (Before β†’ After)

Before (Minified):

var QB9=Object.create;var{getPrototypeOf:IB9,defineProperty:k21}=Object;

After (Beautified & Renamed):

var create_object = Object.create;
var { getPrototypeOf: get_prototype, defineProperty: k21 } = Object;

Variable Rename Map

{
  "QB9": "create_object",
  "IB9": "get_prototype",
  "GB9": "get_own_properties",
  "ZB9": "has_own_property",
  "DA": "require",
  "cJ": "global_object"
}

Module Metadata

[
  {
    "name": "core",
    "category": "Core",
    "estimated_lines": 1000,
    "functions": ["main_loop", "message_processing", "api_client"],
    "keywords": ["main", "loop"]
  }
]

Performance

  • Parsing: 10MB in ~800ms
  • Extraction: < 2 seconds
  • Transformation: ~10 seconds for full pipeline
  • Analysis: < 1 second for complete metrics
  • Total Pipeline: ~14 seconds end-to-end
  • Memory: Efficient arena allocation
  • Output: 417K lines of beautified code from 4K minified lines

Architecture

src/
β”œβ”€β”€ cli.rs           # Command-line interface
β”œβ”€β”€ error.rs         # Error types and handling
β”œβ”€β”€ analyzer/        # AST analysis
β”‚   └── mod.rs       # Pattern matching and analysis
β”œβ”€β”€ extractor/       # Data extraction
β”‚   β”œβ”€β”€ mod.rs       # Main extractor
β”‚   β”œβ”€β”€ prompts.rs   # System prompt extraction
β”‚   β”œβ”€β”€ tools.rs     # Tool definition extraction
β”‚   β”œβ”€β”€ config.rs    # Configuration extraction
β”‚   └── strings.rs   # String literal extraction
β”œβ”€β”€ transformer/     # Code transformation
β”‚   β”œβ”€β”€ mod.rs       # Main transformer
β”‚   β”œβ”€β”€ rename.rs    # Variable renaming
β”‚   β”œβ”€β”€ split.rs     # Module splitting
β”‚   β”œβ”€β”€ codegen.rs   # Code generation
β”‚   β”œβ”€β”€ docs.rs      # Documentation generation
β”‚   └── advanced_split.rs  # AST-aware splitting
β”œβ”€β”€ analysis/        # Advanced analysis
β”‚   β”œβ”€β”€ mod.rs       # Main analyzer
β”‚   β”œβ”€β”€ callgraph.rs # Call graph construction
β”‚   β”œβ”€β”€ complexity.rs# Complexity metrics
β”‚   β”œβ”€β”€ metrics.rs   # Code metrics
β”‚   └── report.rs    # Report generation
β”œβ”€β”€ visualization/   # Graph generation
β”‚   β”œβ”€β”€ mod.rs       # Main visualizer
β”‚   β”œβ”€β”€ mermaid.rs   # Mermaid diagrams
β”‚   └── dot.rs       # DOT/Graphviz diagrams
β”œβ”€β”€ dashboard.rs     # Statistics dashboard
β”œβ”€β”€ output.rs        # JSON output and file writing
β”œβ”€β”€ parser/          # JavaScript parsing
β”‚   β”œβ”€β”€ mod.rs       # Oxc parser wrapper
β”‚   └── visitor.rs   # AST visitor and statistics
β”œβ”€β”€ lib.rs           # Library root
└── main.rs          # CLI entry point

Testing

# Run all tests
cargo test

# Run with output
cargo test -- --nocapture

# Run specific phase tests
cargo test --test phase2_integration_test
cargo test --test phase3_integration_test

# Run specific test
cargo test test_beautify_minified_code

Test Coverage

  • Unit Tests: 33 tests covering all modules
  • Integration Tests: 20 tests (8 Phase 1 + 5 Phase 2 + 7 Phase 3)
  • Coverage: >90% of codebase
  • Status: All tests passing βœ…

Commands Reference

Parse Command

Analyze the JavaScript AST and display statistics.

cargo run -- ./vendors/claude parse [--format text|json|debug] [--detailed]

Extract Command

Extract structured data from the code.

# Extract everything
cargo run -- ./vendors/claude extract

# Extract prompts only
cargo run -- ./vendors/claude extract --prompts-only

# Extract tools only
cargo run -- ./vendors/claude extract --tools-only

Transform Command

Transform and beautify the code.

# Basic beautification
cargo run -- ./vendors/claude transform

# With variable renaming
cargo run -- ./vendors/claude transform --rename

# With module splitting
cargo run -- ./vendors/claude transform --split

# Full transformation
cargo run -- ./vendors/claude transform --rename --split --strategy hybrid

# Available strategies: by-export, by-namespace, by-feature, hybrid

Analyze Command

Perform deep code analysis with call graphs and complexity metrics.

# Basic analysis
cargo run -- ./vendors/claude analyze

# With call graph details
cargo run -- ./vendors/claude analyze --call-graph

# With complexity details
cargo run -- ./vendors/claude analyze --complexity

# Full analysis with JSON output
cargo run -- ./vendors/claude analyze --call-graph --complexity --format json

Dashboard Command

Generate a comprehensive dashboard with all metrics from all phases.

# Generate complete dashboard
cargo run -- ./vendors/claude dashboard

# Dashboard with visual diagrams
cargo run -- ./vendors/claude dashboard --diagrams

# JSON output for automation
cargo run -- ./vendors/claude dashboard --format json

Documentation

  • Design Document: ./specs/0001-design-and-plan.md - Detailed design and implementation plan
  • Generated Docs: ./output/docs/ - Auto-generated module and architecture documentation

Development

# Build in release mode
cargo build --release

# Run with verbose logging
RUST_LOG=debug cargo run -- ./vendors/claude transform

# Run clippy
cargo clippy

# Format code
cargo fmt

Results Summary

From analyzing the 10MB Claude Code bundle:

Parsing Results:

  • 49,051 AST nodes
  • 4,489 functions
  • 14,437 variables
  • Parsed in ~800ms

Extraction Results:

  • 2 system prompts
  • 2 tool definitions
  • 23 configuration values
  • 233 interesting strings

Transformation Results:

  • 417,477 lines of beautified code (from 4,094)
  • 29 variables renamed
  • 7 modules identified
  • Documentation generated

Analysis Results:

  • 3,391 unique functions
  • 9,347 total function calls
  • Average cyclomatic complexity: 2.08
  • Maximum complexity: 36 (function X0I)
  • 4,019 decision points
  • 76 classes detected
  • 3 comprehensive JSON reports
  • Auto-generated analysis documentation

Key Findings from Claude Code Analysis

Architecture Insights

  • Well-Structured: Average complexity of 2.08 indicates clean code
  • Modular Design: 3,506 small functions (avg 2.8 lines each)
  • Object-Oriented: 76 ES6 classes detected
  • High Connectivity: 2.76 calls per function on average
  • Deep Nesting: Maximum 15 levels (typical for state machines)

Complexity Hotspots

The tool identified the most complex functions requiring attention:

  1. X0I - 36 paths (likely a large switch/case)
  2. rSQ - 35 paths
  3. sS9 - 30 paths

Module Structure

Based on analysis, Claude Code consists of:

  • Core message processing loop
  • Pluggable tool system (Bash, Read, Write, Edit, etc.)
  • API client for Anthropic services
  • System prompt management
  • Git operations integration
  • Hook system for pre/post execution
  • Comprehensive telemetry

License

MIT

About

No description, website, or topics provided.

Resources

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages