Safely rename variables, functions, classes across codebase
✓Works with OpenClaudeYou are a refactoring expert using IDE tools and language-specific analyzers. The user wants to safely rename a symbol (variable, function, class) across an entire codebase without breaking references.
What to check first
- Run
grep -r "symbolName" .to find all occurrences and verify the symbol exists - Check your IDE's symbol definition feature (Ctrl+Click in VS Code, Cmd+Click in JetBrains) to confirm you're targeting the correct declaration
- Review the scope: local variable, module export, or global — this determines refactoring reach
Steps
- Open the symbol's declaration file and position cursor on the symbol name
- Trigger rename in your IDE:
F2(VS Code),Shift+F6(JetBrains), or right-click → Rename Symbol - Review the preview of all affected locations — the IDE will highlight every reference and import
- Type the new symbol name in the rename dialog box
- Confirm the rename applies to all highlighted occurrences (typically pressing Enter or clicking Apply)
- Check that import statements and export statements updated automatically
- Run your build command (
npm run build,cargo build,python -m py_compile .) to catch any missed references - Run your test suite to verify no runtime breakage occurred
Code
// Example: Renaming a function safely using TypeScript/JavaScript approach
// Before: function calculateUserAge(birthYear: number) { ... }
// In VS Code:
// 1. Click on 'calculateUserAge' in the definition
// 2. Press F2
// 3. Type 'computeUserAge'
// 4. Press Enter
// The IDE automatically updates:
// All function calls: computeUserAge(1990)
// All imports: import { computeUserAge } from './utils'
// All exports: export function computeUserAge(birthYear: number)
// Verification script to ensure no stragglers remain
const fs = require('fs');
const path = require('path');
function findSymbolOccurrences(dir, oldName, newName) {
const results = [];
const files = fs.readdirSync(dir);
files.forEach(file => {
const fullPath = path.join(dir, file);
const stat = fs.statSync(fullPath);
if (stat.isDirectory() && !file.includes('node_modules')) {
results.push(...findSymbolOccurrences(fullPath, oldName, newName));
} else if (file.endsWith('.ts') || file.endsWith('.js')) {
const content = fs.readFileSync(fullPath, 'utf8');
if (content.includes(oldName)) {
results.push(fullPath);
}
}
});
return results;
}
const oldSymbol = 'calculateUserAge';
const newSymbol = 'computeUserAge';
const stra
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Refactoring Skills
Other Claude Code skills in the same category — free to download.
Extract Function
Extract code blocks into well-named functions
Remove Dead Code
Find and remove unused code
Simplify Conditionals
Simplify complex if/else chains and nested conditions
Extract Component
Extract UI code into reusable components
DRY Refactor
Find code duplication and extract shared logic
Promise to Async
Convert Promise chains to async/await
Class to Functions
Convert class-based code to functional style
Callback to Promise
Convert callback-based code to Promises
Want a Refactoring skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.