How yuyz0112/claude-code-reverse works
1. This repository is not the Claude Code product itself; it is a reverse-engineering workspace. It has two distinct generations of analysis: the current approach in the root, and an older archived approach in v1/.
2. The main architectural boundary in the current approach is at Claude Code’s network/API layer. The repo’s cli.js.patch is meant to be applied to the installed Claude Code CLI so it intercepts the Anthropic SDK call path, specifically beta.messages.create, and records request/response traffic to log files.
3. The runtime data source is the patched Claude Code process. When Claude Code runs, it emits raw conversational logs such as messages.log-style output, which are captured into the checked-in logs/ directory for different scenarios like compaction, IDE integration, sub-agent behavior, and summarization.
4. parser.js is the first analysis stage after capture. Its role is to transform the raw API logs into structured conversation segments that are easier to inspect and compare, including identifying repeated system prompts and tool definitions.
5. visualize.html is the review layer. It is a browser-based interactive viewer that consumes parsed log data so an analyst can step through a session, inspect request/response turns, and distinguish common injected prompts from task-specific content.
6. The results/ directory is the extracted knowledge base from the runtime analysis. results/prompts/ contains the discovered prompt templates, including workflow, reminder, compaction, topic detection, and IDE-related prompts; these are the main control inputs shaping Claude Code’s behavior.
7. results/tools/ contains the analyzed tool contracts in YAML form. These define the tool boundary Claude Code exposes to the model, including filesystem, shell, search, editing, task delegation, web access, and notebook operations.
8. The architecture therefore has a clear flow: patched Claude Code runtime → raw logs in logs/ → parsing in parser.js → human inspection in visualize.html → curated prompt/tool artifacts in results/. The prompts and tools are the stable “behavioral model” extracted from the observed traffic.
9. The v1/ subtree is an older, separate pipeline based on static bundle analysis. It contains a formatted/bundled CLI reconstruction, chunked module outputs, merged chunks, and scripts for splitting, merging, beautifying, and LLM-assisted analysis of the minified codebase.
10. Inside v1/chunks/ and v1/merged-chunks/, the repository stores the intermediate and combined module artifacts used to deconstruct the original bundled CLI. This is an offline reverse-engineering workflow, distinct from the live log-based approach used in the root project.
11. The scripts in v1/scripts/ form the processing toolchain for that earlier approach: code beautification, chunk learning, chunk merging, and LLM interaction. These are analysis utilities rather than application runtime components.
12. In diagram terms, the important subsystems are: the patched Claude Code execution environment, the log-capture and parsing pipeline, the visualization front end, the extracted prompt/tool corpus, and the archived v1 static-bundle analysis pipeline. The repository’s core purpose is to turn observed model/API behavior into a structured architectural understanding of Claude Code.
Main entry points: tools Tools · scripts Analysis scripts · parser.js Parser · results Results
Components 18
Current pipeline
Live Claude Code log-capture analysis in the repository root.
- CLI patch · Patch applied to the installed Claude Code CLI to intercept Anthropic SDK traffic at beta.messages.create.
cli.js.patch - Claude Code · The patched Claude Code process being observed and instrumented.
- Raw logs · Checked-in conversational log files from scenarios like compaction, IDE integration, sub-agents, and summarization.
logs - Parser · Transforms raw API logs into structured conversation segments and identifies repeated prompts and tool definitions.
parser.js - Viewer · Browser-based interactive inspection layer for parsed session data.
visualize.html - Results · Curated behavioral knowledge extracted from runtime analysis.
results - Prompts · Discovered prompt templates that shape Claude Code behavior.
results/prompts - Tools · YAML definitions of the tool boundary exposed to the model.
results/tools - Workflow prompts · System-level workflow and reminder prompts used across sessions.
results/prompts/system-workflow.prompt.md - Behavior prompts · Task- and mode-specific prompts such as compaction, summarization, identity, topic detection, and IDE integration.
results/prompts/compact.prompt.md - FS & shell · Core filesystem and command execution tools such as read, write, edit, glob, grep, ls, and Bash.
results/tools/Bash.tool.yaml - Workflow tools · Higher-level tools for task delegation, todo tracking, and notebook operations.
results/tools/Task.tool.yaml - Web tools · External information access tools such as web search and web fetch.
results/tools/WebSearch.tool.yaml
Archived v1 pipeline
Older static bundle reverse-engineering workflow under v1/.
- v1 CLI · Archived bundled CLI reconstruction used for the earlier offline reverse-engineering workflow.
v1/cli.mjs - Chunk set · Chunked module artifacts extracted from the bundled CLI.
v1/chunks - Merged chunks · Reassembled module groups used to study major dependencies and Claude Code internals.
v1/merged-chunks - Analysis scripts · Beautify, split, merge, learn, and LLM-assisted scripts for the static-bundle workflow.
v1/scripts - Beautify · Formatting stage for the archived bundle analysis pipeline.
v1/cli.beautify.mjs
Connections 17
- CLI patch → Claude Code: patches · Injects interception into the running Claude Code CLI.
- Claude Code → Raw logs: emits · Produces raw request/response conversational traffic.
- Raw logs → Parser: feeds · Raw logs are transformed into structured conversation segments.
- Parser → Viewer: loads · Parsed sessions are inspected in the browser viewer.
- Parser → Results: extracts · Repeated prompts and tool definitions are consolidated into the curated corpus.
- Results → Prompts: contains · Prompt templates are stored as the behavioral prompt corpus.
- Results → Tools: contains · Tool contracts are stored as the analyzed tool corpus.
- Prompts → Workflow prompts: includes · Workflow and reminder prompts form a central prompt subset.
- Prompts → Behavior prompts: includes · Session- and mode-specific prompts form another prompt subset.
- Tools → FS & shell: includes · Filesystem and shell tools form the core execution boundary.
- Tools → Workflow tools: includes · Coordination and task-management tools define higher-level execution flow.
- Tools → Web tools: includes · Web access tools define the external information boundary.
- v1 CLI → Chunk set: split into · The bundled CLI was decomposed into chunk artifacts.
- Chunk set → Merged chunks: recombined as · Chunk artifacts were merged into larger module groupings.
- Analysis scripts → Chunk set: processes · Scripts split and analyze the chunk set.
- Analysis scripts → Merged chunks: refines · Scripts improve and merge the archived modules.
- Analysis scripts → Beautify: includes · Beautification is one stage in the archived analysis pipeline.