[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-Yuyz0112--claude-code-reverse":3,"tool-Yuyz0112--claude-code-reverse":61},[4,18,26,36,44,53],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":17},4358,"openclaw","openclaw\u002Fopenclaw","OpenClaw 是一款专为个人打造的本地化 AI 助手，旨在让你在自己的设备上拥有完全可控的智能伙伴。它打破了传统 AI 助手局限于特定网页或应用的束缚，能够直接接入你日常使用的各类通讯渠道，包括微信、WhatsApp、Telegram、Discord、iMessage 等数十种平台。无论你在哪个聊天软件中发送消息，OpenClaw 都能即时响应，甚至支持在 macOS、iOS 和 Android 设备上进行语音交互，并提供实时的画布渲染功能供你操控。\n\n这款工具主要解决了用户对数据隐私、响应速度以及“始终在线”体验的需求。通过将 AI 部署在本地，用户无需依赖云端服务即可享受快速、私密的智能辅助，真正实现了“你的数据，你做主”。其独特的技术亮点在于强大的网关架构，将控制平面与核心助手分离，确保跨平台通信的流畅性与扩展性。\n\nOpenClaw 非常适合希望构建个性化工作流的技术爱好者、开发者，以及注重隐私保护且不愿被单一生态绑定的普通用户。只要具备基础的终端操作能力（支持 macOS、Linux 及 Windows WSL2），即可通过简单的命令行引导完成部署。如果你渴望拥有一个懂你",349277,3,"2026-04-06T06:32:30",[13,14,15,16],"Agent","开发框架","图像","数据工具","ready",{"id":19,"name":20,"github_repo":21,"description_zh":22,"stars":23,"difficulty_score":10,"last_commit_at":24,"category_tags":25,"status":17},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,"2026-04-05T11:01:52",[14,15,13],{"id":27,"name":28,"github_repo":29,"description_zh":30,"stars":31,"difficulty_score":32,"last_commit_at":33,"category_tags":34,"status":17},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",148568,2,"2026-04-09T23:34:24",[14,13,35],"语言模型",{"id":37,"name":38,"github_repo":39,"description_zh":40,"stars":41,"difficulty_score":32,"last_commit_at":42,"category_tags":43,"status":17},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",108111,"2026-04-08T11:23:26",[14,15,13],{"id":45,"name":46,"github_repo":47,"description_zh":48,"stars":49,"difficulty_score":32,"last_commit_at":50,"category_tags":51,"status":17},6121,"gemini-cli","google-gemini\u002Fgemini-cli","gemini-cli 是一款由谷歌推出的开源 AI 命令行工具，它将强大的 Gemini 大模型能力直接集成到用户的终端环境中。对于习惯在命令行工作的开发者而言，它提供了一条从输入提示词到获取模型响应的最短路径，无需切换窗口即可享受智能辅助。\n\n这款工具主要解决了开发过程中频繁上下文切换的痛点，让用户能在熟悉的终端界面内直接完成代码理解、生成、调试以及自动化运维任务。无论是查询大型代码库、根据草图生成应用，还是执行复杂的 Git 操作，gemini-cli 都能通过自然语言指令高效处理。\n\n它特别适合广大软件工程师、DevOps 人员及技术研究人员使用。其核心亮点包括支持高达 100 万 token 的超长上下文窗口，具备出色的逻辑推理能力；内置 Google 搜索、文件操作及 Shell 命令执行等实用工具；更独特的是，它支持 MCP（模型上下文协议），允许用户灵活扩展自定义集成，连接如图像生成等外部能力。此外，个人谷歌账号即可享受免费的额度支持，且项目基于 Apache 2.0 协议完全开源，是提升终端工作效率的理想助手。",100752,"2026-04-10T01:20:03",[52,13,15,14],"插件",{"id":54,"name":55,"github_repo":56,"description_zh":57,"stars":58,"difficulty_score":32,"last_commit_at":59,"category_tags":60,"status":17},4721,"markitdown","microsoft\u002Fmarkitdown","MarkItDown 是一款由微软 AutoGen 团队打造的轻量级 Python 工具，专为将各类文件高效转换为 Markdown 格式而设计。它支持 PDF、Word、Excel、PPT、图片（含 OCR）、音频（含语音转录）、HTML 乃至 YouTube 链接等多种格式的解析，能够精准提取文档中的标题、列表、表格和链接等关键结构信息。\n\n在人工智能应用日益普及的今天，大语言模型（LLM）虽擅长处理文本，却难以直接读取复杂的二进制办公文档。MarkItDown 恰好解决了这一痛点，它将非结构化或半结构化的文件转化为模型“原生理解”且 Token 效率极高的 Markdown 格式，成为连接本地文件与 AI 分析 pipeline 的理想桥梁。此外，它还提供了 MCP（模型上下文协议）服务器，可无缝集成到 Claude Desktop 等 LLM 应用中。\n\n这款工具特别适合开发者、数据科学家及 AI 研究人员使用，尤其是那些需要构建文档检索增强生成（RAG）系统、进行批量文本分析或希望让 AI 助手直接“阅读”本地文件的用户。虽然生成的内容也具备一定可读性，但其核心优势在于为机器",93400,"2026-04-06T19:52:38",[52,14],{"id":62,"github_repo":63,"name":64,"description_en":65,"description_zh":66,"ai_summary_zh":67,"readme_en":68,"readme_zh":69,"quickstart_zh":70,"use_case_zh":71,"hero_image_url":72,"owner_login":73,"owner_name":74,"owner_avatar_url":75,"owner_bio":76,"owner_company":77,"owner_location":78,"owner_email":79,"owner_twitter":80,"owner_website":81,"owner_url":82,"languages":83,"stars":92,"forks":93,"last_commit_at":94,"license":78,"difficulty_score":95,"env_os":96,"env_gpu":97,"env_ram":98,"env_deps":99,"category_tags":106,"github_topics":78,"view_count":32,"oss_zip_url":78,"oss_zip_packed_at":78,"status":17,"created_at":107,"updated_at":108,"faqs":109,"releases":110},6162,"Yuyz0112\u002Fclaude-code-reverse","claude-code-reverse","A Tool to Visualize Claude Code's LLM Interactions","claude-code-reverse 是一款专为深入理解 Anthropic Claude Code 内部机制而设计的可视化工具。它不致力于还原源代码，而是通过“逆向工程”思路，聚焦于捕捉和分析 Claude Code 在运行过程中与大语言模型（LLM）API 交互的核心数据。\n\n该工具主要解决了开发者难以直接观察黑盒化 AI 代理如何构建提示词、处理上下文及规划任务流程的痛点。通过记录并可视化每一次 API 请求与响应的详细日志，用户能够清晰看到 Claude Code 在不同任务场景下的决策逻辑与思维链条，从而为构建同类高性能 AI 代理提供宝贵的参考范式。\n\nclaude-code-reverse 特别适合 AI 应用开发者、大模型研究人员以及对 Agent 架构设计感兴趣的技术人员使用。其独特的技术亮点在于采用了“运行时行为分析”策略：通过修改本地安装文件中的 SDK 代码，利用 Monkey Patching 技术拦截并记录 `beta.messages.create` 方法的调用数据。这种方式避开了复杂的源码反编译，直接提取出最具学习价值的交互内容，并配套提供了交互式网页","claude-code-reverse 是一款专为深入理解 Anthropic Claude Code 内部机制而设计的可视化工具。它不致力于还原源代码，而是通过“逆向工程”思路，聚焦于捕捉和分析 Claude Code 在运行过程中与大语言模型（LLM）API 交互的核心数据。\n\n该工具主要解决了开发者难以直接观察黑盒化 AI 代理如何构建提示词、处理上下文及规划任务流程的痛点。通过记录并可视化每一次 API 请求与响应的详细日志，用户能够清晰看到 Claude Code 在不同任务场景下的决策逻辑与思维链条，从而为构建同类高性能 AI 代理提供宝贵的参考范式。\n\nclaude-code-reverse 特别适合 AI 应用开发者、大模型研究人员以及对 Agent 架构设计感兴趣的技术人员使用。其独特的技术亮点在于采用了“运行时行为分析”策略：通过修改本地安装文件中的 SDK 代码，利用 Monkey Patching 技术拦截并记录 `beta.messages.create` 方法的调用数据。这种方式避开了复杂的源码反编译，直接提取出最具学习价值的交互内容，并配套提供了交互式网页工具，让枯燥的日志数据转化为直观的可视化图表，极大地降低了分析门槛。","# 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 反向工程：新版本（2025年7月）\n\n[英文版](.\u002FREADME.md)\n\n**🚀 快速体验**：通过我们的交互式可视化工具，体验反向工程分析结果，访问地址：[https:\u002F\u002Fyuyz0112.github.io\u002Fclaude-code-reverse\u002Fvisualize.html](https:\u002F\u002Fyuyz0112.github.io\u002Fclaude-code-reverse\u002Fvisualize.html)\n\n当 Anthropic 发布 Claude Code 时（2025年2月），由于系统负载过高，注册已被暂停，因此我未能第一时间试用。于是，我尝试利用大语言模型对静态代码进行反向工程，并将其作为本仓库的第一个版本实现。初始版本的代码目前存放在 [v1](.\u002Fv1) 目录中。\n\n> 当时，另有一位开发者基于 sourcemaps 直接还原了源代码，但该仓库后来被下架，这表明 Anthropic 官方并不支持此类反向工程行为。\n\n实际上，v1 的实现更多是出于对“使用大语言模型分析大规模 UglifyJS 代码”这一课题的探索，而非真正意义上的 Claude Code 反向工程。\n\n在我们得以实际运行 Claude Code 后，发现有许多更简单、更高效的方式来理解其工作原理。然而，最近我注意到一个引用 v1 方法的仓库逐渐流行起来（其中提到了我的 v1 解法）。但深入研究后会发现，这种方法对于分析整体架构和设计并不奏效。\n\n因此，我花了一夜时间探索了一种基于 **运行时行为与 API 数据** 的反向工程方法（以下简称 v2）。同时，我还开发了一个日志可视化工具，帮助对 Claude Code 感兴趣的研究者专注于他们关心的部分进行分析。\n\n- 如果您对 v2 的实现思路感兴趣，请按顺序阅读以下章节。\n- 如果您仅关注 v2 反向工程分析的结果，可以直接跳转到“分析结果”部分。\n\n## Monkey Patch API 请求代码\n\n作为一款代理工具，Claude Code 最终需要与 LLM API 进行交互。因此，v2 的核心思想是忽略 Claude Code 复杂的内部处理逻辑，而只关注它在不同任务场景下与 LLM API 交换的请求和响应。\n\n理论上讲，如果您希望开发出像 Claude Code 那样强大的代理，只需在相同任务场景下自行编写代码来构造类似的 API 请求即可。这类代码通常属于应用层代码，实现方式和风格多种多样。因此，我认为从头开始自己实现是最合理的选择。\n\n然而，真正值得从 Claude Code 中学习的是它与 LLM API 交互的内容——这反映了它对 LLM 和代理的理解。\n\n获取 API 数据的方法有很多，但我目前采用的方式是修改 Claude Code 的安装文件。\n\n首先，找到 `cli.js` 文件：\n\n```shell\nwhich claude\n$PATH_TO_CLAUDE\nls -l $PATH_TO_CLAUDE\n$PATH_TO_CLAUDE -> $REAL_PATH\u002Fcli.js\n```\n\n接着，使用 `js-beautify` 对 `cli.js` 进行格式化：\n\n```shell\nmv cli.js cli.bak\njs-beautify cli.bak > cli.js\n```\n\n查看格式化后的 `cli.js` 并结合 Anthropic 的 [TS SDK](https:\u002F\u002Fgithub.com\u002Fanthropics\u002Fanthropic-sdk-typescript)，可以发现 Claude Code 在所有请求中都使用了该 SDK，具体为 `beta.messages.create` 方法。\n\n我们只需在 `cli.js` 中找到打包好的 TS SDK 代码，并对 `beta.messages.create` 方法进行 monkey patch。由于 TS SDK 在 Promise 和 Stream 封装方面存在一些细节问题，此处不再赘述，具体补丁代码请参阅 [cli.js.patch](.\u002Fcli.js.patch)。\n\n该补丁实现了以下逻辑：\n\n1. 每次 Claude Code 启动时创建一个 `messages.log` 文件；\n2. 每当发送 API 请求或收到响应时，记录相应的日志。\n\n完成上述修改后，使用 Claude Code 执行各种任务时，便会生成这些日志。基于这些日志，我们可以进一步分析 Claude Code 的工作原理。\n\n## 日志可视化\n\n由于每次对话请求都包含冗长的通用提示和工具定义，原始日志难以阅读。\n\n为了提高反向工程分析的效率，v2 提供了一个日志解析工具 **[parser.js](.\u002Fparser.js)** 和一个可视化工具 **[visualize.html](.\u002Fvisualize.html)**。\n\n打开可视化工具后，您可以选择已录制的日志文件来查看整个对话过程。该工具会根据提示出现的频率和位置，自动识别哪些是程序注入的通用提示。\n\n## 分析结果\n\n> 随着更多任务场景的探索，本节的分析结果将持续更新。\n\n目前已反向工程出的 Claude Code 内部流程包括：\n\n- 配额检查\n- 主题检测\n- 核心代理工作流\n- 上下文压缩\n- IDE 集成\n- 待办事项短期记忆管理\n- 任务\u002F子代理工作流\n- 总结过往对话\n\n分析得到的提示已记录在 [prompts 目录](.\u002Fresults\u002Fprompts\u002F) 中，工具定义则记录在 [tools 目录](.\u002Fresults\u002Ftools\u002F) 中。\n\n这些提示和工具设计都蕴含着许多亮点和有价值的细节，值得仔细研读。\n\n### 配额检查\n\n每次 Claude Code 启动时，都会进行一次轻量级对话，输入文本 `quota`。这很可能用于检查配额是否充足；如果请求成功，则说明配额足够。\n\n该操作使用 Haiku 3.5 模型。\n\n### 主题检测\n\n每当用户输入内容时，LLM 会使用 [check-new-topic 提示](.\u002Fresults\u002Fprompts\u002Fcheck-new-topic.prompt.md) 来判断是否为新主题。\n\n同样使用 Haiku 3.5 模型。\n\n需要注意的是，主题检测仅考虑当前对话内容，不涉及任何上下文信息，因此判断范围非常宽泛。目前看来，这一功能似乎仅用于更新终端标题。\n\n### 核心代理工作流\n\n当上下文足够时，消息会持续追加到当前上下文中。\n\n定义代理工作流的核心流程是[系统工作流提示](.\u002Fresults\u002Fprompts\u002Fsystem-workflow.prompt.md)。该提示包含大量细节，建议直接阅读。\n\n在基于上下文的对话中，用户第一条消息前后，Claude Code 分别插入了[系统提醒开始提示](.\u002Fresults\u002Fprompts\u002Fsystem-reminder-start.prompt.md)和[系统提醒结束提示](.\u002Fresults\u002Fprompts\u002Fsystem-reminder-end.prompt.md)。前者会根据当前环境动态加载信息，而后者则会检查由 Todo 工具管理的短期记忆是否需要被加载。\n\n目前看来，所有工具都会在核心代理工作流中持续加载。\n\n它使用 Sonnet 4 模型。\n\n### 上下文压缩\n\n此过程可手动触发，或在上下文不足时自动启动。它会将当前上下文压缩成一段文本，作为下一次对话的初始信息，从而有效节省上下文空间。\n\n在压缩过程中，系统提示会加载[系统压缩提示](.\u002Fresults\u002Fprompts\u002Fsystem-compact.prompt.md)，并在当前上下文末尾附加一个[压缩提示](.\u002Fresults\u002Fprompts\u002Fcompact.prompt.md)，指导大模型以特定格式完成压缩任务。\n\n它使用 Sonnet 4 模型。\n\n### IDE 集成\n\n当 Claude Code 在 IDE 环境中使用时，它会读取当前打开文件的路径，为对话提供更多上下文信息。\n\n这些文件路径随后会被纳入[IDE 打开文件提示](.\u002Fresults\u002Fprompts\u002Fide-opened-file.prompt.md)中。\n\n在 IDE 集成状态下，Claude Code 还会通过 MCP 注册一些 IDE 特定的工具，例如获取 IDE 中的错误信息、执行代码等。\n\n您可以在 [ide-integration.log](.\u002Flogs\u002Fide-integration.log) 中看到我们如何引导 Claude Code 使用 IDE 工具来修复文件中的 lint 错误。\n\n### Todo 短期记忆管理\n\n在[系统工作流提示](.\u002Fresults\u002Fprompts\u002Fsystem-workflow.prompt.md)的“任务管理”部分，定义了一种基于 `TodoWrite` 工具的任务管理方法。\n\n当 `TodoWrite` 执行时，它实际上会在 `~\u002F.claude\u002Ftodos\u002F` 目录下创建一个 JSON 文件，用于记录当前对话中的 Todo 事项，作为短期记忆。当某个 Todo 完成后，模型也会使用该工具更新这个 JSON 文件。\n\n如核心代理工作流部分所述，系统提醒结束提示会动态加载最新的 Todo 列表，使模型能够跟踪之前的进展。\n\n### 任务\u002F子代理工作流\n\nClaude Code 设计了一个子代理系统，通过加载[任务工具](.\u002Fresults\u002Ftools\u002FTask.tool.yaml)并使用提示来引导模型，在需要执行特定独立任务时调用该工具以启动子代理。\n\nClaude Code 的子代理作为一种多代理的具体形式，具有其特殊的设计：\n\n1. 始终存在主代理的概念（即用户最初交互的对象）。\n2. 启动子代理时，它会从主上下文中提取待处理的任务，并将其作为子上下文的初始提示。\n3. 子代理完成任务后，会将最终结果作为工具结果返回到主上下文中。\n\n这种设计使得子代理成为优化主上下文空间的有效方式。在某些独立任务中（例如“从代码库中查找特定函数实现”），多轮代理工具调用与结果交互会产生大量与最终所需结果无关的上下文（如 LLM 在读取后排除的无关文件）。子代理可以将这些“脏上下文”隔离在子上下文中，随着子代理任务的完成而消失，而主上下文仅保留所需的少量结果。\n\n### 总结过往对话\n\n启动 Claude Code 时，它会总结过往对话。\n\n对应于[总结提示](.\u002Fresults\u002Fprompts\u002Fsummarize-previous-conversation.prompt.md)。\n\n它使用 Haiku 3.5 模型。","# Claude Code Reverse Engineering 快速上手指南\n\n本指南旨在帮助开发者通过运行时行为分析和 API 数据监控，深入理解 Claude Code 的内部工作机制（如 Agent 工作流、上下文压缩、子代理设计等）。\n\n## 环境准备\n\n在开始之前，请确保您的开发环境满足以下要求：\n\n*   **操作系统**: macOS 或 Linux (Windows 需使用 WSL)\n*   **Node.js**: 已安装 Node.js 运行环境 (建议 v18+)\n*   **Claude Code**: 已通过 `npm install -g @anthropic-ai\u002Fclaude-code` 或其他方式全局安装 Claude Code CLI\n*   **工具依赖**:\n    *   `js-beautify`: 用于格式化混淆后的代码\n    *   `git`: 用于克隆本项目\n\n安装前置依赖命令：\n```bash\nnpm install -g js-beautify\n```\n\n## 安装步骤\n\n1.  **克隆项目仓库**\n    获取最新的逆向工程分析工具和补丁文件。\n\n    ```bash\n    git clone https:\u002F\u002Fgithub.com\u002Fyuyz0112\u002Fclaude-code-reverse.git\n    cd claude-code-reverse\n    ```\n\n2.  **定位 Claude Code 入口文件**\n    找到全局安装的 `claude` 命令对应的真实 `cli.js` 路径。\n\n    ```bash\n    which claude\n    # 假设输出为 \u002Fusr\u002Flocal\u002Fbin\u002Fclaude，执行以下命令查看真实路径\n    ls -l $(which claude)\n    # 输出示例：\u002Fusr\u002Flocal\u002Fbin\u002Fclaude -> \u002Fusr\u002Flocal\u002Flib\u002Fnode_modules\u002F@anthropic-ai\u002Fclaude-code\u002Fcli.js\n    # 记录箭头指向的真实路径 $REAL_PATH\u002Fcli.js\n    ```\n\n3.  **备份并格式化源码**\n    为了便于阅读和打补丁，先备份原始文件，然后使用 `js-beautify` 进行格式化。\n\n    ```bash\n    # 请将 $REAL_PATH 替换为上一步获取的实际目录路径\n    cd $REAL_PATH\n    mv cli.js cli.bak\n    js-beautify cli.bak > cli.js\n    ```\n\n4.  **应用 Monkey Patch 补丁**\n    应用本项目提供的补丁，拦截并记录 LLM API 的请求与响应数据。\n\n    ```bash\n    # 返回到克隆的项目目录\n    cd \u002Fpath\u002Fto\u002Fclaude-code-reverse\n    \n    # 应用补丁 (确保路径指向刚才格式化后的 cli.js)\n    patch $REAL_PATH\u002Fcli.js \u003C cli.js.patch\n    ```\n\n## 基本使用\n\n完成上述步骤后，每次运行 `claude` 命令都会自动在当前目录生成 `messages.log` 文件，记录所有的交互数据。\n\n### 1. 运行 Claude Code 产生日志\n正常使用 Claude Code 执行任务，例如询问一个简单的代码问题：\n\n```bash\nclaude \"请解释一下这个项目的架构\"\n```\n*执行完毕后，检查当前目录下是否生成了 `messages.log`。*\n\n### 2. 可视化分析日志\n原始的 log 文件包含大量 Prompt 和工具定义，难以直接阅读。请使用项目提供的可视化工具进行分析。\n\n*   **方式 A：本地打开（推荐）**\n    直接在浏览器中打开项目中的可视化页面，并加载生成的日志文件。\n    \n    ```bash\n    # 在项目目录下直接打开 visualize.html\n    open visualize.html \n    # Windows\u002FLinux 用户请手动用浏览器打开 .\u002Fvisualize.html\n    ```\n    在页面中选择刚才生成的 `messages.log` 文件，即可看到结构化的对话流程、识别出的通用 Prompt 以及工具调用细节。\n\n*   **方式 B：在线体验**\n    如果不想本地启动，也可以访问官方托管的可视化页面（需上传本地日志文件）：\n    [https:\u002F\u002Fyuyz0112.github.io\u002Fclaude-code-reverse\u002Fvisualize.html](https:\u002F\u002Fyuyz0112.github.io\u002Fclaude-code-reverse\u002Fvisualize.html)\n\n### 3. 查看分析结果\n本项目已经预先分析并提取了核心机制的 Prompt 和工具定义，您可以直接查阅 `results` 目录：\n\n*   **核心工作流 Prompt**: `.\u002Fresults\u002Fprompts\u002Fsystem-workflow.prompt.md`\n*   **上下文压缩策略**: `.\u002Fresults\u002Fprompts\u002Fsystem-compact.prompt.md`\n*   **子代理 (Sub Agent) 设计**: `.\u002Fresults\u002Ftools\u002FTask.tool.yaml`\n*   **IDE 集成逻辑**: `.\u002Fresults\u002Fprompts\u002Fide-opened-file.prompt.md`\n\n通过分析这些文件，您可以学习 Claude Code 如何管理短期记忆 (Todo)、如何进行话题检测以及如何优化上下文窗口。","某 AI 应用团队正试图复刻 Claude Code 的智能体架构，希望理解其如何高效调度 LLM 完成复杂编码任务。\n\n### 没有 claude-code-reverse 时\n- 开发者只能面对混淆压缩后的源码束手无策，静态分析难以还原其核心逻辑，甚至可能因触碰官方红线导致项目被下架。\n- 盲目猜测智能体的提示词策略和上下文管理方式，耗费数周时间试错却无法验证猜想是否正确。\n- 缺乏可视化的交互数据，无法直观看到 Claude Code 在不同任务场景下具体发送了什么请求、接收了何种响应。\n- 参考其他不成熟的逆向方案时，发现其仅能恢复部分代码片段，对整体架构设计和 Agent 思维链的分析毫无帮助。\n\n### 使用 claude-code-reverse 后\n- 通过运行时钩子技术直接拦截并记录 `beta.messages.create` 的 API 请求与响应，绕过复杂的内部实现，直击智能体核心交互逻辑。\n- 利用内置的日志可视化工具，清晰复盘 Claude Code 在处理具体任务时的完整对话流，快速提炼其提示词工程精髓。\n- 基于真实的 API 交互数据，团队能够精准模仿其请求构造方式，从零开发出具有同等能力的自定义 Agent，而非盲目照搬代码。\n- 将分析重点从“如何破解代码”转移到“如何设计交互”，大幅缩短研发周期，避免在无效的逆向工程上浪费资源。\n\nclaude-code-reverse 的核心价值在于它将黑盒般的商业智能体转化为透明的交互数据流，让开发者能直接学习顶尖 AI 产品的“思维模式”而非纠结于代码实现。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FYuyz0112_claude-code-reverse_966d0ed0.png","Yuyz0112","yz-yu","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002FYuyz0112_80dd117c.png","Frontend\u002FAI\u002FInfra by day. OSS & video creator by night.","Arcfra",null,"aryu0112@gmail.com","Aryu0112","https:\u002F\u002Fwww.myriptide.com\u002F","https:\u002F\u002Fgithub.com\u002FYuyz0112",[84,88],{"name":85,"color":86,"percentage":87},"JavaScript","#f1e05a",99.9,{"name":89,"color":90,"percentage":91},"HTML","#e34c26",0.1,2342,403,"2026-04-10T01:13:13",4,"未说明 (需预先安装官方 Claude Code CLI，通常支持 Linux\u002FmacOS\u002FWindows)","不需要 (本工具为日志分析与可视化脚本，不涉及模型本地推理)","未说明 (取决于处理的日志文件大小，常规开发内存即可)",{"notes":100,"python":101,"dependencies":102},"本工具并非独立的 AI 模型，而是对已安装的 Anthropic 官方 'Claude Code' CLI 工具进行运行时插桩（Monkey Patching）以记录 API 交互日志。使用前必须先安装并配置好官方的 claude-code-cli。核心操作涉及修改 cli.js 文件并应用补丁，随后使用提供的 parser.js 和 visualize.html 在浏览器中分析生成的日志。无需本地 GPU 或大显存，因为实际推理请求发送至 Anthropic 云端 API。","未说明 (主要依赖 Node.js 环境运行官方 CLI，分析脚本 parser.js 通常为 Node 环境)",[103,104,105],"Node.js (运行官方 claude-code-cli)","js-beautify (用于格式化代码)","无特定 Python 库依赖",[35,13,52],"2026-03-27T02:49:30.150509","2026-04-10T15:54:21.868269",[],[]]