refactor-plan

$npx mdskill add softspark/ai-toolkit/refactor-plan

Creates a detailed refactor plan with tiny commits via user interview.

  • Solves the problem of planning safe, incremental code refactors.
  • Depends on Read, Grep, Glob, Bash, and Agent tools.
  • Interviews user, explores codebase, and presents alternative approaches.
  • Files a GitHub issue with a step-by-step plan of tiny commits.

SKILL.md

.github/skills/refactor-planView on GitHub ↗
---
name: refactor-plan
description: "Creates detailed refactor plan with tiny commits via interview, files as GitHub RFC. Triggers: refactor plan, refactoring RFC, incremental refactor, safe steps."
user-invocable: true
effort: high
argument-hint: "[area or module to refactor]"
allowed-tools: Read, Grep, Glob, Bash, Agent
---

# Refactor Plan

$ARGUMENTS

Create a detailed refactor plan with tiny commits via user interview, filed as a GitHub issue.

## Usage

```
/refactor-plan [area or module to refactor]
```

## What This Command Does

1. **Gathers** detailed problem description from user
2. **Explores** the codebase to verify assertions
3. **Presents** alternative approaches (>=3 options)
4. **Interviews** about implementation details
5. **Checks** test coverage of affected area
6. **Breaks** into tiny commits (Martin Fowler: each step keeps codebase working)
7. **Files** as GitHub issue via `gh issue create`

## Process

### 1. Gather Problem

Ask for detailed description of:
- The problem they want to solve
- Potential ideas for solutions

### 2. Explore Codebase

Use Agent (subagent_type=Explore) to verify assertions and understand current state.

### 3. Present Alternatives

Present >=3 alternative approaches. Discuss trade-offs.

### 4. Interview

Detailed interview about chosen approach. Hammer out exact scope — what changes, what doesn't.

### 5. Check Test Coverage

Explore existing test coverage for the affected area. If insufficient, ask about testing plans.

### 6. Break into Tiny Commits

Each commit:
- Leaves the codebase in a working state
- Is the smallest possible step
- Can be reviewed independently

### 7. File GitHub Issue

Use `gh issue create` with template below. Share URL immediately.

## Issue Template

<refactor-plan-template>

## Problem Statement

The problem from the developer's perspective.

## Solution

The solution from the developer's perspective.

## Commits

Detailed plan in plain English, broken into the tiniest commits possible. Each commit leaves the codebase working.

## Decision Document

Implementation decisions made:
- Modules to build/modify
- Interface changes
- Architectural decisions
- Schema changes
- API contracts

Do NOT include file paths or code snippets — they go stale.

## Testing Decisions

- What makes a good test (external behavior, not implementation details)
- Which modules to test
- Prior art for tests in the codebase

## Out of Scope

What is explicitly NOT part of this refactor.

</refactor-plan-template>

## Rules

- **MUST** present >=3 alternative approaches with trade-offs before committing to one
- **MUST** break the refactor into commits small enough to roll back individually — a commit that cannot be reverted is not tiny
- **MUST** verify test coverage of the affected area before planning; insufficient coverage is a blocker, not a warning
- **NEVER** embed file paths, code snippets, or function names in the issue body — the plan outlives the code
- **NEVER** ask for review after creating the issue — file it immediately, share the URL, iterate in comments
- **CRITICAL**: dead-code cleanup is **per step**, not deferred (Constitution Art. VI.1). "We'll delete the old code later" is only acceptable during explicit expand-contract phases, and the cleanup step must be in the plan.
- **MANDATORY**: the Out of Scope section names what is NOT part of this refactor — scope clarity prevents reviewer confusion

## Gotchas

- "Tiny" is relative to the reviewer's context. A 20-line commit that touches the hot path is not tiny in practice — tiny means **tractable**, not short.
- Tests for refactors are often omitted with "the existing tests cover it". Verify by running the suite with coverage in the affected area, not by asking.
- Rebasing a long chain of tiny commits is painful when the target branch moves. Recommend landing the chain weekly and rebasing on `main` before each review round.
- GitHub issue RFCs tend to get stale if the refactor drags. Add a "Status" line that updates with each landed commit so readers see progress without scrolling through comments.
- Expand-contract refactors with double-writes silently leak cost — both paths are live, both pay resources. Set a hard deadline in the plan for when the old path is removed.

## When NOT to Use

- For **executing** a refactor directly — use `/refactor`
- For architecture-level audit without a specific refactor in mind — use `/architecture-audit`
- For creating a PRD (product requirements) — use `/write-a-prd`
- For a plan without the GitHub RFC step — use `/plan`
- For interface design of a single module — use `/design-an-interface`

More from softspark/ai-toolkit

SkillDescription
a11y-validateAccessibility validator: WCAG 2.1 AA, EN 301 549, EAA. Triggers: a11y, accessibility, WCAG, EAA, ARIA, contrast, keyboard, screen reader.
agent-creatorCreates new specialized agents with frontmatter, tools, delegation. Triggers: new agent, create agent, agent scaffold, specialized agent.
ai-toolkit-rulesMandatory engineering, security, testing, git, performance, quality, and response rules. Claude MUST load this skill for every technical, coding, debugging, review, architecture, DevOps, data, or file-editing task in Chat or Cowork.
api-patternsREST/GraphQL API design: naming, versioning, pagination, idempotency, OpenAPI. Triggers: API design, REST, GraphQL, OpenAPI, Swagger, idempotency, rate limit.
architecture-auditAudits codebase for architectural friction, shallow modules; proposes RFCs. Triggers: improve architecture, shallow modules, deepen modules, reduce coupling.
biz-scanScans codebase for revenue opportunities, KPIs, monetization gaps. Triggers: business metrics, KPI, analytics gaps, monetization, revenue.
briefingExecutive daily briefing aggregating reports from all agents into decision-focused summary. Triggers: briefing, daily summary, status across system, executive update.
chaosInjects controlled faults for resilience testing on non-prod. Triggers: chaos, fault injection, latency injection, dependency kill, resilience test.
ci-cd-patternsCI/CD: GitHub Actions, GitLab CI, Jenkins, caching, blue-green, canary. Triggers: CI, CD, pipeline, GitHub Actions, workflow YAML, release, canary, rollout.
content-moderation-patternsContent moderation with Claude: pre-filter vs LLM-classify, categories, thresholds, HITL. Triggers: moderation, safety filter, policy enforcement, content classifier.