---
name: refactor
description: Refactor code by finding files, grouping them, and launching parallel Snipper agents
argument-hint: <search-pattern-or-description>
disable-model-invocation: true
---

<objective>
Refactor code matching the given pattern across the codebase using parallel Snipper agents for maximum speed.

This skill finds all relevant files, creates ONE instruction file, then launches Snipper agents in parallel with batches of max 3 files each.
</objective>

<quick_start>
```bash
/refactor rename getUserData to fetchUserProfile
/refactor replace console.log with logger.info
/refactor convert class components to functional
/refactor update deprecated API calls
```
</quick_start>

<workflow>

## Phase 1: Discovery
1. Parse the refactor request (method name, pattern, code smell)
2. Find all affected files (Grep for code, Glob for file patterns)
3. Analyze scope — if >15 files, confirm with user

See [steps/step-01-discover.md](steps/step-01-discover.md) for search strategy and instruction file template.

## Phase 2: Create Instructions
4. Create task folder: `.claude/tasks/refactor-{timestamp}/`
5. Create ONE `instructions.md` with: Objective, Pattern, Transformation, Examples, Constraints

## Phase 3: Group and Execute
6. Group files into batches (max 3 per batch)
7. Launch ALL Snipper agents in parallel (single message, multiple Task calls)
8. Wait for completion

## Phase 4: Verification
9. Validate changes (lint/typecheck/build)
10. Provide summary report

See [steps/step-02-execute.md](steps/step-02-execute.md) for execution details and report format.

</workflow>

<success_criteria>
- All target files identified
- ONE instruction file created in `.claude/tasks/refactor-{id}/instructions.md`
- Snipper agents launched in parallel (max 3 files per agent)
- All batches completed successfully
- Lint/type checks pass
- Summary provided to user
</success_criteria>
