skills/optimize-python/SKILL.md
Reviews Python code and applies performance optimizations drawn from a 23-pattern reference (data structures, loops, strings, memory, profiling, and more). Use when the user asks to "optimize this Python code", "make this Python faster", "apply Python performance improvements", or "review Python for performance". Also invoke automatically after writing non-trivial Python code. Do NOT use for debugging logic errors, explaining code, or writing new Python from scratch. Always run refactor-python on the same code first — do not invoke this skill if refactor-python has not been applied yet.
npx skillsauth add armandli/get-skilled optimize-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.
Before proceeding, confirm that refactor-python has already been applied to the
target code in this conversation or session.
If there is clear evidence that refactor-python was run (e.g., the user
mentioned it, a Refactor Report is visible in the conversation, or utility files
exist under utils/), proceed to Step 1.
If there is no evidence that refactor-python was run, stop and notify the
user:
"The
optimize-pythonskill should be run afterrefactor-pythonhas been applied to the same code. Please run/refactor-python [path]first, then re-invoke this skill."
Do not proceed with any optimization until the user confirms that refactoring is complete or explicitly waives the prerequisite.
If $ARGUMENTS is provided, use it as the target path. Otherwise, optimize the
Python code most recently written or discussed in the conversation.
.py files recursively (skip __pycache__, .venv, venv, site-packages)Scan each file for the signals listed in references/optimization-patterns.md.
Classify every finding as:
| Class | Meaning | Action | |-------|---------|--------| | Auto | Safe, mechanical, non-breaking transformation | Apply directly | | Suggest | Architectural or structural change; requires user judgment | Report, do not apply |
Auto-apply threshold: only transform code when you are certain the new form is semantically equivalent. When in doubt, classify as Suggest.
For each Auto finding:
Never auto-apply:
__slots__ (changes class interface)itertools refactors (may change iterator exhaustion semantics)sys.intern (pins objects; requires hot-path confirmation)try/except blocks where exception type mattersAfter all files are processed, output a summary:
## Optimization Report
### Applied (N changes)
- <file>:<line> — <pattern name>: <one-line description of what changed>
### Suggested (N items)
- <file>:<line> — <pattern name>: <why + recommended action>
### Skipped
- <any patterns not found or not applicable, and why>
Keep descriptions concise. For Suggest items, include a short code snippet showing the recommended form when it aids clarity.
bisect, math, collections, itertools), add it to the import block at
the top of the file and mention it in the reportAfter the skill's primary task completes, run (record both the dependency and this skill):
python3 ${PWD}/.claude/skills/skill-stat/scripts/record-stat.py "refactor-python"
python3 ${PWD}/.claude/skills/skill-stat/scripts/record-stat.py "optimize-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 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.