# Phase 1: Discovery & Instructions

## 1. Parse the Refactor Request

Understand what the pattern means:
- Could be: method name, component name, pattern, code smell, etc.
- Identify the search strategy (Grep for code patterns, Glob for file patterns)

## 2. Find All Affected Files

```
Use Grep to search for the pattern in the codebase
Use Glob if searching by file name patterns
Exclude: node_modules, .git, dist, build, bin, obj
```

## 3. Analyze Scope

- Count total files found
- If more than 15 files, ask user to confirm or narrow scope
- Show preview of files to refactor

## 4. Create Task Folder

```
Generate unique ID: refactor-{timestamp}
Create folder: .claude/tasks/refactor-{timestamp}/
```

## 5. Create ONE Instruction File

Create `.claude/tasks/refactor-{id}/instructions.md`:

```markdown
# Refactor: {title}

## Objective
{What needs to be refactored - derived from user request}

## Pattern to Find
{Exact code pattern, method name, or structure to locate}

## Transformation
{How to transform the found pattern - be specific and adaptive}

## Examples
Before:
{example of current code}

After:
{example of refactored code}

## Constraints
- Only modify code matching the pattern
- Preserve all existing functionality
- Follow codebase conventions
- No comments unless necessary
```

**IMPORTANT**: Make instructions adaptive - they should work for ANY file in the list.
