Skip to content
All Skills

Code Refactor

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.

Software Engineering|v1|Updated 7/14/2026|GitHub source
MCP get_skill({ skillId: "code-refactor-2f84b921" })

Use this skill with your agent

Create a free account and connect via MCP

Get Started Free
# 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
#broad-capability#engineering-workflow#productivity#visual-documentation#code#quality

Related Skills

More skills in Software Engineering

Accessibility Standards

Comprehensive web accessibility standards based on WCAG 2.2 AA, with 38+ anti-patterns, legal enforcement context (EAA, ADA Title II), WAI-ARIA patterns, and framework-specific fixes for modern web frameworks and libraries.

#github-copilot#accessibilityMIT

Accord

Authoring unified specification packages across Business/Development/Design teams via staged elaboration (L0 Vision → L1 Requirements → L2 Team Detail → L3 Acceptance Criteria). No code. Use when authoring cross-team specs, building L0-L3 packages, or aligning Biz/Dev/Design on a single source of truth.

#broad-capability#developmentMIT

Acquire Codebase Knowledge

Use this skill when the user explicitly asks to map, document, or onboard into an existing codebase. Trigger for prompts like "map this codebase", "document this architecture", "onboard me to this repo", or "create codebase docs". Do not trigger for routine feature implementation, bug fixes, or narrow code edits unless the user asks for repository-level discovery.

#github-copilot#documentationMIT

Acreadiness Assess

Run the AgentRC readiness assessment on the current repository and produce a static HTML dashboard at reports/index.html. Wraps `npx github:microsoft/agentrc readiness` and hands off rendering to the @ai-readiness-reporter custom agent. Supports policies (--policy) for org-specific scoring. Use when asked to assess, audit, or score the AI readiness of a repo.

#github-copilot#planningMIT

Acreadiness Generate Instructions

Generate tailored AI agent instruction files via AgentRC instructions command. Produces .github/copilot-instructions.md (default, recommended for Copilot in VS Code) plus optional per-area .instructions.md files with applyTo globs for monorepos. Use after running /acreadiness-assess to close gaps in the AI Tooling pillar.

#github-copilot#skillMIT

Acreadiness Policy

Help the user pick, write, or apply an AgentRC policy. Policies customise readiness scoring by disabling irrelevant checks, overriding impact/level, setting pass-rate thresholds, or chaining org baselines with team overrides. Use when the user asks about strict mode, AI-only scoring, custom weights, CI gating, or wants org-wide standardisation.

#github-copilot#planningMIT