# yuyz0112/claude-code-reverse architecture

> Architecture diagram of the GitHub repository yuyz0112/claude-code-reverse, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yuyz0112/claude-code-reverse
- Repository: https://github.com/yuyz0112/claude-code-reverse

## Overview

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: [`results/tools`](https://github.com/yuyz0112/claude-code-reverse/tree/main/results/tools) (Tools), [`v1/scripts`](https://github.com/yuyz0112/claude-code-reverse/tree/main/v1/scripts) (Analysis scripts), [`parser.js`](https://github.com/yuyz0112/claude-code-reverse/blob/main/parser.js) (Parser), [`results`](https://github.com/yuyz0112/claude-code-reverse/tree/main/results) (Results)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_current["Current pipeline"]
  node_cli_patch["CLI patch<br/>runtime hook<br/>[cli.js.patch]"]
  node_claude_runtime["Claude Code<br/>patched runtime"]
  node_logs["Raw logs<br/>captured sessions"]
  node_parser["Parser<br/>[parser.js]"]
  node_visualize["Viewer<br/>review UI<br/>[visualize.html]"]
  node_results[("Results<br/>extracted corpus")]
  node_prompts["Prompts<br/>prompt corpus"]
  node_tools["Tools<br/>tool contracts"]
  node_prompt_workflow["Workflow prompts<br/>system prompt"]
  node_prompt_behavior["Behavior prompts<br/>session prompt<br/>[compact.prompt.md]"]
  node_tool_fs_shell["FS & shell<br/>tool boundary<br/>[Bash.tool.yaml]"]
  node_tool_workflow["Workflow tools<br/>coordination tools<br/>[Task.tool.yaml]"]
  node_tool_web["Web tools<br/>network tools"]
end

subgraph group_archive["Archived v1 pipeline"]
  node_v1_cli["v1 CLI<br/>static bundle<br/>[cli.mjs]"]
  node_v1_chunks[("Chunk set<br/>module slices")]
  node_v1_merged[("Merged chunks<br/>recombined modules")]
  node_v1_scripts["Analysis scripts<br/>processing tools"]
  node_v1_beautify["Beautify<br/>code formatter<br/>[cli.beautify.mjs]"]
end

node_cli_patch -->|"patches"| node_claude_runtime
node_claude_runtime -->|"emits"| node_logs
node_logs -->|"feeds"| node_parser
node_parser -->|"loads"| node_visualize
node_parser -->|"extracts"| node_results
node_results -->|"contains"| node_prompts
node_results -->|"contains"| node_tools
node_prompts -->|"includes"| node_prompt_workflow
node_prompts -->|"includes"| node_prompt_behavior
node_tools -->|"includes"| node_tool_fs_shell
node_tools -->|"includes"| node_tool_workflow
node_tools -->|"includes"| node_tool_web
node_v1_cli -->|"split into"| node_v1_chunks
node_v1_chunks -->|"recombined as"| node_v1_merged
node_v1_scripts -->|"processes"| node_v1_chunks
node_v1_scripts -->|"refines"| node_v1_merged
node_v1_scripts -->|"includes"| node_v1_beautify

click node_cli_patch "https://github.com/yuyz0112/claude-code-reverse/blob/main/cli.js.patch"
click node_logs "https://github.com/yuyz0112/claude-code-reverse/tree/main/logs"
click node_parser "https://github.com/yuyz0112/claude-code-reverse/blob/main/parser.js"
click node_visualize "https://github.com/yuyz0112/claude-code-reverse/blob/main/visualize.html"
click node_results "https://github.com/yuyz0112/claude-code-reverse/tree/main/results"
click node_prompts "https://github.com/yuyz0112/claude-code-reverse/tree/main/results/prompts"
click node_tools "https://github.com/yuyz0112/claude-code-reverse/tree/main/results/tools"
click node_prompt_workflow "https://github.com/yuyz0112/claude-code-reverse/blob/main/results/prompts/system-workflow.prompt.md"
click node_prompt_behavior "https://github.com/yuyz0112/claude-code-reverse/blob/main/results/prompts/compact.prompt.md"
click node_tool_fs_shell "https://github.com/yuyz0112/claude-code-reverse/blob/main/results/tools/Bash.tool.yaml"
click node_tool_workflow "https://github.com/yuyz0112/claude-code-reverse/blob/main/results/tools/Task.tool.yaml"
click node_tool_web "https://github.com/yuyz0112/claude-code-reverse/blob/main/results/tools/WebSearch.tool.yaml"
click node_v1_cli "https://github.com/yuyz0112/claude-code-reverse/blob/main/v1/cli.mjs"
click node_v1_chunks "https://github.com/yuyz0112/claude-code-reverse/tree/main/v1/chunks"
click node_v1_merged "https://github.com/yuyz0112/claude-code-reverse/tree/main/v1/merged-chunks"
click node_v1_scripts "https://github.com/yuyz0112/claude-code-reverse/tree/main/v1/scripts"
click node_v1_beautify "https://github.com/yuyz0112/claude-code-reverse/blob/main/v1/cli.beautify.mjs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli_patch,node_claude_runtime,node_logs,node_parser,node_visualize,node_results,node_prompts,node_tools,node_prompt_workflow,node_prompt_behavior,node_tool_fs_shell,node_tool_workflow,node_tool_web toneBlue
class node_v1_cli,node_v1_chunks,node_v1_merged,node_v1_scripts,node_v1_beautify toneAmber
```

## Components

### Current pipeline

Live Claude Code log-capture analysis in the repository root.

- [CLI patch](https://github.com/yuyz0112/claude-code-reverse/blob/main/cli.js.patch): runtime hook · Patch applied to the installed Claude Code CLI to intercept Anthropic SDK traffic at beta.messages.create. · `cli.js.patch`
- **Claude Code**: patched runtime · The patched Claude Code process being observed and instrumented.
- [Raw logs](https://github.com/yuyz0112/claude-code-reverse/tree/main/logs): captured sessions · Checked-in conversational log files from scenarios like compaction, IDE integration, sub-agents, and summarization. · `logs`
- [Parser](https://github.com/yuyz0112/claude-code-reverse/blob/main/parser.js): log parser · Transforms raw API logs into structured conversation segments and identifies repeated prompts and tool definitions. · `parser.js`
- [Viewer](https://github.com/yuyz0112/claude-code-reverse/blob/main/visualize.html): review UI · Browser-based interactive inspection layer for parsed session data. · `visualize.html`
- [Results](https://github.com/yuyz0112/claude-code-reverse/tree/main/results): extracted corpus · Curated behavioral knowledge extracted from runtime analysis. · `results`
- [Prompts](https://github.com/yuyz0112/claude-code-reverse/tree/main/results/prompts): prompt corpus · Discovered prompt templates that shape Claude Code behavior. · `results/prompts`
- [Tools](https://github.com/yuyz0112/claude-code-reverse/tree/main/results/tools): tool contracts · YAML definitions of the tool boundary exposed to the model. · `results/tools`
- [Workflow prompts](https://github.com/yuyz0112/claude-code-reverse/blob/main/results/prompts/system-workflow.prompt.md): system prompt · System-level workflow and reminder prompts used across sessions. · `results/prompts/system-workflow.prompt.md`
- [Behavior prompts](https://github.com/yuyz0112/claude-code-reverse/blob/main/results/prompts/compact.prompt.md): session prompt · Task- and mode-specific prompts such as compaction, summarization, identity, topic detection, and IDE integration. · `results/prompts/compact.prompt.md`
- [FS & shell](https://github.com/yuyz0112/claude-code-reverse/blob/main/results/tools/Bash.tool.yaml): tool boundary · Core filesystem and command execution tools such as read, write, edit, glob, grep, ls, and Bash. · `results/tools/Bash.tool.yaml`
- [Workflow tools](https://github.com/yuyz0112/claude-code-reverse/blob/main/results/tools/Task.tool.yaml): coordination tools · Higher-level tools for task delegation, todo tracking, and notebook operations. · `results/tools/Task.tool.yaml`
- [Web tools](https://github.com/yuyz0112/claude-code-reverse/blob/main/results/tools/WebSearch.tool.yaml): network 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](https://github.com/yuyz0112/claude-code-reverse/blob/main/v1/cli.mjs): static bundle · Archived bundled CLI reconstruction used for the earlier offline reverse-engineering workflow. · `v1/cli.mjs`
- [Chunk set](https://github.com/yuyz0112/claude-code-reverse/tree/main/v1/chunks): module slices · Chunked module artifacts extracted from the bundled CLI. · `v1/chunks`
- [Merged chunks](https://github.com/yuyz0112/claude-code-reverse/tree/main/v1/merged-chunks): recombined modules · Reassembled module groups used to study major dependencies and Claude Code internals. · `v1/merged-chunks`
- [Analysis scripts](https://github.com/yuyz0112/claude-code-reverse/tree/main/v1/scripts): processing tools · Beautify, split, merge, learn, and LLM-assisted scripts for the static-bundle workflow. · `v1/scripts`
- [Beautify](https://github.com/yuyz0112/claude-code-reverse/blob/main/v1/cli.beautify.mjs): code formatter · Formatting stage for the archived bundle analysis pipeline. · `v1/cli.beautify.mjs`

## Connections

- 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.
