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

when-debugging-code-use-debugging-assistant

Intelligent debugging workflow that systematically identifies symptoms, performs root cause analysis, generates fixes with explanations, validates solutions, and prevents regressions through compre...

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

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

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

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

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して when-debugging-code-use-debugging-assistant.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → when-debugging-code-use-debugging-assistant フォルダができる
  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
同梱ファイル
2

📖 Skill本文(日本語訳)

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

[スキル名] when-debugging-code-use-debugging-assistant

デバッグアシスタントスキル

概要

症状を体系的に特定し、根本原因分析を実行し、説明付きの修正を生成し、ソリューションを検証し、包括的なテストを通じて回帰を防止する、インテリジェントなデバッグワークフローです。

メタデータ

  • スキルID: when-debugging-code-use-debugging-assistant
  • カテゴリ: 開発/デバッグ
  • 複雑度:
  • 必要なエージェント: coder, code-analyzer, tester
  • 前提条件: コードベース、エラーログ、テスト環境へのアクセス

トリガー条件

以下の状況に遭遇した場合に、このスキルを使用します。

  • ランタイムエラーまたは例外
  • 予期しない動作または誤った出力
  • パフォーマンスの低下またはメモリリーク
  • 競合状態またはタイミングの問題
  • 統合の失敗
  • 調査が必要なテストの失敗

5段階デバッグプロトコル (SOP)

フェーズ1: 症状の特定

目的: 問題に関する包括的な情報を収集する

エージェント: code-analyzer

アクション:

  1. エラーメッセージ、スタックトレース、ログを収集する
  2. 期待される動作と実際の動作を文書化する
  3. 再現手順を特定する
  4. 発生範囲と頻度を判断する
  5. 問題の重大度と影響を分類する

出力:

  • 完全なコンテキストを含む症状レポート
  • 再現手順 (手動または自動)
  • 環境コンテキスト (OS、ランタイムバージョン、依存関係)
  • 問題の分類 (バグ、回帰、エッジケース)

成功基準:

  • 問題が一貫して再現できること
  • すべての関連コンテキストが文書化されていること
  • 影響の範囲が明確に定義されていること

フェーズ2: 根本原因分析

目的: 実行フローをトレースし、根本的な原因を特定する

エージェント: code-analyzer + coder

アクション:

  1. エントリポイントから障害までの実行パスをトレースする
  2. 変数の状態とデータ変換を調べる
  3. 違反している可能性のある仮定を特定する
  4. 境界条件とエッジケースを確認する
  5. 問題を引き起こした可能性のある最近のコード変更をレビューする
  6. 依存関係と外部システムとの相互作用を分析する

テクニック:

  • 二分探索デバッグ (場所を絞り込む)
  • 仮説駆動型調査
  • 比較分析 (動作するコードパスと壊れたコードパス)
  • 時間分析 (いつから失敗し始めたか?)

出力:

  • 証拠付きの根本原因ステートメント
  • 影響を受けるコードの場所と行番号
  • バグが発生する理由の説明
  • 関連する問題または副作用

成功基準:

  • 障害を引き起こすメカニズムが明確に理解されていること
  • 根本原因を分離する再現可能なテストケースがあること
  • 症状から原因までの推論チェーンが文書化されていること

フェーズ3: 修正の生成

目的: 解決策のオプションを開発し、説明する

エージェント: coder

アクション:

  1. 2~3の解決策アプローチを生成する
  2. 各アプローチのトレードオフを評価する
  3. 以下の基準に基づいて最適な解決策を選択する:
    • 正確性と完全性
    • パフォーマンスへの影響
    • コードの保守性
    • 副作用のリスク
  4. 明確なコメントを付けて修正を実装する
  5. このアプローチが選択された理由を文書化する

修正パターン:

  • Null安全: Nullチェックを追加する、オプショナルチェイニングを使用する
  • 競合状態: 同期を追加する、プロミスを適切に使用する
  • メモリリーク: リスナーをクリーンアップする、循環参照を解消する
  • 型エラー: ランタイム検証を追加する、型定義を改善する
  • ロジックエラー: 条件を修正する、オフバイワンエラーを修正する

出力:

  • 説明付きで実装された修正
  • 検討された代替アプローチ
  • 文書化された潜在的な副作用
  • API変更がある場合の移行ノート

成功基準:

  • 修正が症状だけでなく根本原因に対処していること
  • コードがクリーンで保守可能であること
  • 新しい問題が導入されていないこと
  • 明確な説明が提供されていること

フェーズ4: 検証テスト

目的: 既存の機能を壊すことなく、修正が問題を解決することを確認する

エージェント: tester

アクション:

  1. 元のバグを再現するテストケースを作成する
  2. 修正前にテストが失敗することを確認する (テストの有効性を証明する)
  3. 修正を適用し、テストがパスすることを確認する
  4. 完全な回帰テストスイートを実行する
  5. 影響を受ける領域で探索的テストを実行する
  6. エッジケースと境界条件をテストする
  7. 本番環境と一致する環境で検証する

テストカバレッジ:

  • 独立したロジックの単体テスト
  • コンポーネント間の相互作用の統合テスト
  • ユーザーワークフローのエンドツーエンドテスト
  • 関連する場合のパフォーマンステスト
  • 該当する場合のセキュリティテスト

出力:

  • 修正を検証するテストケース
  • 回帰テスト結果
  • パフォーマンスベンチマーク (該当する場合)
  • テストカバレッジレポート

成功基準:

  • 元の問題が解決されていること
  • 回帰の失敗がないこと
  • テストカバレッジが増加していること
  • 修正が現実的な環境で検証されていること

フェーズ5: 回帰防止

目的: 問題が再発しないようにする

エージェント: tester + coder

アクション:

  1. テストスイートに永続的なテストケースを追加する
  2. コードコメントにバグと修正を文書化する
  3. パターンが明らかになった場合はアーキテクチャドキュメントを更新する
  4. 同様の問題を検出するための監視またはアサーションを追加する
  5. コードベースの他の場所に同様のバグが存在するかどうかを検討する
  6. 必要に応じて開発ガイドラインを更新する

ドキュメント:

  • 明らかでない修正を説明するコメントを追加する
  • CHANGELOGまたはバグ追跡システムを更新する
  • 複雑な問題のナレッジベースエントリを作成する
  • 学んだ教訓を文書化する

出力:

  • 再発を防止する自動テスト
  • 更新されたドキュメント
  • コードレビューチェックリスト項目 (該当する場合)
  • 監視/アラートの改善

成功基準:

  • 再導入された場合、テストスイートがこの問題を検出すること
  • チームのために知識が保存されていること
  • 同様のバグが防止可能であること
  • 監視が導入されていること (該当する場合)

連携プロトコル

エージェント間のコミュニケーションフロー

1. ユーザーが問題を報告 → code-analyzer (症状の特定)
2. code-analyzerの発見 → coder (根本原因分析)
3. coderの診断 → coder (修正の生成)
4. coderの修正 → tester (検証テスト)
5. testerの結果 → coder + tester (回帰防止)
6. 最終レポート → ユーザー

メモリ連携

メモリキー:

  • debug/[issue-id]/symptoms - 症状分析
  • debug/[issue-id]/root-cause - RCAの発見
  • `d
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Debugging Assistant Skill

Overview

Intelligent debugging workflow that systematically identifies symptoms, performs root cause analysis, generates fixes with explanations, validates solutions, and prevents regressions through comprehensive testing.

Metadata

  • Skill ID: when-debugging-code-use-debugging-assistant
  • Category: Development/Debugging
  • Complexity: HIGH
  • Agents Required: coder, code-analyzer, tester
  • Prerequisites: Access to codebase, error logs, test environment

Trigger Conditions

Use this skill when encountering:

  • Runtime errors or exceptions
  • Unexpected behavior or incorrect output
  • Performance degradation or memory leaks
  • Race conditions or timing issues
  • Integration failures
  • Test failures requiring investigation

5-Phase Debugging Protocol (SOP)

Phase 1: Symptom Identification

Objective: Gather comprehensive information about the issue

Agent: code-analyzer

Actions:

  1. Collect error messages, stack traces, and logs
  2. Document expected vs actual behavior
  3. Identify reproduction steps
  4. Determine scope and frequency of occurrence
  5. Classify issue severity and impact

Outputs:

  • Symptom report with complete context
  • Reproduction steps (manual or automated)
  • Environmental context (OS, runtime version, dependencies)
  • Issue classification (bug, regression, edge case)

Success Criteria:

  • Issue can be consistently reproduced
  • All relevant context is documented
  • Scope of impact is clearly defined

Phase 2: Root Cause Analysis

Objective: Trace execution flow and identify the underlying cause

Agent: code-analyzer + coder

Actions:

  1. Trace execution path from entry point to failure
  2. Examine variable states and data transformations
  3. Identify assumptions that may be violated
  4. Check boundary conditions and edge cases
  5. Review recent code changes that may have introduced the issue
  6. Analyze dependencies and external system interactions

Techniques:

  • Binary search debugging (narrow down location)
  • Hypothesis-driven investigation
  • Comparative analysis (working vs broken code paths)
  • Temporal analysis (when did it start failing?)

Outputs:

  • Root cause statement with evidence
  • Affected code locations and line numbers
  • Explanation of why the bug occurs
  • Related issues or side effects

Success Criteria:

  • Clear understanding of the mechanism causing the failure
  • Reproducible test case that isolates the root cause
  • Documented reasoning chain from symptom to cause

Phase 3: Fix Generation

Objective: Develop and explain solution options

Agent: coder

Actions:

  1. Generate 2-3 solution approaches
  2. Evaluate trade-offs for each approach
  3. Select optimal solution based on:
    • Correctness and completeness
    • Performance impact
    • Code maintainability
    • Risk of side effects
  4. Implement the fix with clear comments
  5. Document why this approach was chosen

Fix Patterns:

  • Null Safety: Add null checks, use optional chaining
  • Race Conditions: Add synchronization, use promises properly
  • Memory Leaks: Clean up listeners, break circular references
  • Type Errors: Add runtime validation, improve type definitions
  • Logic Errors: Correct conditions, fix off-by-one errors

Outputs:

  • Implemented fix with explanation
  • Alternative approaches considered
  • Potential side effects documented
  • Migration notes if API changes

Success Criteria:

  • Fix addresses root cause, not just symptoms
  • Code is clean and maintainable
  • No new issues introduced
  • Clear explanation provided

Phase 4: Validation Testing

Objective: Confirm the fix resolves the issue without breaking existing functionality

Agent: tester

Actions:

  1. Create test case that reproduces original bug
  2. Verify test fails before fix (proves test validity)
  3. Apply fix and verify test passes
  4. Run full regression test suite
  5. Perform exploratory testing in affected areas
  6. Test edge cases and boundary conditions
  7. Validate in environment matching production

Test Coverage:

  • Unit tests for isolated logic
  • Integration tests for component interactions
  • End-to-end tests for user workflows
  • Performance tests if relevant
  • Security tests if applicable

Outputs:

  • Test case that validates the fix
  • Regression test results
  • Performance benchmarks (if applicable)
  • Test coverage report

Success Criteria:

  • Original issue is resolved
  • No regression failures
  • Test coverage increased
  • Fix validated in realistic environment

Phase 5: Regression Prevention

Objective: Ensure the issue doesn't recur

Agent: tester + coder

Actions:

  1. Add permanent test case to test suite
  2. Document the bug and fix in code comments
  3. Update architecture documentation if patterns exposed
  4. Add monitoring or assertions to catch similar issues
  5. Consider if similar bugs exist elsewhere in codebase
  6. Update development guidelines if needed

Documentation:

  • Add comments explaining non-obvious fixes
  • Update CHANGELOG or bug tracking system
  • Create knowledge base entry for complex issues
  • Document lessons learned

Outputs:

  • Automated test preventing recurrence
  • Updated documentation
  • Code review checklist items (if applicable)
  • Monitoring/alerting improvements

Success Criteria:

  • Test suite will catch this issue if reintroduced
  • Knowledge is preserved for team
  • Similar issues are preventable
  • Monitoring is in place (if applicable)

Coordination Protocol

Agent Communication Flow

1. User reports issue → code-analyzer (Symptom Identification)
2. code-analyzer findings → coder (Root Cause Analysis)
3. coder diagnosis → coder (Fix Generation)
4. coder fix → tester (Validation Testing)
5. tester results → coder + tester (Regression Prevention)
6. Final report → User

Memory Coordination

Memory Keys:

  • debug/[issue-id]/symptoms - Symptom analysis
  • debug/[issue-id]/root-cause - RCA findings
  • debug/[issue-id]/fix - Solution implementation
  • debug/[issue-id]/validation - Test results
  • debug/[issue-id]/prevention - Long-term measures

Hooks Integration

Pre-Debug Hook:

npx claude-flow@alpha hooks pre-task --description "Debug: [issue-description]"
npx claude-flow@alpha hooks session-restore --session-id "debug-[issue-id]"

Post-Fix Hook:

npx claude-flow@alpha hooks post-edit --file "[fixed-file]" --memory-key "debug/[issue-id]/fix"
npx claude-flow@alpha hooks notify --message "Fix applied: [description]"

Session End Hook:

npx claude-flow@alpha hooks post-task --task-id "debug-[issue-id]"
npx claude-flow@alpha hooks session-end --export-metrics true

Common Debugging Scenarios

Scenario 1: Null Pointer Exception

Symptom:

TypeError: Cannot read property 'name' of undefined
  at processUser (users.js:45)

Root Cause: User object not validated before property access

Fix:

// Before
function processUser(user) {
  return user.name.toUpperCase();
}

// After
function processUser(user) {
  if (!user || !user.name) {
    throw new Error('Invalid user object');
  }
  return user.name.toUpperCase();
}

Test:

test('processUser handles missing user gracefully', () => {
  expect(() => processUser(null)).toThrow('Invalid user object');
  expect(() => processUser({})).toThrow('Invalid user object');
  expect(processUser({name: 'john'})).toBe('JOHN');
});

Scenario 2: Async Race Condition

Symptom: Intermittent test failures, data corruption in production

Root Cause: Multiple async operations modifying shared state without synchronization

Fix:

// Before - Race condition
async function updateCart(userId, item) {
  const cart = await getCart(userId);
  cart.items.push(item);
  await saveCart(userId, cart);
}

// After - Using optimistic locking
async function updateCart(userId, item) {
  let attempts = 0;
  while (attempts < 3) {
    const cart = await getCart(userId);
    const version = cart._version;
    cart.items.push(item);
    cart._version = version + 1;

    try {
      await saveCartWithVersion(userId, cart, version);
      return cart;
    } catch (error) {
      if (error.code === 'VERSION_CONFLICT') {
        attempts++;
        continue;
      }
      throw error;
    }
  }
  throw new Error('Failed to update cart after 3 attempts');
}

Test:

test('updateCart handles concurrent modifications', async () => {
  const userId = 'user123';
  await createCart(userId);

  // Simulate concurrent updates
  const updates = await Promise.all([
    updateCart(userId, {id: 'item1'}),
    updateCart(userId, {id: 'item2'}),
    updateCart(userId, {id: 'item3'})
  ]);

  const finalCart = await getCart(userId);
  expect(finalCart.items).toHaveLength(3);
  expect(finalCart._version).toBe(3);
});

Scenario 3: Memory Leak

Symptom: Application memory usage grows continuously, eventual crash

Root Cause: Event listeners not removed, causing references to remain

Fix:

// Before - Memory leak
class DataStream {
  constructor() {
    this.listeners = [];
  }

  subscribe(callback) {
    window.addEventListener('data', callback);
    this.listeners.push(callback);
  }
}

// After - Proper cleanup
class DataStream {
  constructor() {
    this.listeners = new Set();
  }

  subscribe(callback) {
    window.addEventListener('data', callback);
    this.listeners.add(callback);

    // Return unsubscribe function
    return () => {
      window.removeEventListener('data', callback);
      this.listeners.delete(callback);
    };
  }

  destroy() {
    // Clean up all listeners
    this.listeners.forEach(callback => {
      window.removeEventListener('data', callback);
    });
    this.listeners.clear();
  }
}

Test:

test('DataStream cleans up event listeners', () => {
  const stream = new DataStream();
  const callback1 = jest.fn();
  const callback2 = jest.fn();

  const unsubscribe1 = stream.subscribe(callback1);
  const unsubscribe2 = stream.subscribe(callback2);

  expect(stream.listeners.size).toBe(2);

  unsubscribe1();
  expect(stream.listeners.size).toBe(1);

  stream.destroy();
  expect(stream.listeners.size).toBe(0);
});

Best Practices

Do's

  • Always reproduce the issue before attempting fixes
  • Document your reasoning at each phase
  • Write tests before applying fixes (TDD approach)
  • Consider multiple solution approaches
  • Validate fixes in realistic environments
  • Add permanent regression tests
  • Share knowledge with the team

Don'ts

  • Don't make assumptions without verification
  • Don't fix symptoms without understanding root cause
  • Don't skip test validation
  • Don't introduce fixes that break existing functionality
  • Don't leave debugging code in production
  • Don't rush to a solution without analysis

Performance Metrics

  • Time to Root Cause: Target < 30 minutes for typical bugs
  • Fix Accuracy: Target > 95% first-attempt success rate
  • Regression Rate: Target < 2% of fixes introduce new issues
  • Test Coverage Increase: Target +5-10% coverage per debug session

Integration with Development Workflow

  1. Issue Reporting: Link to bug tracking system
  2. Version Control: Create fix branches following git-flow
  3. Code Review: All fixes require peer review
  4. CI/CD: Automated testing gates deployment
  5. Monitoring: Alert on recurrence patterns

Advanced Features

Distributed Debugging

  • Use MCP tools for coordinating multi-service debugging
  • Trace distributed transactions across microservices
  • Correlate logs from multiple systems

Proactive Debugging

  • Analyze error patterns to predict issues
  • Use static analysis to find potential bugs
  • Monitor performance metrics for anomalies

Learning System

  • Train neural patterns from successful debugging sessions
  • Build knowledge base of common issues and solutions
  • Improve diagnostic suggestions over time

Troubleshooting the Debugging Process

If debugging is not progressing:

  1. Expand scope: Issue may involve more components
  2. Narrow focus: Try isolating a smaller reproduction case
  3. Fresh perspective: Switch agents or involve another developer
  4. Rubber duck: Explain the problem step-by-step
  5. Break and return: Sometimes distance provides clarity

References

  • SPARC Methodology: Systematic problem-solving approach
  • Claude Flow Hooks: Coordination and memory management
  • Test-Driven Development: Fix validation patterns
  • Root Cause Analysis: 5 Whys, Fishbone diagrams

同梱ファイル

※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。