refactor-clean
Skill15 starsChanged 7 months agoMITView on GitHub
Use when cleaning up Salesforce Apex or LWC code. Dead code removal and consolidation using PMD and Salesforce Code Analyzer for safe cleanup.
12 other projects use a version of this.
Adopted by
Most recently taken up by
- dzhng/jevgreptheir own version, first seen Nov 7, 2026
- dzhng/skillstheir own version, first seen Nov 4, 2026
- Buddhilive/buddhi-clitheir own version, first seen Nov 1, 2026
- dzhng/duet-agenttheir own version, first seen Oct 30, 2026
- drvoss/everything-copilot-clitheir own version, first seen Oct 26, 2026
- julianromli/ai-skillstheir own version, first seen Oct 25, 2026
Used with
Projects with it also use close-spec, design-with-images and 10 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
dzhngSkillclose-spec
When a spec under specs/<feature>/ is done shipping (a write-spec build, or any planned task that produced a spec), archive it to specs/done/ and rewrite it from a build-plan into a durable rationale — the why, the principles, the invariants — pointing back to the real code for the how. Use when implementation has landed and the plan no longer matches what shipped, or the user says a feature/spec is finished. Pairs with [write-spec](../write-spec/SKILL.md) (the plan this closes) and [review](../review/SKILL.md) (run before closing).
Also in 5 projects that use this
dzhngSkilldesign-with-images
Explore UI and visual design with image generation, then iterate the real implementation against the user-selected concept. Use when brainstorming visual directions, offering mockup variants, or implementing an approved generated design; do not stop at the mockups or the first code approximation.
Also in 5 projects that use this
transitive-bullshitSkillcompare-screenshots
Compare screenshots against the intended design, distinguishing approved references from historical baselines. Use for iterative implementation matching, before/after visual review, objective image telemetry, or checking a lone capture for flat, empty, or badly framed content.
Also in 5 projects that use this
LucasMatuszewskiSkillaudit-agents
Audit and maintain agent configuration files (.claude/agents, AGENTS.md, CLAUDE.md, agent-memory). Checks for duplicates, outdated info, naming conflicts, wrong technical facts, and files over 200 lines. Fixes all issues and commits.
Also in 5 projects that use this
wolverin0Skillaudit-decisions
Standardize remediation decisions, baseline-policy entries, and legal-review banners for accepted, deferred, or policy-blocked audit findings.
Also in 4 projects that use this
rhnfzlSkillexplore-unknowns
Walk the user through mapping the unknowns of a task before, during, and after they build it, and hand them a four-quadrant map (settled ground, open decisions, taste, and landmines) they keep. Reach for this eagerly whenever a request is ambiguous or underspecified, the codebase or domain is unfamiliar, the user will "know it when they see it", a reference implementation must be understood before porting, a build-queue or architecture-changing task is about to start, a mid-build deviation needs capturing, or a finished change needs buy-in or verified understanding before merge. Trigger even when the skill is not named: "do a blindspot pass", "find my unknown unknowns", "interview me about this change", "brainstorm the approach for a task I am about to build", "help me scope this", "what am I missing here", "plan this before I build", "I know nothing about X in this codebase". When a territory profile is present it reads memory and the graph first and feeds the map into the build pipeline; without one it degrades to a plain general map. Not for trivial or mechanical tasks with clear acceptance criteria, single-fact lookups, pure debugging of a known symptom, or pure code review, those have their own tools. Do not use it to run the build itself; the map is the deliverable and implementation remains a separate task, whether it has not started or is already underway.
Also in 5 projects that use this
- +6 more from dzhng
Other versions12 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 12
- dzhng/jevgrep★ 3.2ksame name
- dzhng/skills★ 1.5ksame name
- julianromli/ai-skills★ 215same name
- dzhng/yap★ 112same name
- dzhng/duet-agent★ 55same name
- drvoss/everything-copilot-cli★ 48same name
- bis-code/claude-toolkit★ 8same name
- PatriotAgenticLLC/better_claude_skillz★ 3same name
- peopleforrester/claude-dotfiles★ 3same name
- QuentinHsu/skills★ 2same name
2 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository58 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- asideSkill
- checkpointSkill
- configure-sccSkill
- continuous-agent-loopSkill
- mcp-server-patternsSkill
- model-routeSkill
- prompt-optimizerSkill
- resume-sessionSkill
- save-sessionSkill
- search-firstSkill
- security-scanSkill
- sessionsSkill
- sf-2gp-security-reviewSkill
- sf-agentforce-developmentSkill
- sf-agentforce-mcp-actionsSkill
- sf-apex-async-patternsSkill
- sf-apex-best-practicesSkill
- sf-apex-constraintsSkill
- sf-apex-cursorSkill
- sf-apex-enterprise-patternsSkill
- sf-apex-testingSkill
- sf-api-designSkill
- sf-approval-processesSkill
- sf-aura-developmentSkill
- sf-build-fixSkill
- sf-cli-referenceSkill
- sf-data-modelingSkill
- sf-debuggingSkill
- sf-deployment-constraintsSkill
- sf-deploymentSkill
- sf-devops-ci-cdSkill
- sf-docs-lookupSkill
- sf-e2e-testingSkill
- sf-experience-cloudSkill
- sf-flow-developmentSkill
- sf-governor-limitsSkill
- sf-harness-auditSkill
- sf-helpSkill
- sf-integrationSkill
- sf-lwc-constraintsSkill
- sf-lwc-developmentSkill
- sf-lwc-testingSkill
- sf-metadata-managementSkill
- sf-platform-events-cdcSkill
- sf-quickstartSkill
- sf-security-constraintsSkill
- sf-securitySkill
- sf-soql-constraintsSkill
- sf-soql-optimizationSkill
- sf-tdd-workflowSkill
- sf-testing-constraintsSkill
- sf-trigger-constraintsSkill
- sf-trigger-frameworksSkill
- sf-visualforce-developmentSkill
- strategic-compactSkill
- update-docsSkill
- update-platform-docsSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
19 rules. 0 are common, 16 are distinctive, and 3 are very specific to this project.
0
Common
Most of the 12 edited versions we read keep these.
16
Distinctive
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 10
Remove dead code and consolidate duplicates safely.
- Distinctive: line 14
When cleaning up unused Apex classes, methods, or LWC components
- Distinctive: line 15
When consolidating duplicate utility methods across multiple service classes
- Distinctive: line 16
When preparing a codebase for a security review or AppExchange submission
- Distinctive: line 17
When Salesforce Code Analyzer or PMD reports high-severity findings that need cleanup
- Distinctive: line 18
When reducing technical debt by removing commented-out code and unreferenced classes
- Distinctive: line 70
Before removing any CAUTION or DANGER items:
- Distinctive: line 91
Never remove without checking:
- Distinctive: line 103
Delete the dead code
- Distinctive: line 106
If tests fail, revert the deletion immediately
- Distinctive: line 110
After dead code removal, look for consolidation opportunities:
- Distinctive: line 114
Update all callers to use the shared implementation
- Distinctive: line 115
Run full test suite after each consolidation
- Very specific: line 119
Always create a checkpoint before starting: /checkpoint refactor-start
- Distinctive: line 120
Remove one item at a time — never batch deletions
- Distinctive: line 121
Run tests after each removal
- Very specific: line 122
Never remove @AuraEnabled, @InvocableMethod, or global without verifying all callers
- Distinctive: line 123
Check metadata references (Flows, Process Builders, FlexiPages) before deleting any public method
- Distinctive: line 124
Keep a log of what was removed and why
“Common” is measured: kept by at least 6 in 10 of the 12 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Refactor Clean — Dead Code Removal and Consolidation
Remove dead code and consolidate duplicates safely. Uses Salesforce Code Analyzer (sf code-analyzer run) for detection when available, falls back to manual analysis.
When to Use
- When cleaning up unused Apex classes, methods, or LWC components
- When consolidating duplicate utility methods across multiple service classes
- When preparing a codebase for a security review or AppExchange submission
- When Salesforce Code Analyzer or PMD reports high-severity findings that need cleanup
- When reducing technical debt by removing commented-out code and unreferenced classes
Workflow
Step 1 — Detect Dead Code
Option A: Salesforce Code Analyzer (preferred)
sf code-analyzer run --target force-app --format table
sf code-analyzer run --target force-app --format json | jq '.[] | select(.severity <= 2)'Option B: Manual analysis
# Find Apex classes with no references.
# Uses sfdx-project.json packageDirectories to find all source paths,
# rather than hardcoding force-app/main/default.
# Note: This heuristic searches source files for class name strings. Results may
# be incomplete — classes can be referenced dynamically (Type.forName), from
# managed packages, external integrations, or metadata not in source control.
# Always verify before deleting.
SRC_DIRS=$(node -e "
const p = require('./sfdx-project.json');
console.log(p.packageDirectories.map(d => d.path).join(' '));
" 2>/dev/null || echo "force-app")
for dir in $SRC_DIRS; do
find "$dir" -name "*.cls" -not -name "*Test*" | while read cls; do
name=$(basename "$cls" .cls)
# Note: Use word-boundary matching for precise results to avoid partial name matches
refs=$(grep -rlw "$name" $SRC_DIRS --include="*.cls" --include="*.trigger" --include="*.js" --include="*.xml" 2>/dev/null | grep -v "$cls" | wc -l)
if [ "$refs" -eq 0 ]; then echo "UNREFERENCED: $name"; fi
done
done
# Find unused methods within a class (private methods not called internally)
grep -n "private.*void\|private.*String\|private.*List\|private.*Map" <file>.clsStep 2 — Classify Safety
Categorize each finding before removing anything:
| Safety Level | Criteria | Action |
| SAFE | Private methods with no internal callers, unreferenced private classes, commented-out code blocks | Remove immediately |
| CAUTION | Public methods not referenced in code (may be called by Flows, Process Builders, or external systems) | Check metadata references first |
| DANGER | global methods, @AuraEnabled, @InvocableMethod, @InvocableVariable, @RemoteAction, @HttpGet/Post, managed package components | Do NOT remove without explicit verification |
Step 3 — Check Metadata References
Before removing any CAUTION or DANGER items:
# Check if a method is referenced in Flows
grep -rl "ClassName.MethodName" force-app/main/default/flows/
# Check if a class is used in Process Builders
grep -rl "ClassName" force-app/main/default/workflows/
# Check if a class is referenced in Custom Metadata
grep -rl "ClassName" force-app/main/default/customMetadata/
# Check if an LWC component is used in FlexiPages
grep -rl "c-component-name" force-app/main/default/flexipages/
# Check if a class is referenced in page layouts
grep -rl "ClassName" force-app/main/default/layouts/Step 4 — Managed Package Considerations
Never remove without checking:
@AuraEnabledmethods — may be called by LWC/Aura components not in your source@InvocableMethod— may be called by Flows you can't see in source controlglobalmethods — may be called by subscriber orgs or external packageswebServicemethods — may be called by external integrations- Methods referenced in Permission Sets or Custom Permissions
Step 5 — Remove One at a Time
For each SAFE item:
- Delete the dead code
- Run tests:
sf apex run test --test-level RunLocalTests --wait 15 - Verify deployment:
sf project deploy start --dry-run --wait 10 - If tests fail, revert the deletion immediately
Step 6 — Consolidate Duplicates
After dead code removal, look for consolidation opportunities:
- Identify similar methods across classes (same logic, different names)
- Extract shared logic into a utility/service class
- Update all callers to use the shared implementation
- Run full test suite after each consolidation
Safety Rules
- Always create a checkpoint before starting:
/checkpoint refactor-start - Remove one item at a time — never batch deletions
- Run tests after each removal
- Never remove
@AuraEnabled,@InvocableMethod, orglobalwithout verifying all callers - Check metadata references (Flows, Process Builders, FlexiPages) before deleting any public method
- Keep a log of what was removed and why
Examples
refactor-clean Remove unused Apex classes and dead methods from force-app/
refactor-clean Consolidate duplicate utility methods across AccountService and ContactService
refactor-clean Find and remove unreferenced LWC components
refactor-clean Run Salesforce Code Analyzer and clean up all HIGH severity PMD findingsDoes 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.

