jpskill.com
🛠️ 開発・MCP コミュニティ 🔴 エンジニア向け 👤 エンジニア・AI開発者

🛠️ TDDWorkflowsTDDリファクタリング

tdd-workflows-tdd-refactor

テスト駆動開発(TDD)のワークフローにおいて、リファクタリングを効率的に進めるためのSkill。

⏱ ボイラープレート実装 半日 → 30分

📺 まず動画で見る(YouTube)

▶ 【衝撃】最強のAIエージェント「Claude Code」の最新機能・使い方・プログラミングをAIで効率化する超実践術を解説! ↗

※ jpskill.com 編集部が参考用に選んだ動画です。動画の内容と Skill の挙動は厳密には一致しないことがあります。

📜 元の英語説明(参考)

Use when working with tdd workflows tdd refactor

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

一言でいうと

テスト駆動開発(TDD)のワークフローにおいて、リファクタリングを効率的に進めるためのSkill。

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

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

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

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

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

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して tdd-workflows-tdd-refactor.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → tdd-workflows-tdd-refactor フォルダができる
  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-17
取得日時
2026-05-17
同梱ファイル
1

💬 こう話しかけるだけ — サンプルプロンプト

  • Tdd Workflows Tdd Refactor を使って、最小構成のサンプルコードを示して
  • Tdd Workflows Tdd Refactor の主な使い方と注意点を教えて
  • Tdd Workflows Tdd Refactor を既存プロジェクトに組み込む方法を教えて

これをClaude Code に貼るだけで、このSkillが自動発動します。

📖 Skill本文(日本語訳)

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

[スキル名] tdd-workflows-tdd-refactor

このスキルを使用する場面

  • tdd-workflows-tdd-refactor のタスクやワークフローに取り組む場合
  • tdd-workflows-tdd-refactor に関するガイダンス、ベストプラクティス、またはチェックリストが必要な場合

このスキルを使用しない場面

  • タスクが tdd-workflows-tdd-refactor に関連しない場合
  • この範囲外の異なるドメインやツールが必要な場合

指示

  • 目標、制約、および必要な入力を明確にしてください。
  • 関連するベストプラクティスを適用し、結果を検証してください。
  • 実用的な手順と検証を提供してください。
  • 詳細な例が必要な場合は、resources/implementation-playbook.md を開いてください。

包括的なテストセーフティネットを使用して、自信を持ってコードをリファクタリングしてください。

[拡張思考: このツールは、tdd-orchestrator エージェント (opus モデル) を使用して、すべてのテストをグリーンに保ちながら高度なリファクタリングを実行します。包括的なテストカバレッジの安全性のもと、デザインパターンを適用し、コード品質を向上させ、パフォーマンスを最適化します。]

使用方法

サブエージェントタイプを "tdd-orchestrator" に設定した Task ツールを使用して、安全なリファクタリングを実行してください。

プロンプト: "すべてのテストをグリーンに保ちながら、このコードをリファクタリングしてください: $ARGUMENTS。TDD リファクタリングフェーズを適用してください:

コアプロセス

1. 事前評価

  • テストを実行してグリーンのベースラインを確立する
  • コードの臭いとテストカバレッジを分析する
  • 現在のパフォーマンスメトリクスを文書化する
  • 段階的なリファクタリング計画を作成する

2. コードの臭いの検出

  • 重複コード → メソッド/クラスを抽出する
  • 長いメソッド → 焦点を絞った関数に分解する
  • 大きなクラス → 責任を分割する
  • 長いパラメータリスト → パラメータオブジェクト
  • Feature Envy → 適切なクラスにメソッドを移動する
  • Primitive Obsession → 値オブジェクト
  • Switch ステートメント → ポリモーフィズム
  • デッドコード → 削除する

3. デザインパターン

  • 生成 (Factory, Builder, Singleton) を適用する
  • 構造 (Adapter, Facade, Decorator) を適用する
  • 振る舞い (Strategy, Observer, Command) を適用する
  • ドメイン (Repository, Service, Value Objects) を適用する
  • 明確な価値を追加する場合にのみパターンを使用する

4. SOLID 原則

  • 単一責任: 変更の理由が一つであること
  • 開放/閉鎖: 拡張に対して開かれ、変更に対して閉じられていること
  • リスコフの置換: サブタイプが置換可能であること
  • インターフェース分離: 小さく、焦点を絞ったインターフェースであること
  • 依存性逆転: 抽象に依存すること

5. リファクタリング手法

  • メソッド/変数/インターフェースの抽出
  • 不要な間接参照のインライン化
  • 明確さのための名前変更
  • メソッド/フィールドを適切なクラスに移動
  • マジックナンバーを定数に置き換える
  • フィールドのカプセル化
  • 条件分岐をポリモーフィズムに置き換える
  • Null Object の導入

6. パフォーマンス最適化

  • プロファイリングでボトルネックを特定する
  • アルゴリズムとデータ構造を最適化する
  • 有益な場合にキャッシュを実装する
  • データベースクエリを削減する (N+1 問題の解消)
  • 遅延ロードとページネーション
  • 常に前後で測定する

7. 段階的な手順

  • 小さく、アトミックな変更を行う
  • 各変更後にテストを実行する
  • 各リファクタリングの成功後にコミットする
  • リファクタリングと振る舞いの変更を分離する
  • 必要に応じて足場を使用する

8. アーキテクチャの進化

  • レイヤー分離と依存関係管理
  • モジュール境界とインターフェース定義
  • デカップリングのためのイベント駆動型パターン
  • データベースアクセスパターンの最適化

9. 安全性検証

  • 各変更後に完全なテストスイートを実行する
  • パフォーマンス回帰テスト
  • テストの有効性のためのミューテーションテスト
  • 主要な変更のためのロールバック計画

10. 高度なパターン

  • Strangler Fig: レガシーシステムの段階的な置き換え
  • Branch by Abstraction: 大規模な変更
  • Parallel Change: 拡張-縮小パターン
  • Mikado Method: 依存関係グラフのナビゲーション

出力要件

  • 改善が適用されたリファクタリング済みコード
  • テスト結果 (すべてグリーン)
  • 前後のメトリクス比較
  • 適用されたリファクタリング手法のリスト
  • パフォーマンス改善の測定値
  • 残りの技術的負債の評価

安全性チェックリスト

コミットする前に:

  • ✓ すべてのテストがパスする (100% グリーン)
  • ✓ 機能の回帰がない
  • ✓ パフォーマンスメトリクスが許容範囲内である
  • ✓ コードカバレッジが維持/改善されている
  • ✓ ドキュメントが更新されている

回復プロトコル

テストが失敗した場合:

  • 直前の変更を直ちに戻す
  • 破壊的なリファクタリングを特定する
  • より小さな段階的な変更を適用する
  • 安全な実験のためにバージョン管理を使用する

例: メソッド抽出パターン

変更前:

class OrderProcessor {
  processOrder(order: Order): ProcessResult {
    // Validation
    if (!order.customerId || order.items.length === 0) {
      return { success: false, error: "Invalid order" };
    }

    // Calculate totals
    let subtotal = 0;
    for (const item of order.items) {
      subtotal += item.price * item.quantity;
    }
    let total = subtotal + (subtotal * 0.08) + (subtotal > 100 ? 0 : 15);

    // Process payment...
    // Update inventory...
    // Send confirmation...
  }
}

変更後:

class OrderProcessor {
  async processOrder(order: Order): Promise<ProcessResult> {
    const validation = this.validateOrder(order);
    if (!validation.isValid) return ProcessResult.failure(validation.error);

    const orderTotal = OrderTotal.calculate(order);
    const inventoryCheck = await this.inventoryService.checkAvailability(order.items);
    if (!inventoryCheck.available) return ProcessResult.failure(inventoryCheck.reason);

    await this.paymentService.processPayment(order.paymentMethod, orderTotal.total);
    await this.inventoryService.reserveItems(order.items);
    await this.notificationService.sendOrderConfirmation(order, orderTotal);

    return ProcessResult.success(order.id, orderTotal.total);
  }

  private validateOrder(order: Order): ValidationResult {
    if (!order.customerId) return ValidationResult.invalid("Customer ID required");
    if (order.items.length === 0) return ValidationResult.invalid("Order must contain items");
    return ValidationResult.valid();
  }
}

適用済み: メソッド抽出、値オブジェクト、依存性注入、非同期パターン

リファクタリングするコード: $ARGUMENTS"

制限事項

  • このスキルは、タスクが上記の範囲と明確に一致する場合にのみ使用してください。
  • 出力を s

(原文がここで切り詰められています)

📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Use this skill when

  • Working on tdd workflows tdd refactor tasks or workflows
  • Needing guidance, best practices, or checklists for tdd workflows tdd refactor

Do not use this skill when

  • The task is unrelated to tdd workflows tdd refactor
  • You need a different domain or tool outside this scope

Instructions

  • Clarify goals, constraints, and required inputs.
  • Apply relevant best practices and validate outcomes.
  • Provide actionable steps and verification.
  • If detailed examples are required, open resources/implementation-playbook.md.

Refactor code with confidence using comprehensive test safety net:

[Extended thinking: This tool uses the tdd-orchestrator agent (opus model) for sophisticated refactoring while maintaining all tests green. It applies design patterns, improves code quality, and optimizes performance with the safety of comprehensive test coverage.]

Usage

Use Task tool with subagent_type="tdd-orchestrator" to perform safe refactoring.

Prompt: "Refactor this code while keeping all tests green: $ARGUMENTS. Apply TDD refactor phase:

Core Process

1. Pre-Assessment

  • Run tests to establish green baseline
  • Analyze code smells and test coverage
  • Document current performance metrics
  • Create incremental refactoring plan

2. Code Smell Detection

  • Duplicated code → Extract methods/classes
  • Long methods → Decompose into focused functions
  • Large classes → Split responsibilities
  • Long parameter lists → Parameter objects
  • Feature Envy → Move methods to appropriate classes
  • Primitive Obsession → Value objects
  • Switch statements → Polymorphism
  • Dead code → Remove

3. Design Patterns

  • Apply Creational (Factory, Builder, Singleton)
  • Apply Structural (Adapter, Facade, Decorator)
  • Apply Behavioral (Strategy, Observer, Command)
  • Apply Domain (Repository, Service, Value Objects)
  • Use patterns only where they add clear value

4. SOLID Principles

  • Single Responsibility: One reason to change
  • Open/Closed: Open for extension, closed for modification
  • Liskov Substitution: Subtypes substitutable
  • Interface Segregation: Small, focused interfaces
  • Dependency Inversion: Depend on abstractions

5. Refactoring Techniques

  • Extract Method/Variable/Interface
  • Inline unnecessary indirection
  • Rename for clarity
  • Move Method/Field to appropriate classes
  • Replace Magic Numbers with constants
  • Encapsulate fields
  • Replace Conditional with Polymorphism
  • Introduce Null Object

6. Performance Optimization

  • Profile to identify bottlenecks
  • Optimize algorithms and data structures
  • Implement caching where beneficial
  • Reduce database queries (N+1 elimination)
  • Lazy loading and pagination
  • Always measure before and after

7. Incremental Steps

  • Make small, atomic changes
  • Run tests after each modification
  • Commit after each successful refactoring
  • Keep refactoring separate from behavior changes
  • Use scaffolding when needed

8. Architecture Evolution

  • Layer separation and dependency management
  • Module boundaries and interface definition
  • Event-driven patterns for decoupling
  • Database access pattern optimization

9. Safety Verification

  • Run full test suite after each change
  • Performance regression testing
  • Mutation testing for test effectiveness
  • Rollback plan for major changes

10. Advanced Patterns

  • Strangler Fig: Gradual legacy replacement
  • Branch by Abstraction: Large-scale changes
  • Parallel Change: Expand-contract pattern
  • Mikado Method: Dependency graph navigation

Output Requirements

  • Refactored code with improvements applied
  • Test results (all green)
  • Before/after metrics comparison
  • Applied refactoring techniques list
  • Performance improvement measurements
  • Remaining technical debt assessment

Safety Checklist

Before committing:

  • ✓ All tests pass (100% green)
  • ✓ No functionality regression
  • ✓ Performance metrics acceptable
  • ✓ Code coverage maintained/improved
  • ✓ Documentation updated

Recovery Protocol

If tests fail:

  • Immediately revert last change
  • Identify breaking refactoring
  • Apply smaller incremental changes
  • Use version control for safe experimentation

Example: Extract Method Pattern

Before:

class OrderProcessor {
  processOrder(order: Order): ProcessResult {
    // Validation
    if (!order.customerId || order.items.length === 0) {
      return { success: false, error: "Invalid order" };
    }

    // Calculate totals
    let subtotal = 0;
    for (const item of order.items) {
      subtotal += item.price * item.quantity;
    }
    let total = subtotal + (subtotal * 0.08) + (subtotal > 100 ? 0 : 15);

    // Process payment...
    // Update inventory...
    // Send confirmation...
  }
}

After:

class OrderProcessor {
  async processOrder(order: Order): Promise<ProcessResult> {
    const validation = this.validateOrder(order);
    if (!validation.isValid) return ProcessResult.failure(validation.error);

    const orderTotal = OrderTotal.calculate(order);
    const inventoryCheck = await this.inventoryService.checkAvailability(order.items);
    if (!inventoryCheck.available) return ProcessResult.failure(inventoryCheck.reason);

    await this.paymentService.processPayment(order.paymentMethod, orderTotal.total);
    await this.inventoryService.reserveItems(order.items);
    await this.notificationService.sendOrderConfirmation(order, orderTotal);

    return ProcessResult.success(order.id, orderTotal.total);
  }

  private validateOrder(order: Order): ValidationResult {
    if (!order.customerId) return ValidationResult.invalid("Customer ID required");
    if (order.items.length === 0) return ValidationResult.invalid("Order must contain items");
    return ValidationResult.valid();
  }
}

Applied: Extract Method, Value Objects, Dependency Injection, Async patterns

Code to refactor: $ARGUMENTS"

Limitations

  • Use this skill only when the task clearly matches the scope described above.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.