Code Refactor
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.
Run in terminal (recommended)
claude mcp add code-refactor npx -- -y @trustedskills/code-refactor
Or manually add to ~/.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
Grepto find occurrences of patterns within files, with options for displaying context lines and line numbers. - Edit Integration: Utilizes
Editwith thereplace_all=trueflag 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
oldNametonewName" - "replace all
getUserDatawithfetchUserData" - "convert
var count = 0tolet 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
Greppatterns.
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 Hub | Pass |
| Socket | Pass |
| Snyk | Pass |
🌐 Community
Passed automated security scans.