understand
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseunderstand
understand
把「本次(AI)新生成的代码变更」变成一个可交互的审阅网页:左侧按真实项目布局列出变更文件树,右侧显示所选文件的 diff(高亮、增删与未变更代码明显区分),并在右侧边栏逐段给出相关单位需求与代码解释。
始终用中文产出解释与需求。
Turn "this batch of (AI-)generated code changes" into an interactive review webpage: the left side lists the changed file tree following the actual project structure, the right side displays the diff of the selected file (with syntax highlighting, clearly distinguishing additions/deletions from unchanged code), and the right sidebar provides related unit requirements and code explanations for each code segment.
Always generate explanations and requirements in Chinese.
何时用
When to Use
- 用户说 、"review 这次改动"、"解释下新写的代码"、"看看这次变更做了啥"。
/understand - 目标是理解 + 审阅当前工作区里尚未吃透的改动(通常是 AI 刚生成的),不是重构或修 bug。
- When the user says "/understand", "review this change", "explain the newly written code", "check what this change does"
- The goal is to understand and review changes in the current workspace that haven't been fully grasped (usually newly generated by AI), not to refactor or fix bugs.
组成
Components
skill 目录下三件套(都在 ):
~/.claude/skills/understand/- — 纯标准库生成器,两个子命令:
understand.py(解析 git diff →scan+data.json骨架)、annotations.json(合并注释 →render)。report.html - — Claude light 主题两栏页面(占位符
template.html注入数据),Prism.js 走 CDN 做语法高亮。__UNDERSTAND_PAYLOAD__ - 本文件 — 流程说明。
Three core files in the skill directory (located at ):
~/.claude/skills/understand/- — A pure standard library generator with two subcommands:
understand.py(parses git diff → generates skeleton forscan+data.json),annotations.json(merges annotations → outputsrender)report.html - — A two-column page with Claude light theme (injects data via placeholder
template.html), using Prism.js via CDN for syntax highlighting__UNDERSTAND_PAYLOAD__ - This file — Process documentation
执行流程
Execution Flow
在**用户当前工作目录(仓库内)**执行以下步骤。全程把 当作本 skill 目录的绝对路径(即本文件所在目录)。
SKILL_DIRExecute the following steps in the user's current working directory (within the repo). Treat as the absolute path to this skill directory (i.e., the directory where this file resides) throughout the process.
SKILL_DIR1. 扫描变更
1. Scan Changes
bash
python3 "$SKILL_DIR/understand.py" scan- 默认基线 = 当前分支与主分支(origin/main→main→master)的 merge-base;如用户指定范围可加 (例如只看最后一次提交用
--base <ref>)。--base HEAD~1 - 默认输出目录 (相对 CWD)。可用
.understand/改。--out <dir> - 它覆盖:已提交(base..HEAD) + 已暂存 + 未暂存 + 未跟踪新文件。
- 命令会打印 JSON:文件数、增删行数、/
data.json路径、以及annotations.json(变更文件列表)。读这个输出了解改了哪些文件。paths
bash
python3 "$SKILL_DIR/understand.py" scan- Default baseline = merge-base of the current branch and the main branch (origin/main→main→master); if the user specifies a range, add (e.g., use
--base <ref>to only view the last commit)--base HEAD~1 - Default output directory is (relative to CWD). Use
.understand/to modify it--out <dir> - It covers: committed changes (base..HEAD) + staged changes + unstaged changes + untracked new files
- The command will print JSON: number of files, lines added/deleted, paths to /
data.json, andannotations.json(list of changed files). Read this output to understand which files were modifiedpaths
2. 通读改动并撰写注释
2. Read Through Changes and Write Annotations
先把改动读懂,再落注释。建议:
- 每个变更文件(结合
Read里的 hunks 看具体增删行号),必要时读周边未改代码补足上下文。data.json - 判断每处改动对应的单位需求:优先从仓库线索找真实依据——commit message、需求文档、代码注释里写的需求编号/背景、相关 issue。找到真实需求就照写;确实找不到,就基于代码逻辑写「推测意图」并在注释里把
docs/置为inferred(前端会标成灰色「推测意图」而非「需求」,避免把猜测伪装成事实)。true
然后编辑 (scan 已生成骨架,保留其 顺序,逐个填充)。结构:
.understand/annotations.jsonfiles[].pathjson
{
"title": "本次变更的一句话主题",
"summary": "整体在做什么、为什么(2~4 句,可用 **加粗** 与 `代码`)",
"files": [
{
"path": "src/main/java/.../PwaTierInvitationService.java",
"summary": "这个文件这次改了什么、为何改(1~3 句)",
"annotations": [
{
"side": "new",
"start": 52,
"end": 53,
"requirement": "expires_at 为 timestamptz,需正确编码",
"explanation": "Vert.x PG 客户端不支持 `java.time.Instant`,改绑 `OffsetDateTime`(`atOffset(UTC)`),否则运行期报 coercion 错误。",
"inferred": false
}
]
}
]
}注释字段:
- —
side锚定新版本行号(增行/上下文),"new"锚定旧版本行号(删行)。绝大多数解释用"old"。"new" - /
start— 该段代码的行号区间(end里对应 side 的data.json/newNo;单行时oldNo可省或等于end)。行号是文件真实行号,不是 diff 里的序号。start - — 该段对应的单位需求(简短一句,作为标签展示)。可留空。
requirement - — 代码解释:讲清这段在干嘛、为什么这么写、有何风险/前提。可用
explanation和`code`。**bold** - — 需求为推测时置
inferred。true
注释密度:聚焦关键/易错/体现需求的段落(新增的核心逻辑、边界处理、并发/事务、类型坑、SQL 口径等),不必逐行;每个重要文件给 1~5 条即可。可参考项目记忆里的常见坑(如 Vert.x 、PG 数值数组、 编码)来判断哪些点值得解释。
Future.await()= ANYtimestamptzFirst understand the changes thoroughly, then write annotations. Recommendations:
- each changed file (refer to the hunks in
Readto see specific line numbers of additions/deletions), and read surrounding unchanged code if necessary to supplement contextdata.json - Determine the related unit requirement for each change: prioritize finding real evidence from repo clues — commit messages, requirement documents in , requirement IDs/background written in code comments, related issues. Write the real requirement if found; if none can be found, write an "inferred intent" based on code logic and set
docs/toinferredin the annotation (the frontend will mark it as gray "Inferred Intent" instead of "Requirement" to avoid passing guesses off as facts)true
Then edit (the scan has generated a skeleton; keep the order of and fill them one by one). Structure:
.understand/annotations.jsonfiles[].pathjson
{
"title": "One-sentence theme of this change",
"summary": "Overall what's being done and why (2~4 sentences, can use **bold** and `code`)",
"files": [
{
"path": "src/main/java/.../PwaTierInvitationService.java",
"summary": "What was changed in this file and why (1~3 sentences)",
"annotations": [
{
"side": "new",
"start": 52,
"end": 53,
"requirement": "expires_at is timestamptz, needs correct encoding",
"explanation": "Vert.x PG client does not support `java.time.Instant`, changed to bind `OffsetDateTime` (using `atOffset(UTC)`), otherwise a coercion error will occur at runtime.",
"inferred": false
}
]
}
]
}Annotation fields:
- —
sideanchors to line numbers in the new version (added lines/context),"new"anchors to line numbers in the old version (deleted lines). Most explanations use"old""new" - /
start— Line number range of the code segment (corresponding toend/newNoof the specified side inoldNo; for single lines,data.jsoncan be omitted or equal toend). Line numbers are the actual line numbers of the file, not the sequence numbers in the diffstart - — Related unit requirement for this segment (short sentence, displayed as a tag). Can be left blank
requirement - — Code explanation: clearly state what this segment does, why it's written this way, and any risks/preconditions. Can use
explanationand`code`**bold** - — Set to
inferredif the requirement is inferredtrue
Annotation density: Focus on key/error-prone/requirement-reflecting segments (new core logic, boundary handling, concurrency/transactions, type pitfalls, SQL calibers, etc.), no need to explain line by line; 1~5 annotations per important file are sufficient. Refer to common pitfalls in project memory (such as Vert.x , PG numeric arrays, encoding) to judge which points are worth explaining
Future.await()= ANYtimestamptz3. 渲染并打开
3. Render and Open
bash
python3 "$SKILL_DIR/understand.py" render
open .understand/report.html # macOS;Linux 用 xdg-openrenderdata.jsonannotations.json.understand/report.html最后用中文向用户简述:改了几个文件、核心变更是什么、有哪些值得注意的点,并给出 路径。
report.htmlbash
python3 "$SKILL_DIR/understand.py" render
open .understand/report.html # macOS; use xdg-open for Linuxrenderdata.jsonannotations.json.understand/report.htmlFinally, briefly inform the user in Chinese: how many files were changed, what the core changes are, any notable points, and provide the path to
report.html注意
Notes
- 是产物目录,建议提醒用户按需
.understand/或加git clean,别误提交。.gitignore - 若 为空(无变更),如实告知用户没有检测到改动,不要硬造。
data.json - 行号务必对齐 :
data.json里的annotations.json用文件真实行号,start/end决定用新/旧行号系。填错会导致边栏卡片锚不到代码行(不报错,但点「定位」无反应)。side - 不改动用户业务代码;本 skill 只读代码 + 写 下的产物。
.understand/
- is the output directory; it is recommended to remind the user to use
.understand/as needed or add it togit cleanto avoid accidental commits.gitignore - If is empty (no changes detected), truthfully inform the user that no changes were found, do not fabricate content
data.json - Line numbers must align with :
data.jsoninstart/enduse the actual file line numbers, andannotations.jsondetermines whether to use the new/old line number system. Incorrect entries will cause sidebar cards to fail to anchor to code lines (no error will be reported, but clicking "Locate" will have no effect)side - Do not modify the user's business code; this skill only reads code + writes outputs under
.understand/