skills/defrag/SKILL.md
Analyze code for refactoring opportunities and suggest the top 10 highest-value improvements. Use this whenever the user says `/defrag`, asks to refactor, clean up code, improve code quality, identify code smells, or wants a ranked list of code improvements. This skill is for analysis only unless the user explicitly asks to apply a specific suggestion.
npx skillsauth add hexbee/hello-skills defragInstall 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.
Use this skill to inspect one or more files, identify the highest-value refactoring opportunities, and present a ranked top 10 list with concrete code-level suggestions.
This skill is analysis-first. Do not apply edits unless the user explicitly switches from analysis to implementation.
scripts/git_hotspots.py for consistent counts.If the user did not specify files, use the most relevant local context you can discover from the conversation or repo state. If the scope is still ambiguous and a wrong guess would be misleading, ask for the file or directory to analyze.
Check for these opportunity types:
shorten_file: files over 300 lines that should be split into coherent unitsshorten_function: functions over 50 lines that should be decomposedreduce_nesting: nested conditionals that should become guard clauses or early returnsextract_function: repeated or complex logic that should move into a named helperrename_for_clarity: unclear names, overloaded names, or names that hide intentsimplify_conditionals: brittle or verbose branching that can be simplifiedextract_constants: magic strings, numbers, selectors, or thresholds that should become local constantsconsolidate_duplicates: duplicate logic that should be mergedmodernize_syntax: safe use of modern syntax such as destructuring or optional chainingavoid_globality: move global items closer to where they are usedoptimize_imports: remove unused imports and tighten import organizationremove_dead_code: identify unused code paths, stale helpers, or unreachable branchesadd_tests: call out risky logic with weak or missing coveragebreak_up_hotspots: inspect the last 30 days of git history and flag files changed more than 30 timesWhen git history is available:
If git history is unavailable, say so briefly and continue with static code analysis.
To collect hotspot data, you can run:
python skills/defrag/scripts/git_hotspots.py --repo . --days 30 --limit 5
Score each refactoring from 0 to 100 using this weighted model:
35%30%25%5%5%Use judgment, but keep scores internally consistent. High scores should correspond to changes that are both important and realistically actionable.
Follow this order:
scripts/git_hotspots.py: counts per-file churn from recent git history and returns a JSON summary for hotspot analysisevals/evals.json: starter prompts for validating trigger behavior and output structureagents/openai.yaml: UI-facing metadata and default invocation promptUse this exact structure for each ranked item:
{filepath}:{start_line}-{end_line}Before:
{current code snippet}
After:
{refactored code snippet}
After the ranked list, end with:
Found {N} refactoring opportunities. Top 10 shown with average score: {avg}
Then ask:
Would you like me to apply any of these? Say "apply #1" or "apply all".
Optimize for the highest-value improvements, not the largest number of comments.
A strong result:
Do not:
testing
Diagnose and fix Docker image pull failures on macOS with OrbStack, especially Docker Hub EOF/TLS/manifest errors caused by system proxies, Clash/CyberClash/Mihomo/Surge-style TUN mode, fake-ip DNS such as 198.18.0.x, or unstable registry access. Use when `docker pull` or `docker manifest inspect` fails with EOF, SSL_ERROR_SYSCALL, failed to fetch anonymous token, failed to resolve reference, failed to copy, or registry-1.docker.io/auth.docker.io connectivity confusion.
development
Generate and revise job resumes from raw notes, existing resumes, career histories, or profile snippets. Use when Codex needs to create, redesign, tighten, or review a resume/CV, especially for Chinese or English A4 resumes, PDF/HTML output, first-screen hiring signal, skill ordering, pagination balance, header/contact layout, or reframing an engineering background for AI-focused roles.
development
Convert a public webpage URL into Markdown and save it as a reusable `.md` file with the bundled script. Prefer `https://r.jina.ai/<url>` first, and only fallback to `https://markdown.new/` if `r.jina.ai` is unavailable. Use this whenever the user wants to turn a public webpage, article, documentation page, blog post, release note, or reference URL into Markdown for reading, archiving, summarizing, extraction, RAG prep, or downstream agent reuse, even if they do not explicitly mention markdown or saving a file.
tools
Design agent-usable SaaS tool systems using six reusable tool shapes (Search, Summarize, Draft, Update, Notify, Approve) plus connectors and policy guardrails. Use when turning SaaS features into reliable agent actions with clear contracts, permissions, audit trails, and approval gates.