# rename > Use this skill proactively when the user asks to rename a function, class, variable, or method. This performs safe semantic renaming across the entire codebase using LSP - never use find-and-replace for code refactoring. - Author: joel_aniol-admin - Repository: JoelCampoint/claude_lsp - Version: 20260125221258 - Stars: 0 - Forks: 0 - Last Updated: 2026-02-06 - Source: https://github.com/JoelCampoint/claude_lsp - Web: https://mule.run/skillshub/@@JoelCampoint/claude_lsp~rename:20260125221258 --- --- name: rename description: Use this skill proactively when the user asks to rename a function, class, variable, or method. This performs safe semantic renaming across the entire codebase using LSP - never use find-and-replace for code refactoring. arguments: - name: symbol description: The current name of the symbol to rename required: true - name: newName description: The new name for the symbol required: true - name: file description: File where the symbol is defined required: false --- # Rename Symbol Use the LSP `rename_symbol` tool to safely rename a symbol across the entire codebase. ## ⚠️ CRITICAL SAFETY RULES **BEFORE any rename, you MUST:** 1. **Run impact analysis first** using `find_references` 2. **Assess risk level** based on number of affected files 3. **Show clear warning** to user with risk assessment 4. **Get EXPLICIT confirmation** - never auto-proceed on high-impact renames ### Risk Level Thresholds | Files Affected | Risk Level | Action Required | |----------------|------------|-----------------| | 1-5 files | 🟢 LOW | Show preview, ask confirmation | | 6-20 files | 🟡 MEDIUM | Show detailed breakdown, warn about testing | | 21-50 files | 🟠 HIGH | Strong warning, recommend backup/branch first | | 51+ files | 🔴 CRITICAL | **STOP** - Require explicit "I understand the risk" | ## Steps ### Step 1: Impact Assessment (MANDATORY) First, check how many files will be affected: ``` mcp__cclsp__find_references with: - symbol_name: "{{symbol}}" - file_path: "{{file}}" (if provided) ``` Count unique files and determine risk level. ### Step 2: Show Risk Assessment **For LOW risk (1-5 files):** ``` Rename: `oldName` → `newName` Risk: 🟢 LOW (3 files affected) Proceed with dry-run preview? ``` **For MEDIUM risk (6-20 files):** ``` Rename: `oldName` → `newName` Risk: 🟡 MEDIUM (12 files affected) ⚠️ This will modify multiple files. Consider running tests after this change. Proceed with dry-run preview? ``` **For HIGH risk (21-50 files):** ``` Rename: `oldName` → `newName` Risk: 🟠 HIGH (35 files affected) ⚠️ WARNING: Large-scale refactoring Recommendations: 1. Create a git branch first 2. Have tests ready to verify 3. Review changes carefully before committing Do you want to proceed with a dry-run preview? ``` **For CRITICAL risk (51+ files):** ``` Rename: `oldName` → `newName` Risk: 🔴 CRITICAL (97 files affected!) 🛑 STOP - This is a major refactoring operation! This symbol is used across the entire codebase. Renaming it carries significant risk of: - Breaking functionality in unexpected places - Causing merge conflicts with other branches - Requiring extensive testing I will NOT proceed unless you explicitly confirm: "I understand the risk and want to proceed" Consider alternatives: - Is this rename really necessary? - Can you rename a more specific/local symbol instead? - Should this be done in a dedicated refactoring PR? ``` ### Step 3: Dry Run Preview (only after user confirms) ``` mcp__cclsp__rename_symbol with: - symbol_name: "{{symbol}}" - new_name: "{{newName}}" - file_path: "{{file}}" (if provided) - dry_run: true ``` Show: - List of files affected - Number of replacements per file - Preview of changes ### Step 4: Final Confirmation **NEVER auto-apply.** Always ask: ``` Ready to apply rename? Files to modify: X Total replacements: Y Type "yes" to apply, or "no" to cancel. ``` ### Step 5: Apply (only after explicit "yes") ``` mcp__cclsp__rename_symbol with: - symbol_name: "{{symbol}}" - new_name: "{{newName}}" - file_path: "{{file}}" (if provided) - dry_run: false ``` ## Example Output ### Low Risk Example ``` Rename: `getUserData` → `fetchUserProfile` Risk: 🟢 LOW (3 files affected) Dry-run preview: 📁 src/services/UserService.php - Line 34: function definition - Line 89: internal call 📁 src/controllers/ProfileController.php - Line 23: method call 📁 tests/UserServiceTest.php - Line 12: test call Total: 4 replacements in 3 files Apply this rename? (yes/no) ``` ### Critical Risk Example ``` Rename: `render` → `display` Risk: 🔴 CRITICAL (58 files affected!) 🛑 This is a core framework method. Affected areas: - 45 Controllers - 12 Tests - 1 Service I strongly recommend against renaming core infrastructure. If you must proceed, please confirm with: "I understand the risk and want to proceed" ``` ## Why Use LSP Rename ❌ **Don't use find-and-replace** because: - May rename unrelated symbols with same name - Won't update strings or comments (which is correct) - Can miss dynamic usages ✅ **LSP rename** understands: - Scope and context - Type information - Only renames the actual symbol, not coincidental matches ## Recovery If something goes wrong: ```bash git checkout . # Discard all changes git stash # Or stash for later review ``` Always recommend the user commits or stashes current work before large renames.