skills/refactor-python/SKILL.md
Scans a Python codebase for duplicate or near-duplicate logic patterns across functions, classes, and files, then extracts those patterns into typed utility classes in a shared module. Use when the user asks to "refactor this Python code", "find duplicate logic", "extract shared utilities", "apply DRY to Python", "deduplicate Python code", or "find repeated patterns in Python". Groups extracted helpers by the object type they operate on (strings, numbers, dates, collections, etc.). Do NOT use for performance optimization (use optimize-python), for debugging logic errors, or for explaining code. Do NOT extract code that appears only once. Run this skill before optimize-python.
npx skillsauth add armandli/get-skilled refactor-pythonInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
If $ARGUMENTS is provided, use it as the target path. Otherwise, scan the
Python code most recently written or discussed in the conversation.
.py files recursively__pycache__, .venv, venv, site-packagestest_*.py, *_test.py, tests/ directory)
unless the user explicitly includes themRead all target files and search for:
Minimum threshold:
Classify every finding as:
| Class | Meaning | Action | |-------|---------|--------| | Auto | Safe mechanical extraction; all occurrences are semantically equivalent | Extract and replace | | Suggest | Needs judgment — structural change, uncertain equivalence, or side-effect concern | Report only, do not apply |
Auto-extraction threshold: only extract when you are certain every occurrence has the same return type, the same side-effect profile, and would behave identically when replaced by a call to the new utility. When in doubt, classify as Suggest.
For each finding, assign:
StringUtils, RateCalculator, DateUtils, CollectionUtils,
Validators, SerializationUtils)def line with parameters replacing
every varying constant or value (e.g., def strip_prefix(text: str, prefix: str) -> str)Group all findings by operand type to determine which utility files to create or update.
For each operand type group that has ≥ 1 Auto finding:
<project_root>/utils/<type>_utils.py
(e.g., utils/string_utils.py, utils/numeric_utils.py)utils/ directory does not exist, create itOne function per distinct logical operation. Do not merge unrelated helpers into a single function.
For each Auto finding:
import for the new utility at the top of every modified source file
(use absolute import from project root if possible)After all files are processed, output a structured summary:
## Refactor Report
### Extracted (N utilities created/updated)
- utils/<file>.py — <ClassName>.<method>: extracted from <file1>:<line>, <file2>:<line>, ...
### Replaced (N call sites updated)
- <file>:<line> — replaced with <ClassName>.<method>(...)
### Suggested (N items — not applied)
- <file>:<line> — <description>: <why it qualifies> — Recommended: <proposed function signature>
### Skipped
- <any patterns considered but not extracted, and why>
Keep descriptions concise. For Suggest items, include a short code snippet showing the recommended extracted form when it aids clarity.
try/except semantics — if a call site is inside a try/except
that depends on the exact exception type raised by the duplicated code,
classify as Suggest instead of Autoself attributes into a standalone utility unless the attribute is passed as
an explicit parameter to the utility functionAfter the skill's primary task completes, run:
python3 ${PWD}/.claude/skills/skill-stat/scripts/record-stat.py "refactor-python"
tools
--- name: update-readme description: Updates a project README.md with build instructions, unit test instructions, and a mermaid architecture diagram. Use when a project README needs to be created or refreshed. Trigger phrases: "update readme", "generate readme", "create readme", "refresh readme docs". Emphasizes project interfaces, extension points, and customization hooks in the diagram — not concrete implementations. Do NOT use for documentation sites, wikis, or non-project READMEs. argument-h
business
--- name: skill-stat description: Records skill usage statistics and issue reports into .claude/skill-stats.md. Increments the Uses count for a skill name, and optionally logs an issue report that increments the Issues count and appends a row to the Issue Reports table. Use when tracking how often a skill is invoked, when a user reports a problem with a skill, or when another skill needs to log its own usage. Trigger phrases: "record skill stat", "log skill usage", "report skill issue". Do NOT u
testing
--- name: revert description: Reverts ALL git changes in the working directory: staged changes, unstaged modifications, and new untracked files. Use when user asks to "revert all changes", "undo all changes", "discard all changes", "reset all git changes", or "clean working directory". Do NOT use for reverting a specific file or a specific commit — those need targeted git commands. disable-model-invocation: true --- Revert all git changes in the working directory. This is destructive and cannot
tools
Scans a C++ codebase for duplicate or near-duplicate logic patterns across .cpp and .h files, then extracts them into reusable utility functions in a shared utils/ directory. Use when the user asks to "refactor this C++ code", "find duplicate logic in C++", "extract shared C++ utilities", "apply DRY to C++", "deduplicate C++ code", or "find repeated patterns in C++". Groups extracted helpers by the object type they operate on (strings, numbers, containers, etc.). Template functions are placed in .h headers only; non-template utilities get a .h declaration and a .cpp definition. Do NOT use for performance optimization, debugging logic errors, code formatting (use format-cpp), or explaining code. Do NOT extract code that appears only once. Run this skill before format-cpp.