# Code Refactor

Perform bulk code refactoring operations like renaming variables/functions across...

- Repository: https://github.com/mhattingpete/claude-skills-marketplace (689 stars)
- Category: Engineering
- License: Apache-2.0
- Last updated: 2026-07-25
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add mhattingpete/claude-skills-marketplace --skill code-refactor -g -a claude-code -y`
Codex: `npx skills add mhattingpete/claude-skills-marketplace --skill code-refactor -g -a codex -y`
Cursor: `npx skills add mhattingpete/claude-skills-marketplace --skill code-refactor -g -a cursor -y`
Gemini CLI: `npx skills add mhattingpete/claude-skills-marketplace --skill code-refactor -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add mhattingpete/claude-skills-marketplace`

## Description

Perform bulk code refactoring operations like renaming variables/functions across files, replacing patterns, and updating API calls. Use when users request renaming identifiers, replacing deprecated code patterns, updating method calls, or making consistent changes across multiple locations.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Code Refactor

Systematic code refactoring across files. **Auto-switches to execution mode** for 10+ files (90% token savings).

## Mode Selection

- **1-9 files**: Use native tools (Grep + Edit with replace_all)
- **10+ files**: Automatically use `code-execution` skill

**Execution example (50 files):**
```python
from api.code_transform import rename_identifier
result = rename_identifier('.', 'oldName', 'newName', '**/*.py')
# Returns: {'files_modified': 50, 'total_replacements': 247}
# ~500 tokens vs ~25,000 tokens traditional
```

## When to Use

- "rename [identifier] to [new_name]"
- "replace all [pattern] with [replacement]"
- "refactor to use [new_pattern]"
- "update all calls to [function/API]"
- "convert [old_pattern] to [new_pattern]"

## Core Workflow (Native Mode)

### 1. Find All Occurrences
```
Grep(pattern="getUserData", output_mode="files_with_matches")     # Find files
Grep(pattern="getUserData", output_mode="content", -n=true, -B=2, -A=2)  # Verify with context
```

### 2. Replace All Instances
```
Edit(
  file_path="src/api.js",
  old_string="getUserData",
  new_string="fetchUserData",
  replace_all=true
)
```

### 3. Verify Changes
```
Grep(pattern="getUserData", output_mode="files_with_matches")  # Should return none
```

## Workflow Examples

### Rename Function
1. Find: `Grep(pattern="getUserData", output_mode="files_with_matches")`
2. Count: "Found 15 occurrences in 5 files"
3. Replace in each file with `replace_all=true`
4. Verify: Re-run Grep
5. Suggest: Run tests

### Replace Deprecated Pattern
1. Find: `Grep(pattern="\\bvar\\s+\\w+", output_mode="content", -n=true)`
2. Analyze: Check if reassigned (let) or constant (const)
3. Replace: `Edit(old_string="var count = 0", new_string="let count = 0")`
4. Verify: `npm run lint`

The rest: https://github.com/mhattingpete/claude-skills-marketplace/blob/HEAD/code-operations-plugin/skills/code-refactor/SKILL.md
