Symbolic refactoring patterns using Serena MCP tools. Core patterns for safe code modification, reference tracking, and automated refactoring workflows.
/plugin marketplace add chkim-su/serena-refactor-marketplace/plugin install serena-refactor@serena-refactor-marketplaceThis skill inherits all available tools. When active, it can use any tool Claude has access to.
Understand and modify code at the symbol level. Ensure safety through AST-based editing, not text replacement.
1. get_symbols_overview to understand file structure (depth=0)
2. When class of interest found, use depth=1 to check method list
3. When specific method body needed, use find_symbol + include_body=True
| Pattern | Meaning | Example |
|---|---|---|
ClassName | All classes with that name | UserService |
ClassName/method | Method of specific class | UserService/create |
/ClassName/method | Exact path matching | /UserService/create |
get* (substring_matching=True) | Prefix matching | getValue, getData |
Using find_referencing_symbols:
- Assess refactoring impact scope
- Build dependency graph
- Detect circular references
When to Use:
Cautions:
When to Use:
Pattern:
mode: "regex"
needle: "old_pattern.*?end_marker"
repl: "new_content"
allow_multiple_occurrences: True/False
| Tool | Use Case |
|---|---|
insert_before_symbol | Adding imports, adding decorators |
insert_after_symbol | Adding new methods/classes |
1. Read target method body with find_symbol
2. Identify code block to extract
3. Design new method signature
4. Add new method with insert_after_symbol
5. Replace original with call using replace_content
6. Verify impact with find_referencing_symbols
1. Identify all usages with find_referencing_symbols
2. Rename across entire codebase with rename_symbol
3. Verify results (all references updated automatically)
1. Get class method list with find_symbol + depth=1
2. Identify common methods
3. Write new interface definition
4. Add interface with insert_before_symbol
5. Modify class to implement interface with replace_symbol_body
1. Read original method with find_symbol (include_body=True)
2. Add method to target class with insert_after_symbol
3. Identify all call sites with find_referencing_symbols
4. Update call sites with replace_content
5. Delete original method (replace_symbol_body with empty or remove)
Detection: Class has more than 10 methods
Fix:
1. Group methods with get_symbols_overview
2. Create new classes by responsibility
3. Apply move method pattern
4. Delegate from original class to new classes
Detection: Business logic directly depends on infrastructure
Fix:
1. Map dependencies with find_referencing_symbols
2. Apply extract interface pattern
3. Change to constructor injection
Detection: Type-based switch/if chains
Fix:
1. Detect switch statements with search_for_pattern
2. Extract each case to strategy class
3. Apply factory/registry pattern
write_memory:
- Architecture decision records
- Refactoring history
- Coding conventions
read_memory:
- Previous refactoring progress
- Known technical debt
- High-priority fix targets
Build robust backtesting systems for trading strategies with proper handling of look-ahead bias, survivorship bias, and transaction costs. Use when developing trading algorithms, validating strategies, or building backtesting infrastructure.