refactor-audit
Skill1 starsChanged 9 months agoMITView on GitHub
Audit a codebase for refactoring opportunities across all packages/sections. Spawns parallel refactor subagents per section, collects suggestions without executing, then presents a ranked plan for approval. Use when the user asks to "audit for refactors", "refactoring suggestions", "code quality review", "refactor plan", "find refactoring opportunities", or "what should we clean up".
In this repository9 other files it gives its agents.
- bug-bash-updateSkill
- ci-cd-pipelineSkill
- claudemd-auditorSkill
- docs-consolidatorSkill
- ralphSkill
- reflectSkill
- setup-workflowSkill
- skill-reviewerSkill
- smoke-testSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
13 rules. About 0 are common, 12 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈12
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 16
Read the project root: package.json, workspace configs (pnpm-workspace.yaml, lerna.json), Cargo.toml workspaces, monorepo packages/ or …
- Distinctive: line 30
If the user provided an explicit section breakdown in their prompt, use that instead of auto-discovering.
- Distinctive: line 65
After all subagents complete:
- Distinctive: line 101
Wait for user approval. The user may:
- Distinctive: line 104
Ask for more detail on specific suggestions
- Distinctive: line 111
After approval, for each approved suggestion:
- Distinctive: line 115
After each subagent completes, run the section's test suite to verify behavior is preserved.
- Distinctive: line 116
If tests fail, revert and flag the suggestion as blocked.
- Distinctive: line 118
Commit approved changes in logical groups (one commit per category or per section, not one per suggestion).
- Distinctive: line 122
Behavior preservation is paramount: Every suggestion must maintain identical external behavior.
- Distinctive: line 123
Don't refactor what you don't understand: If the subagent can't determine why code exists, flag it as "needs investigation" rather than …
- Distinctive: line 124
Respect existing patterns: If the codebase consistently uses a pattern (even if suboptimal), don't suggest changing isolated instances.
- Distinctive: line 125
No style wars: Don't suggest reformatting, reordering imports, or changing naming conventions unless there's a concrete readability or …
≈ “Common” is an estimate: at least 1 in 5 of the 372,429 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Refactor Audit
Analyze a codebase for refactoring opportunities across all packages. Designed to be non-destructive — collects and ranks suggestions without executing any changes.
Workflow
Phase 1: Discover project sections
Scan the repository to identify distinct sections of the codebase. Each section should be a coherent unit (package, service, module) with its own domain.
- Read the project root:
package.json, workspace configs (pnpm-workspace.yaml,lerna.json),Cargo.tomlworkspaces, monorepopackages/orapps/directories, top-level folders with their own build configs. - For each discovered section, note:
- Root path
- Language/framework
- Approximate size (file count)
- Key focus areas for refactoring (infer from the section's domain — e.g., contracts care about gas optimization, frontends care about component decomposition)
- Build a section table:
| Section | Root path | Language | Focus areas |
|---------|-----------|----------|-------------|
| ... | ... | ... | ... |If the user provided an explicit section breakdown in their prompt, use that instead of auto-discovering.
Phase 2: Parallel refactor analysis
Spawn one refactor subagent per section in parallel. Each subagent receives:
- The section's root path and focus areas from Phase 1
- The analysis-only instructions below
Subagent instructions (include verbatim in each subagent prompt):
Analyze the code in
{root_path}for refactoring opportunities. Do NOT make any changes — analysis only.For each suggestion, provide:
- What: File(s) and specific code to change (include line numbers)
- Why: How this improves the code (readability, performance, maintainability, correctness)
- Size:
quick-win(< 30 min),moderate(1-2 hrs), orsignificant(half-day+)- Risk:
low(safe rename/extract),medium(logic restructure, needs tests),high(behavioral change, cross-cutting)- Category: One of:
dead-code,duplication,extraction,simplification,naming,type-safety,performance,error-handling,organizationFocus areas for this section: {focus_areas}
Prioritize suggestions that:
- Remove dead code or unused imports
- Eliminate duplication (especially copy-pasted logic)
- Extract reusable functions from repeated patterns
- Simplify overly complex conditionals or nested logic
- Improve type safety (remove
any, add missing types)Flag any cross-package opportunities — shared logic that could move to a common package, inconsistent patterns across packages, or duplicated utilities.
Output your suggestions as a structured list grouped by category.
Phase 3: Consolidate and rank
After all subagents complete:
- Deduplicate: Merge suggestions that touch the same code or propose the same change from different angles.
- Group cross-cutting suggestions: Collect cross-package opportunities into their own section.
- Filter: Drop suggestions that are:
- Cosmetic-only with no readability benefit
- High-risk with low payoff
- Likely to cause merge conflicts with active work (check recent branches if possible)
- Rank remaining suggestions by impact-to-effort ratio within each size category:
- Quick wins first (highest value per minute)
- Then moderate suggestions
- Then significant suggestions
Phase 4: Present the plan
Present the consolidated suggestions to the user:
## Refactor Audit Report
### Quick Wins
- [ ] **[category]** `path/to/file.ts:L42` — [what to change]. *Why:* [reason]. Risk: [low/medium].
### Moderate
- [ ] **[category]** `path/to/file.ts:L100-150` — [what to change]. *Why:* [reason]. Risk: [low/medium/high].
### Significant
- [ ] **[category]** `path/to/file.ts` + `other/file.ts` — [what to change]. *Why:* [reason]. Risk: [medium/high].
### Cross-Package Opportunities
- [ ] [description of shared pattern or utility that spans packages]
### Skipped
- [suggestion]: [why it was dropped]Wait for user approval. The user may:
- Approve all suggestions
- Approve a subset (by checking items)
- Ask for more detail on specific suggestions
- Reject the audit entirely
Do not execute any refactors until the user explicitly approves.
Phase 5: Execute approved refactors
After approval, for each approved suggestion:
- Spawn a
refactorsubagent (orgeneral-purposefor cross-package changes) to implement the change. - Group related suggestions into a single subagent call when they touch the same files.
- After each subagent completes, run the section's test suite to verify behavior is preserved.
- If tests fail, revert and flag the suggestion as blocked.
Commit approved changes in logical groups (one commit per category or per section, not one per suggestion).
Guidelines
- Behavior preservation is paramount. Every suggestion must maintain identical external behavior. If a suggestion might change behavior, it must be flagged as high-risk.
- Don't refactor what you don't understand. If the subagent can't determine why code exists, flag it as "needs investigation" rather than suggesting removal.
- Respect existing patterns. If the codebase consistently uses a pattern (even if suboptimal), don't suggest changing isolated instances. Either suggest a codebase-wide migration or leave it alone.
- No style wars. Don't suggest reformatting, reordering imports, or changing naming conventions unless there's a concrete readability or correctness benefit.
- Test coverage matters. Suggestions affecting untested code should be flagged as higher risk. Consider suggesting tests as a prerequisite.
- Cross-package suggestions need extra scrutiny. Moving code between packages affects build order, dependencies, and deployment. Always flag these as
significantsize minimum.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

