jpskill.com
🛠️ 開発・MCP コミュニティ

understand-diff

コード変更の影響範囲やリスクを、コード全体の構造を理解した上でGitの差分やPRから分析し、プルリクエストのレビューや変更内容の把握、リスク評価を効率的に行うSkill。

📜 元の英語説明(参考)

Analyze git diffs and PRs using the codebase knowledge graph to understand impact and risk. Use when: reviewing pull requests, understanding what a diff actually changes, assessing risk of a code change.

🇯🇵 日本人クリエイター向け解説

一言でいうと

コード変更の影響範囲やリスクを、コード全体の構造を理解した上でGitの差分やPRから分析し、プルリクエストのレビューや変更内容の把握、リスク評価を効率的に行うSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o understand-diff.zip https://jpskill.com/download/15513.zip && unzip -o understand-diff.zip && rm understand-diff.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/15513.zip -OutFile "$d\understand-diff.zip"; Expand-Archive "$d\understand-diff.zip" -DestinationPath $d -Force; ri "$d\understand-diff.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して understand-diff.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → understand-diff フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

/understand-diff

概要

コードベースのナレッジグラフを使用して、git の差分とプルリクエストを分析し、コード変更の真の影響とリスクを理解します。このスキルは、変更されたファイルをグラフノードにマッピングし、エッジをたどって影響を受けるコンポーネントを見つけ、レイヤーを跨ぐ懸念事項を特定し、構造化されたリスク評価を生成します。

グラフ構造リファレンス

ナレッジグラフの JSON は、次の構造を持っています。

  • project — {name, description, languages, frameworks, analyzedAt, gitCommitHash}
  • nodes[] — それぞれが {id, type, name, filePath, summary, tags[], complexity, languageNotes?} を持ちます
    • ノードタイプ: file, function, class, module, concept
    • ID: file:path, func:path:name, class:path:name
  • edges[] — それぞれが {source, target, type, direction, weight} を持ちます
    • 主要なタイプ: imports, contains, calls, depends_on
  • layers[] — それぞれが {id, name, description, nodeIds[]} を持ちます
  • tour[] — それぞれが {order, title, description, nodeIds[]} を持ちます

効率的な読み方

  1. JSON 内で関連するエントリを検索するために、完全なファイルを読み込む前に Grep を使用します
  2. 必要なセクションのみを読み込みます — グラフ全体をコンテキストにダンプしないでください
  3. ノード名とサマリーは、理解のために最も役立つフィールドです
  4. エッジはコンポーネントがどのように接続されているかを示します — 依存関係の連鎖のために imports と calls をたどります

指示

  1. .understand-anything/knowledge-graph.json が存在することを確認します。存在しない場合は、最初に /understand を実行するようにユーザーに伝えます。

  2. 変更されたファイルのリストを取得します (まだグラフを読み込まないでください):

    • コミットされていない変更があるブランチの場合: git diff --name-only
    • フィーチャーブランチの場合: git diff main...HEAD --name-only (またはベースブランチ)
    • ユーザーが PR 番号を指定した場合: その PR から差分を取得します
  3. プロジェクトメタデータのみを読み込みます — Grep または行数制限付きの Read を使用して、コンテキストのために "project" セクションのみを抽出します。

  4. 変更されたファイルのノードを検索します — 変更された各ファイルパスについて、ナレッジグラフで次のものを検索するために Grep を使用します:

    • 一致する "filePath" 値を持つノード (例: grep "changed/file/path")
    • これにより、ファイルノードと、それらのファイルで定義された関数/クラスノードが見つかります
    • 一致するすべてのノードの id 値をメモします
  5. 接続されたエッジ (1 ホップ) を検索します — 一致する各ノード ID について、エッジ内でその ID を Grep して、次のものを見つけます:

    • 変更されたノードを imports または depends on するもの (上流の呼び出し元)
    • 変更されたノードが imports または call するもの (下流の依存関係)
    • これらは「影響を受けるコンポーネント」です — 壊れる可能性のあるもの、または更新が必要なものです
  6. 影響を受けるレイヤーを特定します"layers" セクションで一致するノード ID を Grep して、どのアーキテクチャレイヤーが触れられているかを判断します。

  7. 構造化された分析を提供します:

    • 変更されたコンポーネント: 直接変更されたもの (一致するノードからのサマリー付き)
    • 影響を受けるコンポーネント: 影響を受ける可能性のあるもの (1 ホップのエッジから)
    • 影響を受けるレイヤー: どのアーキテクチャレイヤーが触れられているか、およびレイヤーを跨ぐ懸念事項
    • リスク評価: ノードの complexity 値、レイヤーを跨ぐエッジの数、および爆発半径 (影響を受けるコンポーネントの数) に基づきます
    • 注意深くレビューすべき点と潜在的な問題を提案します
  8. ダッシュボード用の差分オーバーレイを書き込みます — 分析を生成した後、変更されたコンポーネントと影響を受けるコンポーネントをダッシュボードで視覚化できるように、差分データを .understand-anything/diff-overlay.json に書き込みます。ファイルには以下が含まれます:

    {
      "version": "1.0.0",
      "baseBranch": "<使用されたベースブランチ>",
      "generatedAt": "<ISO タイムスタンプ>",
      "changedFiles": ["<変更されたファイルパスのリスト>"],
      "changedNodeIds": ["<ステップ 4 からのノード ID>"],
      "affectedNodeIds": ["<ステップ 5 からのノード ID、changedNodeIds を除く>"]
    }

    書き込み後、/understand-anything:understand-dashboard を実行して差分オーバーレイを視覚的に確認できることをユーザーに伝えます。

例 1: フィーチャーブランチの差分の分析

ユーザー: /understand-diff

エージェントは git diff main...HEAD --name-only を実行し、3 つの変更されたファイル src/auth/session.tssrc/auth/middleware.ts、および src/api/users.ts を見つけます。これらのファイルパスについてナレッジグラフを検索し、5 つの一致するノード (3 つのファイルノードと 2 つの関数ノード) を見つけます。エッジをたどると、8 つの影響を受けるコンポーネントが明らかになります: チェックアウトフロー、課金サービス、および管理パネルはすべて認証ミドルウェアに依存しています。エージェントは次のように報告します: 変更されたコンポーネント (Auth レイヤーの 3 つのファイル)、影響を受けるコンポーネント (3 つのレイヤーにわたる 8 つの上流の呼び出し元)、リスク評価 (高 -- 認証ミドルウェアの変更は 8 つの呼び出し元に影響し、複雑さスコアは 12)。diff-overlay.json を書き込み、爆発半径を視覚化するためにダッシュボードを実行することを提案します。

例 2: ターゲットを絞った変更を含む PR のレビュー

ユーザー: /understand-diff (src/services/payment.ts へのコミットされていない変更あり)

エージェントは git diff --name-only を実行し、1 つの変更されたファイルを見つけます。グラフ内で file:src/services/payment.ts を特定します (複雑さ: 14、タグ: billing, stripe, payments)。エッジトラバーサルは、2 つの上流の呼び出し元 (handleCheckoutrunMonthlyBilling) と 1 つの下流の依存関係 (stripe-client) を示しています。エージェントは次のように報告します: 変更されたコンポーネント (1 つのファイル、Services レイヤー)、影響を受けるコンポーネント (API および Jobs レイヤーの 2 つの呼び出し元)、リスク評価 (中 -- 複雑さの高いファイルですが、爆発半径は限定的)。差分オーバーレイを書き込み、変更された支払いサービスを呼び出すため、課金ジョブをテストする必要があることに注意します。

ガイドライン

  • 不要な読み込みを最小限に抑えるために、ナレッジグラフを読み込む前に、常に変更されたファイルのリストを取得します
  • より広範なアーキテクチャへの影響を示すレイヤーを跨ぐエッジに、リスク評価を集中させます
  • 複雑さの高いファイルは微妙なバグが発生しやすいため、リスク評価にノードの複雑さスコアを含めます
  • ダッシュボードで結果を視覚化できるように、分析のたびに diff-overlay.json を書き込みます
  • 変更されたファイルがグラフで見つからない場合は、ナレッジグラフが古くなっている可能性があることを警告し、再生成することを提案します
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

/understand-diff

Overview

Analyze git diffs and pull requests using the codebase knowledge graph to understand the true impact and risk of code changes. The skill maps changed files to graph nodes, follows edges to find affected components, identifies cross-layer concerns, and produces a structured risk assessment.

Graph Structure Reference

The knowledge graph JSON has this structure:

  • project — {name, description, languages, frameworks, analyzedAt, gitCommitHash}
  • nodes[] — each has {id, type, name, filePath, summary, tags[], complexity, languageNotes?}
    • Node types: file, function, class, module, concept
    • IDs: file:path, func:path:name, class:path:name
  • edges[] — each has {source, target, type, direction, weight}
    • Key types: imports, contains, calls, depends_on
  • layers[] — each has {id, name, description, nodeIds[]}
  • tour[] — each has {order, title, description, nodeIds[]}

How to Read Efficiently

  1. Use Grep to search within the JSON for relevant entries BEFORE reading the full file
  2. Only read sections you need — don't dump the entire graph into context
  3. Node names and summaries are the most useful fields for understanding
  4. Edges tell you how components connect — follow imports and calls for dependency chains

Instructions

  1. Check that .understand-anything/knowledge-graph.json exists. If not, tell the user to run /understand first.

  2. Get the changed files list (do NOT read the graph yet):

    • If on a branch with uncommitted changes: git diff --name-only
    • If on a feature branch: git diff main...HEAD --name-only (or the base branch)
    • If the user specifies a PR number: get the diff from that PR
  3. Read project metadata only — use Grep or Read with a line limit to extract just the "project" section for context.

  4. Find nodes for changed files — for each changed file path, use Grep to search the knowledge graph for:

    • Nodes with matching "filePath" values (e.g., grep "changed/file/path")
    • This finds file nodes AND function/class nodes defined in those files
    • Note the id values of all matched nodes
  5. Find connected edges (1-hop) — for each matched node ID, Grep for that ID in the edges to find:

    • What imports or depends on the changed nodes (upstream callers)
    • What the changed nodes import or call (downstream dependencies)
    • These are the "affected components" — things that might break or need updating
  6. Identify affected layers — Grep for the matched node IDs in the "layers" section to determine which architectural layers are touched.

  7. Provide structured analysis:

    • Changed Components: What was directly modified (with summaries from matched nodes)
    • Affected Components: What might be impacted (from 1-hop edges)
    • Affected Layers: Which architectural layers are touched and cross-layer concerns
    • Risk Assessment: Based on node complexity values, number of cross-layer edges, and blast radius (number of affected components)
    • Suggest what to review carefully and any potential issues
  8. Write diff overlay for dashboard — after producing the analysis, write the diff data to .understand-anything/diff-overlay.json so the dashboard can visualize changed and affected components. The file contains:

    {
      "version": "1.0.0",
      "baseBranch": "<the base branch used>",
      "generatedAt": "<ISO timestamp>",
      "changedFiles": ["<list of changed file paths>"],
      "changedNodeIds": ["<node IDs from step 4>"],
      "affectedNodeIds": ["<node IDs from step 5, excluding changedNodeIds>"]
    }

    After writing, tell the user they can run /understand-anything:understand-dashboard to see the diff overlay visually.

Examples

Example 1: Analyzing a feature branch diff

User: /understand-diff

The agent runs git diff main...HEAD --name-only and finds 3 changed files: src/auth/session.ts, src/auth/middleware.ts, and src/api/users.ts. It searches the knowledge graph for these file paths and finds 5 matching nodes (3 file nodes plus 2 function nodes). Following edges reveals 8 affected components: the checkout flow, billing service, and admin panel all depend on the auth middleware. The agent reports: Changed Components (3 files in the Auth layer), Affected Components (8 upstream callers across 3 layers), Risk Assessment (HIGH -- auth middleware change affects 8 callers, complexity score 12). It writes diff-overlay.json and suggests running the dashboard to visualize the blast radius.

Example 2: Reviewing a PR with targeted changes

User: /understand-diff (with uncommitted changes to src/services/payment.ts)

The agent runs git diff --name-only and finds 1 changed file. It locates file:src/services/payment.ts in the graph (complexity: 14, tags: billing, stripe, payments). Edge traversal shows 2 upstream callers (handleCheckout, runMonthlyBilling) and 1 downstream dependency (stripe-client). The agent reports: Changed Components (1 file, Services layer), Affected Components (2 callers in API and Jobs layers), Risk Assessment (MEDIUM -- high-complexity file but limited blast radius). It writes the diff overlay and notes that the billing job should be tested since it calls the changed payment service.

Guidelines

  • Always get the changed files list before reading the knowledge graph to minimize unnecessary reads
  • Focus the risk assessment on cross-layer edges, which indicate changes with broader architectural impact
  • Include node complexity scores in the risk assessment since high-complexity files are more likely to have subtle bugs
  • Write diff-overlay.json after every analysis so the dashboard can visualize results
  • When changed files are not found in the graph, warn that the knowledge graph may be outdated and suggest regenerating it