techdebt
??ッション終了時に重複コード、未使用インポート、セキュリティ問題、複雑な箇所などを検出・修正し、コード品質を向上させるためのSkill。
📜 元の英語説明(参考)
Technical debt detection and remediation. Run at session end to find duplicated code, dead imports, security issues, and complexity hotspots. Triggers: 'find tech debt', 'scan for issues', 'check code quality', 'wrap up session', 'ready to commit', 'before merge', 'code review prep'. Always uses parallel subagents for fast analysis.
🇯🇵 日本人クリエイター向け解説
??ッション終了時に重複コード、未使用インポート、セキュリティ問題、複雑な箇所などを検出・修正し、コード品質を向上させるためのSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o techdebt.zip https://jpskill.com/download/5945.zip && unzip -o techdebt.zip && rm techdebt.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/5945.zip -OutFile "$d\techdebt.zip"; Expand-Archive "$d\techdebt.zip" -DestinationPath $d -Force; ri "$d\techdebt.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
techdebt.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
techdebtフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-17
- 取得日時
- 2026-05-17
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
テクニカルデットスキャナー
並列サブエージェントを使用した、テクニカルデットの自動検出ツールです。コンテキストが新鮮なうちに問題を捕捉するため、セッション終了時に実行されるように設計されています。
クイックスタート
# セッション終了時 - 最後のコミットからの変更をスキャン(デフォルト)
/techdebt
# ディープスキャン - コードベース全体を分析
/techdebt --deep
# 特定のカテゴリ
/techdebt --duplicates # 重複のみ
/techdebt --security # セキュリティ問題のみ
/techdebt --complexity # 複雑度の高い箇所のみ
/techdebt --deadcode # デッドコードのみ
# 自動修正モード(インタラクティブ)
/techdebt --fix
アーキテクチャ
高速な分析のために、常に並列サブエージェントを使用します。
メインエージェント(オーケストレーター)
│
├─> サブエージェント 1: 重複スキャナー
├─> サブエージェント 2: セキュリティスキャナー
├─> サブエージェント 3: 複雑度スキャナー
└─> サブエージェント 4: デッドコードスキャナー
↓ すべて並列で実行(スコープに応じて 2~15 秒)
メインエージェント: 検出結果を統合 → 重大度でランク付け → レポート生成
利点:
- 🚀 並列実行 - すべてのスキャンが同時に実行されます
- 🧹 クリーンなメインコンテキスト - 分析作業による汚染がありません
- 💪 スケーラブル - 大規模なコードベースを効率的に処理します
- 🎯 高速 - 小さな差分でも並列化の恩恵を受けます
ワークフロー
ステップ 1: スコープの決定
デフォルト(フラグなし):
- 最後のコミット以降に変更されたファイルをスキャンします:
git diff --name-only HEAD - 高速なセッション終了ワークフロー(約 2~3 秒)
- 「まとめ」のシナリオに最適です
ディープスキャン(--deep フラグ):
- コードベース全体をスキャンします
- 包括的な分析(中規模プロジェクトで約 10~15 秒)
- リファクタリング時や主要なリリース準備時に使用します
特定のカテゴリ(例: --duplicates):
- 指定されたスキャナーのみを実行します
- ターゲットを絞った分析に最も高速なオプションです
ステップ 2: 並列サブエージェントの起動
4 つのサブエージェントを同時に起動します(カテゴリが指定されている場合はそのサブセット)。
サブエージェント 1: 重複スキャナー
- タスク: AST の類似性を使用して重複するコードブロックを検出します
- ツール:
ast-grep、構造検索、トークン分析 - 出力: 類似度スコア付きの重複コードブロックのリスト
サブエージェント 2: セキュリティスキャナー
- タスク: セキュリティの脆弱性とアンチパターンを検出します
- チェック: ハードコードされたシークレット、SQL インジェクション、XSS、安全でない暗号化
- 出力: 重大度と修正ガイダンス付きのセキュリティ検出結果
サブエージェント 3: 複雑度スキャナー
- タスク: 過度に複雑な関数とメソッドを特定します
- メトリクス: サイクロマティック複雑度、ネストの深さ、関数長
- 出力: リファクタリングの提案付きの複雑度の高い箇所
サブエージェント 4: デッドコードスキャナー
- タスク: 未使用のインポート、変数、到達不能なコードを検出します
- チェック: 未使用のインポート、デッドブランチ、孤立した関数
- 出力: 安全な削除手順付きのデッドコードリスト
サブエージェント指示テンプレート:
{scope} をスキャンして {category} の問題を検出します。
スコープ: {file_list または "entire codebase"}
言語: {ファイル拡張子から検出}
フォーカス: {カテゴリ固有のパターン}
出力形式:
- ファイルパス + 行番号
- 問題の説明
- 重大度 (P0-P3)
- 提案される修正 (利用可能な場合)
適切なツールを使用します:
- 重複: ast-grep による構造的類似性
- セキュリティ: パターンマッチング + 既知の脆弱性パターン
- 複雑度: サイクロマティック複雑度計算
- デッドコード: 未使用シンボルの静的分析
ステップ 3: 検出結果の統合
メインエージェントはすべてのサブエージェントから結果を収集し、次の処理を行います。
- 重複排除 - カテゴリ間の重複する検出結果を削除します
- 重大度によるランク付け:
- P0 (クリティカル): セキュリティの脆弱性、ブロッキング問題
- P1 (高): 主要な重複、高い複雑度
- P2 (中): 軽微な重複、中程度の複雑度
- P3 (低): デッドコード、スタイル問題
- ファイルごとのグループ化 - 影響を受けるファイルごとに検出結果を整理します
- デットスコアの計算 - 全体的なテクニカルデットのメトリクス
ステップ 4: レポートの生成
実用的なレポートを生成します。
# テクニカルデットレポート
**スコープ:** {X files changed | Entire codebase}
**スキャン時間:** {duration}
**デットスコア:** {0-100, lower is better}
## 概要
| カテゴリ | 検出数 | P0 | P1 | P2 | P3 |
|----------|----------|----|----|----|----|
| 重複 | X | - | X | X | - |
| セキュリティ | X | X | - | - | - |
| 複雑度 | X | - | X | X | - |
| デッドコード | X | - | - | X | X |
## クリティカルな問題 (P0)
### {file_path}:{line}
**カテゴリ:** {Security}
**問題:** ハードコードされた API キーが検出されました
**影響:** 認証情報の漏洩リスク
**修正:** 環境変数に移動する
## 高優先度 (P1)
### {file_path}:{line}
**カテゴリ:** {Duplication}
**問題:** 45 行のブロックが 3 つのファイルに重複しています
**影響:** メンテナンスの負担、不整合のリスク
**修正:** 共有ユーティリティ関数として抽出する
[... すべての検出結果について続きます ...]
## 推奨事項
1. マージする前にすべての P0 の問題に対処してください
2. 複雑度の高い関数のリファクタリングを検討してください
3. メンテナンスの負担を軽減するためにデッドコードを削除してください
## 自動修正が利用可能です
`/techdebt --fix` を実行して、安全な自動修正を対話的に適用します。
ステップ 5: 自動修正モード(オプション)
--fix フラグが指定されている場合:
-
安全な修正を特定:
- デッドインポートの削除(安全)
- 単純な重複の抽出(レビューが必要)
- フォーマットの修正(安全)
-
対話型プロンプト:
修正: utils.py:5 から未使用のインポート 'requests' を削除します [Y]es / [N]o / [A]ll / [Q]uit -
変更を適用:
- 確認された修正でファイルを編集します
- 変更の git diff を表示します
- コミットを促します
安全ルール:
- セキュリティの問題は決して自動修正しません(手動レビューが必要です)
- 複雑度の問題は決して自動修正しません(設計上の決定が必要です)
- 明示的なユーザー確認がある場合のみ自動修正します
検出パターン
重複
AST 類似性検出:
- 構造パターンマッチングに
ast-grepを使用します - 80%以上の構造的類似性を持つコードブロックを検出します
- 些細な違い(変数名、空白)は無視します
トークンベース分析:
- トークンシーケンスを比較して正確な重複を検出します
- 最小しきい値: 6 行連続
- ファイル間で類似する重複をグループ化します
しきい値:
- P1: 30 行以上が 3 箇所以上で重複
- P2: 15 行以上が 2 箇所以上で重複
- P3: 6 行以上
(原文がここで切り詰められています)
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Tech Debt Scanner
Automated technical debt detection using parallel subagents. Designed to run at session end to catch issues while context is fresh.
Quick Start
# Session end - scan changes since last commit (default)
/techdebt
# Deep scan - analyze entire codebase
/techdebt --deep
# Specific categories
/techdebt --duplicates # Only duplication
/techdebt --security # Only security issues
/techdebt --complexity # Only complexity hotspots
/techdebt --deadcode # Only dead code
# Auto-fix mode (interactive)
/techdebt --fix
Architecture
Always uses parallel subagents for fast analysis:
Main Agent (orchestrator)
│
├─> Subagent 1: Duplication Scanner
├─> Subagent 2: Security Scanner
├─> Subagent 3: Complexity Scanner
└─> Subagent 4: Dead Code Scanner
↓ All run in parallel (2-15s depending on scope)
Main Agent: Consolidate findings → Rank by severity → Generate report
Benefits:
- 🚀 Parallel execution - all scans run simultaneously
- 🧹 Clean main context - no pollution from analysis work
- 💪 Scalable - handles large codebases efficiently
- 🎯 Fast - even small diffs benefit from parallelization
Workflow
Step 1: Determine Scope
Default (no flags):
- Scan files changed since last commit:
git diff --name-only HEAD - Fast session-end workflow (~2-3 seconds)
- Perfect for "wrap up" scenarios
Deep scan (--deep flag):
- Scan entire codebase
- Comprehensive analysis (~10-15 seconds for medium projects)
- Use when refactoring or preparing major releases
Specific category (e.g., --duplicates):
- Run only specified scanner
- Fastest option for targeted analysis
Step 2: Spawn Parallel Subagents
Launch 4 subagents simultaneously (or subset if category specified):
Subagent 1: Duplication Scanner
- Task: Find duplicated code blocks using AST similarity
- Tools:
ast-grep, structural search, token analysis - Output: List of duplicate code blocks with similarity scores
Subagent 2: Security Scanner
- Task: Detect security vulnerabilities and anti-patterns
- Checks: Hardcoded secrets, SQL injection, XSS, insecure crypto
- Output: Security findings with severity and remediation guidance
Subagent 3: Complexity Scanner
- Task: Identify overly complex functions and methods
- Metrics: Cyclomatic complexity, nested depth, function length
- Output: Complexity hotspots with refactoring suggestions
Subagent 4: Dead Code Scanner
- Task: Find unused imports, variables, and unreachable code
- Checks: Unused imports, dead branches, orphaned functions
- Output: Dead code list with safe removal instructions
Subagent instructions template:
Scan {scope} for {category} issues.
Scope: {file_list or "entire codebase"}
Language: {detected from file extensions}
Focus: {category-specific patterns}
Output format:
- File path + line number
- Issue description
- Severity (P0-P3)
- Suggested fix (if available)
Use appropriate tools:
- Duplication: ast-grep for structural similarity
- Security: pattern matching + known vulnerability patterns
- Complexity: cyclomatic complexity calculation
- Dead Code: static analysis for unused symbols
Step 3: Consolidate Findings
Main agent collects results from all subagents and:
- Deduplicate - Remove duplicate findings across categories
- Rank by severity:
- P0 (Critical): Security vulnerabilities, blocking issues
- P1 (High): Major duplication, high complexity
- P2 (Medium): Minor duplication, moderate complexity
- P3 (Low): Dead code, style issues
- Group by file - Organize findings by affected file
- Calculate debt score - Overall technical debt metric
Step 4: Generate Report
Create actionable report with:
# Tech Debt Report
**Scope:** {X files changed | Entire codebase}
**Scan Time:** {duration}
**Debt Score:** {0-100, lower is better}
## Summary
| Category | Findings | P0 | P1 | P2 | P3 |
|----------|----------|----|----|----|----|
| Duplication | X | - | X | X | - |
| Security | X | X | - | - | - |
| Complexity | X | - | X | X | - |
| Dead Code | X | - | - | X | X |
## Critical Issues (P0)
### {file_path}:{line}
**Category:** {Security}
**Issue:** Hardcoded API key detected
**Impact:** Credential exposure risk
**Fix:** Move to environment variable
## High Priority (P1)
### {file_path}:{line}
**Category:** {Duplication}
**Issue:** 45-line block duplicated across 3 files
**Impact:** Maintenance burden, inconsistency risk
**Fix:** Extract to shared utility function
[... continue for all findings ...]
## Recommendations
1. Address all P0 issues before merge
2. Consider refactoring high-complexity functions
3. Remove dead code to reduce maintenance burden
## Auto-Fix Available
Run `/techdebt --fix` to interactively apply safe automated fixes.
Step 5: Auto-Fix Mode (Optional)
If --fix flag provided:
-
Identify safe fixes:
- Dead import removal (safe)
- Simple duplication extraction (review required)
- Formatting fixes (safe)
-
Interactive prompts:
Fix: Remove unused import 'requests' from utils.py:5 [Y]es / [N]o / [A]ll / [Q]uit -
Apply changes:
- Edit files with confirmed fixes
- Show git diff of changes
- Prompt for commit
Safety rules:
- Never auto-fix security issues (require manual review)
- Never auto-fix complexity (requires design decisions)
- Only auto-fix with explicit user confirmation
Detection Patterns
Duplication
AST Similarity Detection:
- Use
ast-grepfor structural pattern matching - Detect code blocks with >80% structural similarity
- Ignore trivial differences (variable names, whitespace)
Token-based Analysis:
- Compare token sequences for exact duplicates
- Minimum threshold: 6 consecutive lines
- Group similar duplicates across files
Thresholds:
- P1: 30+ lines duplicated in 3+ locations
- P2: 15+ lines duplicated in 2+ locations
- P3: 6+ lines duplicated in 2 locations
Security
Pattern Detection:
| Pattern | Severity | Example |
|---|---|---|
| Hardcoded secrets | P0 | API_KEY = "sk-..." |
| SQL injection risk | P0 | f"SELECT * FROM users WHERE id={user_id}" |
| Insecure crypto | P0 | hashlib.md5(), random.random() for tokens |
| Path traversal | P0 | open(user_input) without validation |
| XSS vulnerability | P0 | Unescaped user input in HTML |
| Eval/exec usage | P1 | eval(user_input) |
| Weak passwords | P2 | Hardcoded default passwords |
Language-specific checks:
- Python:
pickleusage,yaml.load()without SafeLoader - JavaScript:
eval(),innerHTMLwith user data - SQL: String concatenation in queries
Complexity
Metrics:
| Metric | P1 Threshold | P2 Threshold |
|---|---|---|
| Cyclomatic Complexity | >15 | >10 |
| Function Length | >100 lines | >50 lines |
| Nested Depth | >5 levels | >4 levels |
| Number of Parameters | >7 | >5 |
Refactoring suggestions:
- Extract method for long functions
- Introduce parameter object for many parameters
- Simplify conditionals with guard clauses
- Break up deeply nested logic
Dead Code
Detection methods:
- Unused imports (language-specific linters)
- Unreachable code (after return/break/continue)
- Unused variables (written but never read)
- Orphaned functions (never called in codebase)
Safe removal criteria:
- No external references found
- Not part of public API
- Not dynamically imported/called
Language Support
Tier 1 (Full support):
- Python:
ast-grep,radon,pylint - JavaScript/TypeScript:
ast-grep,eslint,jscpd - Go:
gocyclo,golangci-lint - Rust:
clippy,cargo-audit
Tier 2 (Basic support):
- Java, C#, Ruby, PHP: Pattern-based detection only
Language detection:
- Auto-detect from file extensions
- Use appropriate tools per language
- Fallback to universal patterns if specific tools unavailable
Integration Patterns
Session End Automation
Add to your workflow:
## Session Wrap-Up Checklist
- [ ] Run `/techdebt` to scan changes
- [ ] Address any P0 issues found
- [ ] Create tasks for P1/P2 items
- [ ] Commit clean code
Pre-Commit Hook
Create .claude/hooks/pre-commit.sh:
#!/bin/bash
# Auto-run tech debt scan before commits
echo "🔍 Scanning for tech debt..."
claude skill techdebt --quiet
if [ $? -eq 1 ]; then
echo "❌ P0 issues detected. Fix before committing."
exit 1
fi
echo "✅ No critical issues found"
CI/CD Integration
Run deep scan on pull requests:
# .github/workflows/techdebt.yml
name: Tech Debt Check
on: [pull_request]
jobs:
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run tech debt scan
run: claude skill techdebt --deep --ci
Advanced Usage
Baseline Tracking
Track debt over time:
# Initial baseline
/techdebt --deep --save-baseline
# Compare against baseline
/techdebt --compare-baseline
# Output: "Debt increased by 15% since baseline"
Baseline stored in .claude/techdebt-baseline.json:
{
"timestamp": "2026-02-03T10:00:00Z",
"commit": "a28f0fb",
"score": 42,
"findings": {
"duplication": 8,
"security": 0,
"complexity": 12,
"deadcode": 5
}
}
Custom Patterns
Add project-specific patterns in .claude/techdebt-rules.json:
{
"security": [
{
"pattern": "TODO.*security",
"severity": "P0",
"message": "Security TODO must be resolved"
}
],
"complexity": {
"cyclomatic_threshold": 12,
"function_length_threshold": 80
}
}
Report Formats
/techdebt --format=json # JSON output for tooling
/techdebt --format=markdown # Markdown report (default)
/techdebt --format=sarif # SARIF for IDE integration
Troubleshooting
Issue: Scan times out
- Solution: Use
--deeponly on smaller modules, or increase timeout - Consider: Break large codebases into smaller scan chunks
Issue: Too many false positives
- Solution: Adjust thresholds in
.claude/techdebt-rules.json - Consider: Use
--ignore-patternsflag to exclude test files
Issue: Missing dependencies (ast-grep, etc.)
- Solution: Install tools via
npm install -g @ast-grep/clior skip category - Fallback: Pattern-based detection still works without specialized tools
Best Practices
- Run at every session end - Catch debt while context is fresh
- Address P0 immediately - Don't commit critical issues
- Create tasks for P1/P2 - Track technical debt in backlog
- Use baselines for trends - Monitor debt accumulation over time
- Automate in CI/CD - Prevent debt from merging
- Educate team - Share findings, discuss refactoring strategies
References
See also:
- Anthropic's Agent Skills - Subagent patterns
- references/patterns.md - Language-specific debt patterns
- references/severity-guide.md - How to rank findings