Code Refactor

🌐Community
by mhattingpete · vlatest · Repository

Automatically improves existing Python code for readability, efficiency, and maintainability using proven refactoring patterns.

Install on your platform

We auto-selected Claude Code based on this skill’s supported platforms.

1

Run in terminal (recommended)

terminal
claude mcp add code-refactor npx -- -y @trustedskills/code-refactor
2

Or manually add to ~/.claude/settings.json

~/.claude/settings.json
{
  "mcpServers": {
    "code-refactor": {
      "command": "npx",
      "args": [
        "-y",
        "@trustedskills/code-refactor"
      ]
    }
  }
}

Requires Claude Code (claude CLI). Run claude --version to verify your install.

About This Skill

What it does

This skill automatically improves existing Python code for readability, efficiency, and maintainability using proven refactoring patterns. It systematically refactors code across multiple files, intelligently switching between native tools (Grep and Edit) and a code-execution mode to optimize token usage. For 10 or more files, the skill leverages the code-execution skill to achieve significant token savings compared to traditional methods.

When to use it

This skill is helpful in these scenarios:

  • Renaming identifiers (variables, functions) within a codebase.
  • Replacing specific patterns of code with alternatives.
  • Updating calls to functions or APIs.
  • Converting deprecated coding patterns to newer ones.
  • Performing large-scale refactoring tasks across many files.

Key capabilities

  • Systematic Refactoring: Applies changes consistently across multiple files.
  • Mode Switching: Automatically selects between native tools and code execution for efficiency (10+ files).
  • Grep Integration: Uses Grep to find occurrences of patterns within files, with options for displaying context lines and line numbers.
  • Edit Integration: Utilizes Edit with the replace_all=true flag to replace all instances of a pattern in a file.
  • Token Optimization: Significantly reduces token usage when refactoring large codebases (up to 90% savings).

Example prompts

Here are some example prompts you can use:

  • "rename oldName to newName"
  • "replace all getUserData with fetchUserData"
  • "convert var count = 0 to let count = 0"

Tips & gotchas

  • Planning is Key: The skill recommends finding all instances of a pattern first, reviewing their context, and considering edge cases (strings, comments) before making changes.
  • Test After Refactoring: It's highly recommended to run tests after refactoring to ensure the code still functions correctly.
  • Case Sensitivity: Be explicit about case sensitivity when defining Grep patterns.

Tags

🛡️

TrustedSkills Verification

Unlike other registries that point to live repositories, TrustedSkills pins every skill to a verified commit hash. This protects you from malicious updates — what you install today is exactly what was reviewed and verified.

Security Audits

Gen Agent Trust HubPass
SocketPass
SnykPass

Details

Version
vlatest
License
Author
mhattingpete
Installs
44

🌐 Community

Passed automated security scans.