home / skills / shotaiuchi / dotclaude / team-refactor

team-refactor skill

/dotclaude/skills/team-refactor

This skill automatically assembles and deploys a specialized agent team to analyze, plan, and execute large-scale refactors with a comprehensive roadmap.

npx playbooks add skill shotaiuchi/dotclaude --skill team-refactor

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
6.0 KB
---
name: team-refactor
description: Agent Teamsで大規模リファクタリングチームを自動構成・起動
argument-hint: "[--pr N | --commit REF | --diff | --staged | path | goal]"
user-invocable: true
disable-model-invocation: true
---

# Refactor Team

Create an Agent Team with automatically selected specialists based on the refactoring target and goal.

## Instructions

1. **Analyze the target** (file, directory, or refactoring goal) to determine the refactoring type
2. **Select appropriate specialists** based on the selection matrix below
3. **Create the agent team** with only the selected specialists
4. Have them share findings and produce a comprehensive refactoring plan

## Step 0: Scope Detection

Parse `$ARGUMENTS` to determine the analysis target.
See `references/agent-team/scope-detection.md` for full detection rules.

| Flag | Scope | Action |
|------|-------|--------|
| `--pr <N>` | PR | `gh pr diff <N>` + `gh pr view <N> --json title,body,files` |
| `--issue <N>` | Issue | `gh issue view <N> --json title,body,comments` |
| `--commit <ref>` | Commit | `git show <ref>` or `git diff <range>` |
| `--diff` | Unstaged changes | `git diff` |
| `--staged` | Staged changes | `git diff --staged` |
| `--branch <name>` | Branch diff | `git diff main...<name>` |
| Path pattern | File/Directory | `Glob` + `Read` |
| Free text | Description | Use as context for analysis |
| (empty or ambiguous) | Unknown | Ask user to specify target |

## Step 1: Codebase Analysis

Before spawning any teammates, analyze the target to determine the refactoring type:

| Signal | Type |
|--------|------|
| Extracting classes/functions, splitting modules, decomposing monoliths | Extract/Split |
| Renaming symbols, moving files, reorganizing directory structure | Rename/Restructure |
| Replacing patterns (e.g., callbacks to async/await, inheritance to composition) | Pattern Change |
| Updating libraries, frameworks, or language versions | Dependency Update |
| Optimizing hot paths, reducing memory usage, improving throughput | Performance |
| Mixed signals | Analyze dominant patterns and apply multiple types |

## Step 2: Specialist Selection Matrix

| Specialist | Extract/Split | Rename/Restructure | Pattern Change | Dependency Update | Performance |
|:-----------|:------------:|:------------------:|:--------------:|:-----------------:|:-----------:|
| Dependency Mapper | Always | Always | Always | Always | Always |
| Code Archeologist | Always | Always | Always | If legacy | If legacy |
| Pattern Analyst | Always | If pattern-related | Always | Skip | If algorithmic |
| Migration Planner | If breaking changes | Always | Always | Always | Skip |
| Test Guardian | Always | Always | Always | Always | Always |
| Impact Assessor | Always | Always | Always | Always | Always |
| Compatibility Checker | If public API | If public API | If public API | Always | Skip |

### Selection Rules

- **Always**: Spawn this specialist unconditionally
- **Skip**: Do not spawn this specialist
- **Conditional**: Spawn only if the condition is met based on code analysis

When uncertain, **include the specialist** (prefer thoroughness over efficiency).

## Step 3: Team Creation

Spawn only the selected specialists using the **Task tool** (`subagent_type: "general-purpose"`).

**Execution Rules:**
- Send ALL Task tool calls in a **single message** for parallel execution
- Each subagent runs in its own context and returns findings to the lead (main context)
- Provide each subagent with the full target context (refactoring scope, file contents, etc.) in the prompt
- The lead (main context) is responsible for synthesis — do NOT spawn a subagent for synthesis

1. **Dependency Mapper**: Map all dependencies, import chains, call graphs, and coupling relationships for the target code. Identify tightly coupled modules, circular dependencies, and hidden connections that could break during refactoring.

2. **Code Archeologist**: Research the history of the code, understand why decisions were made, and identify hidden constraints. Use git blame, commit messages, and code comments to uncover rationale that must be preserved.

3. **Pattern Analyst**: Identify current design patterns, anti-patterns, and recommend target patterns for the refactoring. Evaluate whether proposed patterns fit the codebase's conventions and team's familiarity.

4. **Migration Planner**: Create a step-by-step migration plan that ensures each step leaves the codebase in a working state. Define rollback points, feature flags, and incremental delivery milestones.

5. **Test Guardian**: Verify existing test coverage, identify gaps, and ensure tests will catch regressions during refactoring. Recommend additional tests needed before starting and verification checkpoints throughout.

6. **Impact Assessor**: Analyze the blast radius of changes, identify affected consumers, and assess risk levels. Categorize impacts by severity and likelihood, and flag areas requiring extra caution.

7. **Compatibility Checker**: Verify backward compatibility for public APIs, exported interfaces, and external contracts. Identify breaking changes and propose compatibility shims or migration guides for consumers.

## Workflow

1. Lead analyzes the codebase and defines the refactoring scope, announcing selected specialists with reasoning
2. Each selected specialist analyzes the target from their specialized perspective
3. Specialists share findings with each other to build a comprehensive understanding
4. The lead synthesizes all findings into a safe, incremental refactoring plan:
   - Dependency map showing affected modules and their relationships
   - Risk assessment with severity and likelihood ratings
   - Step-by-step execution order with rollback points
   - Test verification checkpoints between each major step

## Output

The lead produces a final refactoring plan including:
- Refactoring type detected and specialists selected (with reasoning)
- Dependency map of affected code
- Risk assessment matrix
- Ordered execution steps with rollback strategy
- Test verification checkpoints

Overview

This skill automates creation and orchestration of a specialist Agent Team to plan large-scale code refactors. It detects the refactoring scope, analyzes the codebase to classify the refactor type, selects the right experts, and runs them in parallel to produce a safe, incremental refactoring plan. The lead agent synthesizes findings into dependency maps, risk assessments, and rollout steps.

How this skill works

The skill parses the provided target (file, directory, PR, commit, diff, or free-text goal) to determine scope and refactor type. It runs a pre-analysis to classify signals (extract/split, rename/restructure, pattern change, dependency update, performance) and applies a selection matrix to spawn only the required specialists. Each specialist runs in parallel with the full target context and returns focused findings; the lead agent then synthesizes those results into a step-by-step plan with rollback points and test checkpoints.

When to use it

  • Preparing a coordinated, multi-person refactor across modules or services
  • Refactoring legacy or tightly coupled code where risk and history matter
  • Upgrading frameworks, libraries, or language versions with potential breaking changes
  • Restructuring public APIs or making pattern-level architecture changes
  • Planning performance optimizations that touch many components

Best practices

  • Provide a clear scope argument (PR, commit, diff, file path, or concise goal) to avoid ambiguous analysis
  • Prefer including more specialists if uncertain—thoroughness reduces missed risks
  • Ensure repository history is available to the tool for archeological analysis (git access)
  • Maintain an up-to-date test suite before running the plan; add critical tests early
  • Use feature flags and small incremental steps in the migration plan to minimize blast radius

Example use cases

  • Split a monolithic service into smaller modules while preserving public API contracts
  • Rename and reorganize a package hierarchy across multiple repositories with compatibility shims
  • Migrate callback-based code to async/await across a large codebase with staged rollout
  • Upgrade a framework major version and produce a migration plan with compatibility checks and test gates
  • Optimize a hot code path by analyzing coupling, measuring impact, and sequencing safe changes

FAQ

What inputs does the skill accept to define scope?

It accepts PR numbers, issue numbers, commit refs, diffs, staged/unstaged changes, branch diffs, file or directory paths, or free-text goals—specify one to avoid ambiguity.

How are specialists selected?

Selection follows an analysis-driven matrix: some specialists always run, others run conditionally based on detected patterns, and when uncertain the skill errs on including the specialist.