Safe refactoring operations using LSP for precise symbol resolution. Supports rename, extract function/method, and move symbol operations with automatic reference updates.
Performs safe, LSP-powered refactoring operations like rename, extract, and move with automatic reference updates and impact analysis. Use this for any refactoring that affects multiple files or symbols across your codebase.
/plugin marketplace add tylerburleigh/claude-foundry/plugin install foundry@claude-foundryThis skill inherits all available tools. When active, it can use any tool Claude has access to.
references/impact-analysis.mdreferences/lsp-check.mdreferences/operations.mdreferences/troubleshooting.mdSkill(foundry:sdd-refactor) provides LSP-powered refactoring with safety checks. It uses findReferences to understand impact before making changes, performs batch edits, and verifies correctness.
Core capabilities:
IMPORTANT: This skill uses Claude Code's built-in LSP tools for precise refactoring. If LSP returns no results for the target language, fall back to Grep-based patterns.
This skill integrates with the Spec-Driven Development workflow:
sdd-plan --> sdd-refactor (for planned refactoring tasks) --> sdd-update --> sdd-fidelity-review
Can also be used standalone for ad-hoc refactoring outside of specs.
Use Skill(foundry:sdd-refactor) for:
Do NOT use for:
[x?]=decision ·(GATE)=user approval ·→=sequence ·↻=loop ·§=section ref
- **Entry** → [Type: Rename|Extract|Move|Cleanup?]
- ValidateTarget → [LSP available?]
- [yes] → `documentSymbol` → `goToDefinition`
- [no] → Grep fallback
- ImpactAnalysis (GATE - REQUIRED)
- `findReferences` → Risk[<10|<50|50-100|>100 refs]
- (GATE: user approval for scope)
- Execute → [4 operation-specific paths]
- Verify → Structural[LSP] → References[LSP] → Tests[run-tests]
- Document → [spec task?] → journal entry
- **Exit**: Done
This skill uses Claude Code's built-in LSP tools directly:
| Tool | Purpose |
|---|---|
findReferences | Find all usages of a symbol |
goToDefinition | Navigate to symbol definition |
documentSymbol | Get file structure/symbol outline |
For spec integration, use foundry-mcp:
| Router | Actions | Purpose |
|---|---|---|
task | update-status, complete | Track refactoring task progress |
journal | add | Document refactoring decisions |
Gather information about what to refactor:
User provides:
Validate target exists with LSP:
definition = goToDefinition(file="src/module.py", symbol="OldClassName", line=10)
if definition found:
Proceed to impact analysis
else:
Ask user to verify symbol name and location
Fallback if LSP unavailable:
Use Grep to verify symbol exists:
Grep(pattern="class OldClassName", path="src/")
NEVER refactor without understanding impact first.
findReferences to get all usages of the symbolCRITICAL: Read references/impact-analysis.md before refactoring. Contains required impact report format.
Execute the appropriate operation based on refactoring type:
| Operation | Key Steps |
|---|---|
| Rename | Collect references → Sort by dependency → Batch edit → Verify |
| Extract | Identify block → Analyze variables → Create function → Replace |
| Move | Find references → Move definition → Update imports → Verify |
| Dead Code | Check reference count → Remove if zero → Clean imports |
See references/operations.md for detailed procedures for each operation type.
After any refactoring:
Structural verification (LSP):
documentSymbol(file="src/module.py")
# Verify expected structure preserved
Reference verification (LSP):
findReferences(file="src/module.py", symbol="NewName")
# Verify all references resolve
Run affected tests:
Skill(foundry:run-tests) "Run tests for affected files"
If refactoring is part of a spec task:
mcp__plugin_foundry_foundry-mcp__task action="complete" spec_id="{spec-id}" task_id="{task-id}" completion_notes="Renamed OldClassName to NewClassName across 12 files. All tests passing."
For significant refactors, add journal entry:
mcp__plugin_foundry_foundry-mcp__journal action="add" spec_id="{spec-id}" title="Refactoring: OldClassName -> NewClassName" content="Renamed class for clarity. 47 references updated across 12 files. No functional changes." entry_type="decision"
Before using LSP-enhanced workflow, verify by calling documentSymbol on the target file. If it returns successfully, use LSP workflow. Otherwise, fall back to Grep-based workflow.
See references/lsp-check.md for fallback triggers and verification procedure.
| Scope | Approach |
|---|---|
| Single file, <10 refs | Direct refactoring |
| Cross-file, <50 refs | Batch with verification |
| 50-100 refs | Split into incremental changes |
| >100 refs | Create spec for tracking, phase the work |
Rename class:
Skill(foundry:sdd-refactor) "Rename AuthService to AuthenticationService in src/auth/service.py"
Extract method:
Skill(foundry:sdd-refactor) "Extract lines 45-67 in src/handlers.py into new method validate_request"
Move function:
Skill(foundry:sdd-refactor) "Move helper_function from src/utils.py to src/helpers/common.py"
Dead code cleanup:
Skill(foundry:sdd-refactor) "Find and remove unused functions in src/legacy/"
Rename with spec context:
Skill(foundry:sdd-refactor) "Complete task-2-3: Rename UserDTO to UserResponse as specified"
For comprehensive documentation including:
references/impact-analysis.mdreferences/operations.mdreferences/lsp-check.mdreferences/troubleshooting.mdThis skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.