Skip to main content
skill CX Codex

code-refactor — Claude Code skill: rename and replace code at scale

code-refactor is a Claude Code skill for bulk code changes across files: renaming variables and functions, replacing deprecated patterns, and updating API calls. It automatically selects a mode that saves up to 90% of tokens for 10+ files.

Apache-2.0 304 installs ★ 697 updated 2026-07-25

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add mhattingpete/claude-skills-marketplace --skill code-refactor -a claude-code
Open on GitHub

What code-refactor does

code-refactor applies consistent changes to your codebase systematically. You give it a pattern or identifier to find, it locates every match across all files, shows you the context around each one, and then replaces them all in a single pass.

For projects up to 9 files, the skill uses native search and replace tools. Beyond that, it switches to execution mode with a Python script that does the same job in a fraction of the tokens—around 90% savings on large codebases. Renaming across 50 files costs roughly 500 tokens instead of 25,000.

The skill stays careful about edge cases: it asks whether to touch strings and comments, warns you about breaking changes to public APIs, and suggests running tests when done.

What it helps with

  • rename a variable or function everywhere in the project
  • replace outdated syntax patterns across all files
  • update API endpoints to a new version
  • standardize code style or library usage throughout
  • find and consolidate duplicated code

Example prompts for the agent

  • Rename getUserData to fetchUserData everywhere
  • Replace all /api/auth/login with /api/v2/authentication/login
  • Update every var to let in src/, but only where the variable is reassigned

How to install code-refactor

1Skills CLI (Vercel)

npx skills add mhattingpete/claude-skills-marketplace --skill code-refactor -a claude-code

2Manually: put the files in place

~/.claude/skills/code-refactor/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/code-refactor/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about code-refactor

How do I install code-refactor for Claude Code?

Run npx skills add mhattingpete/claude-skills-marketplace --skill code-refactor -a claude-code, then check ~/.claude/skills/code-refactor/SKILL.md.

What does code-refactor do?

It finds all instances of a pattern, variable, or function across your project, shows context for each match, and applies changes to all of them at once. For large codebases (10+ files), it switches to a Python execution mode and cuts token use by 90%.

When does code-refactor switch to execution mode?

At 10 files or more. The skill uses native grep and edit tools for smaller jobs. Once you cross the threshold, it runs a Python script (rename_identifier) that does the same work far more efficiently, especially useful for projects with hundreds of files.

Source text

SKILL.md · Apache-2.0
---
name: code-refactor
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.
---

# 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`

### Update API Calls
1. Find: `Grep(pattern="/api/auth/login", output_mode="content", -n=true)`
2. Replace: `Edit(old_string="'/api/auth/login'", new_string="'/api/v2/authentication/login'", replace_all=true)`
3. Test: Recommend integration tests

## Best Practices

**Planning:**
- Find all instances first
- Review context of each match
- Inform user of scope
- Consider edge cases (strings, comments)

**Safe Process:**
1. Search → Find all
2. Analyze → Verify appropriate
3. Inform → Tell user scope
4. Execute → Make changes
5. Verify → Confirm applied
6. Test → Suggest running tests

**Edge Cases:**
- Strings/comments: Ask if should update
- Exported APIs: Warn of breaking changes
- Case sensitivity: Be explicit

## Tool Reference

**Edit with replace_all:**
- `replace_all=true`: Replace all occurrences
- `replace_all=false`: Replace only first (or fail if multiple)
- Must match EXACTLY (whitespace, quotes)

**Grep patterns:**
- `-n=true`: Show line numbers
- `-B=N, -A=N`: Context lines
- `-i=true`: Case-insensitive
- `type="py"`: Filter by file type

## Integration

- **test-fixing**: Fix broken tests after refactoring
- **code-transfer**: Move refactored code
- **feature-planning**: Plan large refactorings

© mhattingpete · Apache-2.0 · mhattingpete/claude-skills-marketplace

Similar skills

All skills for Code review and refactoring →

From the same set15

The whole set →
file-operations file-operations collects file metadata, line counts, and content metrics across a project without editing or altering any files. CX Codex +1 418installs code-auditor code-auditor walks a repository through architecture, code quality, security, performance, testing and maintainability, then hands back a report. Useful when you inherit code and need to know what hurts. CX Codex +1 344installs dashboard-creator dashboard-creator builds a single-page HTML dashboard with KPI cards, charts, progress bars and data tables. Handy when you need to show metrics without a frontend framework. CX Codex +1 337installs timeline-creator timeline-creator turns a project's tasks and dates into an interactive HTML timeline with Gantt bars, phases and milestones. Handy when a plan has to live in one file. CX Codex +1 337installs feature-planning The feature-planning skill turns feature requests and complex changes into ordered implementation plans with concrete tasks. Use it before coding when the scope needs structure. CX Codex +1 297installs code-execution The code-execution skill runs Python locally for bulk file work, code analysis, transformations, and Git tasks. It fits large or multi-step workflows. CX Codex +1 294installs conversation-analyzer conversation-analyzer analyzes your local Claude Code session logs to detect recurring errors, repetitive prompts, and workflow bottlenecks. CX Codex +1 249installs technical-doc-creator technical-doc-creator builds HTML documentation for APIs and systems with code samples, architecture diagrams, syntax highlighting, and workflow steps. CX Codex +1 221installs

Project sponsors

Companies that keep this analytics open