refactor-clean
Remove dead code, unused exports or dependencies, or duplicate implementations. Use for cleanup audits and safe deletion plans; not for adding features or ordinary refactoring.
- License 许可
- MIT
- 所属仓库
- xiaden/SkyScow
- 最近更新
- 2026-09-30
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- refactor-clean
- description
- Remove dead code, unused exports or dependencies, or duplicate implementations. Use for cleanup audits and safe deletion plans; not for adding features or ordinary refactoring.
02 资源文件 1
- 参考文档references/deletion-log.md3.5 KB
03 SKILL.md 正文
Refactor & Clean
Purpose: Systematically identify and remove dead code, unused exports, unused dependencies, and duplicates — with an audit trail and safe rollback at every step.
When to Use
Trigger conditions:
- Cleaning up a codebase after a large feature removal or migration
- Auditing unused npm dependencies or TypeScript exports
- Consolidating duplicate implementations across modules
- Preparing a repo for handoff, open-source release, or major refactor
- User mentions knip, depcheck, ts-prune, or dead code detection
Do NOT use this skill when:
- Actively developing a feature (cleanup mid-flight causes merge conflicts)
- Right before a production deployment (no time for rollback if a false positive bites)
- Test coverage is below ~60% (can't verify removals safely)
- Working in code you don't understand — research first, clean second
- The codebase has no build/lint pipeline (you can't verify removals)
Workflow
1. Analyze Phase
Run detection tools in parallel. Each tool has a different lens — use all three and cross-reference.
| Tool | What it finds | Key flags |
|---|---|---|
| knip | Unused files, exports, dependencies, types | --include exports,types to focus; --strict to catch re-exports |
| depcheck | Unused npm dependencies | --ignores=<pkg> for known dev-time-only deps |
| ts-prune | Unused TypeScript exports | -p tsconfig.json to scope; pipe through grep -v to exclude public API |
| eslint | Unused disable directives, variables | --report-unused-disable-directives |
npx knip --include exports,dependencies,files
npx depcheck
npx ts-prune -p tsconfig.json | grep -v "index.ts"
npx eslint . --report-unused-disable-directives --quiet
Gotchas:
- knip reports re-exports as unused even when consumed externally — verify against public API surface
- ts-prune can't see dynamic imports (
import()) orrequire()calls — grep for those separately - depcheck flags devDependencies used only in scripts (e.g.,
tsx,ts-node) — checkpackage.jsonscripts - Tools disagree on barrel files (
index.ts) — these are often false positives
2. Risk Assessment
Categorize each finding before removing:
| Risk level | Criteria | Action |
|---|---|---|
| SAFE | Unused export with zero internal/external imports; unused devDependency | Remove immediately |
| CAREFUL | Potentially used via dynamic import, reflection, or plugin registration | Grep for string references; check if registered in config |
| RISKY | Part of public API, shared utility, or barrel re-export | Do not remove without confirming external consumers |
For each item:
grep -rn "symbolName" src/— confirm zero live references- Check for dynamic imports:
grep -rn "import(.*symbolName" src/ - Check git history:
git log --oneline -5 -- path/to/file— understand why it exists - Verify it's not in the public API surface (check
exportsinpackage.json, README docs)
3. Remove Phase
Safe deletion order (each step verifiable independently):
- Unused imports —
eslint --fixor manual removal - Unused private functions — internal, no external risk
- Unused exported functions — after confirming zero consumers
- Unused types/interfaces — after confirming no type-only imports
- Unused files — last, after all their exports are confirmed dead
- Unused dependencies —
npm uninstall <pkg>(updatespackage.json+ lockfile)
After each removal:
npm run build && npm test && npm run lint
4. Consolidate Phase
For duplicate code found during analysis:
- Pick the winner — most feature-complete, best tested, most recently modified
- Update all imports to point at the winner
- Delete the duplicate
- Verify build + tests pass
- Log in DELETION_LOG.md
5. Verify Phase
Final gate before committing:
npm run build # Builds successfully
npm test # All tests pass
npm run lint # No new lint errors
npx knip # Re-run to confirm findings are resolved
Safety Checklist
Before removing anything:
- [ ] Detection tools run and findings categorized
- [ ] Grep confirms zero live references
- [ ] Dynamic imports checked
- [ ] Public API surface verified
- [ ] Backup branch created (
git checkout -b cleanup/dead-code-YYYY-MM-DD)
After each removal:
- [ ] Build succeeds
- [ ] Tests pass
- [ ] No new lint errors
- [ ] Committed with clear message (
chore: remove unused <thing>) - [ ] DELETION_LOG.md updated
Error Recovery
If something breaks after removal:
git revert HEAD && npm install && npm run build && npm test- Identify the failure — was it a dynamic import, tool false negative, or external consumer?
- Mark the item as "DO NOT REMOVE" in DELETION_LOG.md with the reason
- Fix forward with updated grep patterns (e.g., add the dynamic import pattern to your search)
References
- DELETION_LOG.md format and examples: See [
references/deletion-log.md](file:///home/opencode/.config/opencode/skills/refactor-clean/references/deletion-log.md)
04 同仓库更多 Skills
unquoted-colon
暂无简介
quoted-description
Use when a plain scalar contains a colon: like this one.
block-description
Use when a plain scalar contains a colon: like this one.
work-routing
Canonical authority for who owns the next unit of work — direct work versus delegation, task tiers, bounded localization, the Change DAG size threshold, R&D evaluation routing, progressive research escalation, researcher scope signals, and QA/support owner selection. Use before choosing execution, investigation, design, or QA ownership; do not use to construct dispatch prompts, handoff schemas, or Change DAG/DD tool operation.
update-docs
Update project documentation to match code changes — generate codemaps, refresh READMEs, detect doc/code drift using AST analysis. Use when updating documentation after code changes, generating codemaps, verifying doc accuracy, or detecting stale documentation. Do NOT use for writing API reference docs from scratch (use doc-coauthoring) or for creating new skill files (use making-editing-skills).
skill-loading-system
Explain or troubleshoot OpenCode skill discovery, loading, permissions, availability, or prompt injection.