[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-72761":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":17,"stars7d":18,"stars30d":19,"stars90d":16,"forks30d":16,"starsTrendScore":20,"compositeScore":21,"rankGlobal":10,"rankLanguage":10,"license":10,"archived":22,"fork":22,"defaultBranch":23,"hasWiki":24,"hasPages":24,"topics":25,"createdAt":10,"pushedAt":10,"updatedAt":26,"readmeContent":27,"aiSummary":28,"trendingCount":16,"starSnapshotCount":16,"syncStatus":29,"lastSyncTime":30,"discoverSource":31},72761,"claude-code-reverse","Yuyz0112\u002Fclaude-code-reverse","Yuyz0112","A Tool to Visualize Claude Code's LLM Interactions","https:\u002F\u002Fyuyz0112.github.io\u002Fclaude-code-reverse\u002F",null,"JavaScript",2382,408,20,5,0,3,12,22,9,71.04,false,"main",true,[],"2026-06-12 04:01:07","# Claude Code Reverse Engineering: New Version (July 2025)\n\n[中文版](.\u002FREADME.zh_CN.md)\n\n**🚀 Quick Try**: Experience the reverse engineering analysis results through our interactive visualization tool at [https:\u002F\u002Fyuyz0112.github.io\u002Fclaude-code-reverse\u002Fvisualize.html](https:\u002F\u002Fyuyz0112.github.io\u002Fclaude-code-reverse\u002Fvisualize.html)\n\nWhen Anthropic released Claude Code (February 2025), I couldn't try it directly because registrations were paused due to high load. So, I implemented a solution to reverse engineer static code using LLMs, which became the first version of this repository. The code for the initial version is currently archived in the [v1](.\u002Fv1) directory.\n\n> At the time, there was another version by someone else that directly restored the source code based on sourcemaps. However, that repository was later taken down, indicating that Anthropic officially does not support this type of reverse engineering.\n\nActually, the implementation of v1 was less about reverse engineering Claude Code and more an experiment to explore the limits of \"analyzing large uglify JS code using LLMs.\"\n\nWhen we were able to actually run Claude Code, we found many simpler and more efficient ways to understand how it works. However, I recently noticed a repository gaining popularity that referenced the v1 approach (it mentioned referring to my v1 solution). Yet, a deeper look reveals that this method isn't effective for analyzing the overall architecture and design.\n\nSo, I spent a night exploring a reverse engineering approach based on **runtime behavior and API data** (hereafter referred to as v2). I also created a log visualization tool to help researchers interested in Claude Code analyze the parts they care about.\n\n- If you're interested in the implementation ideas behind v2, please read the following sections in order.\n- If you're only interested in the results of the v2 reverse engineering analysis, you can jump directly to the \"Analysis Results\" section.\n\n## Monkey Patching API Request Code\n\nAs an agent, Claude Code ultimately needs to interact with LLM APIs. Therefore, the core idea behind v2 is to ignore Claude Code's complex internal processing and instead focus only on the requests and responses that Claude Code ultimately exchanges with the LLM API in different task scenarios.\n\nIf you want to develop an agent as powerful as Claude Code, theoretically, you just need to implement your own code to construct similar API requests under the same task scenarios. This type of code is typically application code, with many different implementation methods and styles. Therefore, I believe implementing it from scratch yourself is the most reasonable approach.\n\nWhat's truly worth learning from Claude Code, however, is the content of its interactions with the LLM API, as this reflects its understanding of LLMs and agents.\n\nTo get the API data, there are many methods, but my current approach involves modifying Claude Code's installed files.\n\nFirst, locate the `cli.js` file:\n\n```shell\nwhich claude\n$PATH_TO_CLAUDE\nls -l $PATH_TO_CLAUDE\n$PATH_TO_CLAUDE -> $REAL_PATH\u002Fcli.js\n```\n\nNext, use `js-beautify` to format `cli.js`:\n\n```shell\nmv cli.js cli.bak\njs-beautify cli.bak > cli.js\n```\n\nUpon examining the formatted `cli.js` and referring to Anthropic's [TS SDK](https:\u002F\u002Fgithub.com\u002Fanthropics\u002Fanthropic-sdk-typescript), you'll find that Claude Code uses this SDK for all its requests, specifically the `beta.messages.create` method.\n\nWe just need to find the bundled TS SDK code within `cli.js` and monkey patch the `beta.messages.create` method. The TS SDK has some intricacies regarding Promise and Stream encapsulation that I won't detail here; please refer to the actual patch code in [cli.js.patch](.\u002Fcli.js.patch) for specifics.\n\nThis patch implements the following logic:\n\n1.  Create a `messages.log` file every time Claude Code starts.\n2.  Record corresponding logs whenever an API request is sent and a response is received.\n\nAfter making this modification, using Claude Code will generate these logs. Based on this, we can use Claude Code to perform various tasks and analyze the logs to understand how it works.\n\n## Log Visualization\n\nBecause each conversational request includes lengthy common prompts and tool definitions, the raw logs are difficult to read.\n\nTo accelerate the efficiency of reverse engineering analysis, v2 provides a log parsing tool, **[parser.js](.\u002Fparser.js)**, and a visualization tool, **[visualize.html](.\u002Fvisualize.html)**.\n\nAfter opening the visualization tool, you can select a recorded log file to view the entire conversation. The tool attempts to automatically identify which prompts are common prompts (injected by the program) based on their frequency and position within the conversation.\n\n## Analysis Results\n\n> This section on analysis results will be continuously updated as more task scenarios are explored.\n\nThe internal processes of Claude Code that have been reverse-engineered include:\n\n- Quota check\n- Topic detection\n- Core Agent workflow\n- Context compaction\n- IDE integration\n- Todo short-term memory management\n- Task\u002FSub Agent workflow\n- Summarize previous conversations\n\nThe analyzed prompts are recorded in the [prompts directory](.\u002Fresults\u002Fprompts\u002F), and the analyzed tool definitions are recorded in the [tools directory](.\u002Fresults\u002Ftools\u002F).\n\nPrompts and tool designs both contain many highlights and valuable details worth studying. You can read through them at your leisure.\n\n### Quota Check\n\nEach time Claude Code starts, it performs a lightweight conversation, inputting the text `quota`. This is likely used to check if the quota is sufficient; a successful request indicates enough quota.\n\nIt uses the Haiku 3.5 model.\n\n### Topic Detection\n\nWhenever a user inputs content, the LLM uses the [check-new-topic prompt](.\u002Fresults\u002Fprompts\u002Fcheck-new-topic.prompt.md) to determine if it's a new topic.\n\nIt uses the Haiku 3.5 model.\n\nIt's important to note that topic detection only considers the current conversation content, without any context. This makes it a very broad check. Currently, it seems to be used solely for updating the terminal title.\n\n### Core Agent Workflow\n\nWhen there's sufficient context, messages are continuously appended to the current context.\n\nThe core process that defines the Agent's workflow is the [system workflow prompt](.\u002Fresults\u002Fprompts\u002Fsystem-workflow.prompt.md). It contains a wealth of detail, so reading it directly is recommended.\n\nBefore and after the first user message in a context-based conversation, Claude Code also inserts the [system reminder start prompt](.\u002Fresults\u002Fprompts\u002Fsystem-reminder-start.prompt.md) and [system reminder end prompt](.\u002Fresults\u002Fprompts\u002Fsystem-reminder-end.prompt.md), respectively. The former dynamically loads information based on the current environment, while the latter checks if any short-term memories managed by the Todo tool need to be loaded.\n\nCurrently, it appears all tools are consistently loaded within the core Agent workflow.\n\nIt uses the Sonnet 4 model.\n\n### Context Compaction\n\nTriggered manually or when context becomes insufficient, this process compresses the current context into a single block of text, which then serves as the initial information for the next conversation. This effectively conserves context space.\n\nDuring compaction, the system prompt loads the [system compact prompt](.\u002Fresults\u002Fprompts\u002Fsystem-compact.prompt.md), and a [compact prompt](.\u002Fresults\u002Fprompts\u002Fcompact.prompt.md) is appended to the end of the current context, instructing the LLM to complete the compression in a specific format.\n\nIt uses the Sonnet 4 model.\n\n### IDE Integration\n\nWhen Claude Code is used within an IDE environment, it reads the paths of currently open files to provide more context for the conversation.\n\nThese file paths are then incorporated into the [IDE open file prompt](.\u002Fresults\u002Fprompts\u002Fide-opened-file.prompt.md).\n\nIn the IDE integration state, Claude Code will also register some IDE-specific tools through MCP, such as obtaining error information in the IDE, executing code, etc.\n\nYou can see in [ide-integration.log](.\u002Flogs\u002Fide-integration.log) how we guided Claude Code to use IDE tools to fix lint errors in files.\n\n### Todo Short-Term Memory Management\n\nWithin the \"Task Management\" section of the [system workflow prompt](.\u002Fresults\u002Fprompts\u002Fsystem-workflow.prompt.md), a task management method based on the `TodoWrite` tool is defined.\n\nWhen `TodoWrite` executes, it actually creates a JSON file in `~\u002F.claude\u002Ftodos\u002F` to record the Todos from the current conversation, serving as short-term memory. When a Todo is completed, the model also uses this tool to update the JSON file.\n\nAs mentioned in the Core Agent Workflow section, the system reminder end prompt dynamically loads the latest Todo list, enabling the model to keep track of its previous progress.\n\n### Task\u002FSub Agent Workflow\n\nClaude Code designed a Sub Agent system, implemented by loading the [Task Tool](.\u002Fresults\u002Ftools\u002FTask.tool.yaml), using prompts to guide the model to initiate a Sub Agent through calling this tool when specific independent tasks need to be executed.\n\nClaude Code's Sub Agent, as a specific form of Multi Agent, has its special design:\n\n1. There's always a concept of Main Agent (the object users initially interact with).\n2. When initiating a Sub Agent, it extracts the task to be processed from the main context and uses it as the initial prompt for the sub context.\n3. After the Sub Agent completes the task, it returns the final result as a tool result to the main context.\n\nThis design makes Sub Agent an effective way to optimize main context space. In some independent tasks (such as \"finding specific function implementations from the codebase\"), multiple rounds of Agent tool call\u002Fresult interactions generate a lot of context irrelevant to the final required result (such as searching irrelevant files that are excluded by the LLM after reading). Sub Agent can isolate this \"dirty context\" in the sub context, which disappears when the Sub Agent task is completed, while the main context only retains the small portion of needed results.\n\n### Summarize Previous Conversations\n\nWhen starting Claude Code, it summarizes previous conversations.\n\nCorresponds to the [Summarize prompt](.\u002Fresults\u002Fprompts\u002Fsummarize-previous-conversation.prompt.md).\n\nIt uses the Haiku 3.5 model.\n","Claude Code Reverse Engineering 是一个用于可视化分析 Claude 代码与大语言模型（LLM）交互的工具。该项目主要通过运行时行为和API数据来逆向工程，采用JavaScript实现，并提供了一个交互式可视化工具以帮助用户更直观地理解Claude代码的工作机制。核心功能包括对API请求和响应的详细记录与展示，特别适用于希望深入了解或研究Claude代码如何与LLM进行通信的研究者及开发者。此外，对于那些想要开发类似智能代理应用的人来说，此项目提供了宝贵的参考案例，展示了如何构建有效的API请求。",2,"2026-06-11 03:43:32","high_star"]