mcpbeat Sign in

Lsp Refactoring Agent Skill

Intelligent code refactoring using IDE-level tools (rename, find-references, go-to-definition), AST-aware pattern matching, and TDD verification. Use for safe, large-scale refactoring with precision.

1k tokens
context cost
the whole folder, loaded on every use
1
files
instructions only
0
copies elsewhere
how many repositories repackaged it
141
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/ArabelaTso/Skills-4-SE --skill lsp-refactoring

The instruction itself

10 sections, as written by the author

LSP Refactoring

Refactoring workflow that combines language server capabilities with code search and test-driven verification for safe, precise code transformations.

When to Use This Skill

  • Renaming symbols across an entire workspace
  • Extracting functions, classes, or modules
  • Moving code between files with automatic reference updates
  • Large-scale pattern-based code transformations
  • Any refactoring where manual find-replace is error-prone

What This Skill Does

Phase 1: Analysis — Understand Before Changing

  • Scope assessment: Find all usages of the target symbol using grep or IDE references
  • Dependency graph: Trace where the symbol is defined and what depends on it
  • Impact analysis: Identify all files that will be affected
  • Pattern discovery: Search for similar patterns that should be refactored consistently
# Find all usages of a function
grep -rn "getUserData" src/ --include="*.ts"

# Find pattern across codebase with AST-aware tools (if available)
# e.g., ast-grep, semgrep, or comby
ast-grep --pattern 'console.log($MSG)' --lang typescript

Phase 2: Plan — Design the Transformation

  • Pre-flight check: Run the type checker / linter to capture baseline errors
  • Rename validation: Verify the symbol can be safely renamed (no conflicts)
  • Transformation plan: List each change with file, line, before/after
  • Test identification: Find tests covering the code being refactored

Phase 3: Execute — Apply Changes Safely

For renames (use IDE/editor capabilities when available):

# Using sed for simple renames
find src/ -name "*.ts" -exec sed -i '' 's/getUserData/fetchUserProfile/g' {} +

# Or use language-specific tools
# TypeScript: ts-morph, jscodeshift
# Python: rope, bowler
# Go: gorename

For pattern-based transformations:

# Using ast-grep (if installed)
ast-grep --pattern 'console.log($MSG)' --rewrite 'logger.info($MSG)' --lang typescript

# Using comby
comby 'console.log(:[msg])' 'logger.info(:[msg])' .ts

For structural changes (extract/move):

  • Create the new target (file, function, class)
  • Move the code
  • Update all references using LSP rename
  • Remove the old code
  • Verify no dangling references

Phase 4: Verify — TDD Confirmation

  • Type check: Run the project type checker — must be clean
   npx tsc --noEmit          # TypeScript
   mypy src/                  # Python
   go vet ./...               # Go
  • Build check: Run project build — must pass
  • Test check: Run test suite — all previously passing tests must still pass
  • Diff review: git diff to review the complete changes for unintended modifications

If any check fails:

  • Revert changes: git checkout -- .
  • Analyze the failure
  • Adjust approach and retry

Approach by Language

| Language | Rename Tool | Pattern Search | Type Check |

|----------|-------------|----------------|------------|

| TypeScript | ts-morph, jscodeshift | ast-grep, semgrep | tsc --noEmit |

| Python | rope, bowler | ast-grep, semgrep | mypy, pyright |

| Go | gorename, gopls | ast-grep, semgrep | go vet |

| Java | IntelliJ refactor, openrewrite | semgrep | javac |

| Rust | rust-analyzer | ast-grep | cargo check |

Anti-Patterns

  • Manual find-replace without verifying all references — misses dynamic usages
  • Skipping type check after rename — may introduce type errors
  • Not running tests after refactoring — behavior may have changed
  • Refactoring while fixing bugs — do one or the other, never both

Example

User: "Rename getUserData to fetchUserProfile across the project"

Output:

  • grep -rn finds 23 usages across 8 files
  • Applies rename using sed/jscodeshift across all locations
  • tsc --noEmit passes with no errors
  • npm test — 47 tests pass
  • git diff shows clean, focused changes

Inspired by: oh-my-opencode /refactor command

Other skills for the same job

different authors, same section of the catalogue
Receiving Code Review
by ZhanlinCui
×7

Use when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation

2k tokens
Requesting Code Review
by ZhanlinCui
×6

Use when completing tasks, implementing major features, or before merging to verify work meets requirements

2k tokens
Git Commit
by github
vendor ×3

Execute git commit with conventional commit message analysis, intelligent staging, and message generation. Use when user asks to commit changes, create a git commit, or mentions "/commit". Supports: (1) Auto-detecting type and scope from changes, (2) Generating conventional commit messages from diff, (3) Interactive commit with optional type/scope/description overrides, (4) Intelligent file staging for logical grouping

799 tokens
Github Code Review
by ComeOnOliver
×3

Comprehensive GitHub code review with AI-powered swarm coordination

13k tokens
Karpathy Guidelines
by hyyhf
×3

Behavioral guidelines to reduce common LLM coding mistakes. Use when writing, reviewing, or refactoring code to avoid overcomplication, make surgical changes, surface assumptions, and define verifiable success criteria.

629 tokens
Code Reviewer
by google-gemini
vendor ×2

Use this skill to review code. It supports both local changes (staged or working tree) and remote Pull Requests (by ID or URL). It focuses on correctness, maintainability, and adherence to project standards.

795 tokens
Agent MD Refactor
by softaworks
×2

Refactor bloated AGENTS.md, CLAUDE.md, or similar agent instruction files to follow progressive disclosure principles. Splits monolithic files into organized, linked documentation.

4k tokens
Commit Work
by softaworks
×2

Create high-quality git commits: review/stage intended changes, split into logical commits, and write clear commit messages (including Conventional Commits). Use when the user asks to commit, craft a commit message, stage changes, or split work into multiple commits.

2k tokens

How to use it

Copy the folder

Take arabelatso/lsp-refactoring from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

The agent identifies a skill by the name field in its header. Two skills with the same name cannot sit side by side — one of them will be ignored.

Install what it needs

The instructions reference npx. Without those the skill loads but fails at the first command.