code-cleanup-guardian
Skill0 starsChanged 3 months agoMITView on GitHub
Safely refactor and clean up code without breaking existing functionality. Use when doing any code cleanup, refactoring, formatting, removing dead code, or restructuring files. Prevents regression by enforcing incremental changes and mandatory testing.
- Deletes or force-pushes
In this repository44 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- a11y-auditSkill
- ai-engineerSkill
- api-clientSkill
- changelog-enforcerSkill
- code-reviewerSkill
- contract-testSkill
- db-migrateSkill
- dep-auditSkill
- devops-automatorSkill
- env-configSkill
- error-observabilitySkill
- frontend-designSkill
- git-commit-helperSkill
- github-issues-managerSkill
- git-issue-syncSkill
- git-protocolSkill
- handoffSkill
- incident-responseSkill
- init-projectSkill
- karpathy-guidelinesSkill
- market-researcherSkill
- parallel-agent-git-isolationSkill
- product-strategistSkill
- pr-workflowSkill
- rapid-builderSkill
- release-managerSkill
- resumeSkill
- scrutinizeSkill
- shadcn-uiSkill
- skill-builderSkill
- sprint-plannerSkill
- state-machine-diagramsSkill
- state-managementSkill
- surveySkill
- system-architectSkill
- tech-docsSkill
- unstuckSkill
- ux-design-systemSkill
- ux-researchSkill
- webapp-testingSkill
- web-dev-fundamentalsSkill
- workflow-optimizerSkill
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 7 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 13
Before starting, classify the cleanup scope:
- Distinctive: line 29
Test after each caller redirect
- Distinctive: line 30
Remove original only after all callers migrated and tests pass
- Distinctive: line 36
Check string literals, config files, and dynamic references
- Distinctive: line 41
Check for reflection, dynamic dispatch, or string-based references
- Distinctive: line 42
Check test files — remove test coverage for dead code too
- Distinctive: line 43
Remove in a dedicated commit with clear message
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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
Code Cleanup Guardian
Core safety protocol is in ~/.claude/rules/code-cleanup-safety.md. This skill adds tactical guidance.
Refactoring Assessment
Before starting, classify the cleanup scope:
| Scope | Risk | Approach |
| Formatting only | Low | Autoformat, single commit, verify no logic diff |
| Rename/move | Medium | Update all references, verify with grep, test |
| Extract function/module | Medium | Ensure identical behavior, compare outputs |
| Change data flow | High | Write characterization tests first, then refactor |
| Remove feature/code path | High | Prove zero references, check feature flags, test |
Refactoring Workflows
Extract & Split
- Identify the boundary (function, class, module)
- Copy to new location — do NOT cut yet
- Redirect callers to new location one at a time
- Test after each caller redirect
- Remove original only after all callers migrated and tests pass
Safe Rename
grep -r "oldName" src/— count all references- Rename with IDE refactor tool or find-and-replace
grep -r "oldName" src/— confirm zero references remain- Check string literals, config files, and dynamic references
- Test
Dead Code Removal
grep -rn "targetName" --include="*.ts" --include="*.tsx" --include="*.js" --include="*.jsx" --include="*.py" --include="*.php" .(grep does not expand{a,b}braces inside--include)- Check for reflection, dynamic dispatch, or string-based references
- Check test files — remove test coverage for dead code too
- Remove in a dedicated commit with clear message
Recovery Protocol
| Situation | Action |
| Tests fail after one commit | git revert HEAD |
| Tests fail after multiple commits | git log --oneline, find last green, git revert HEAD~N..HEAD |
| Uncertain what broke | git bisect start, git bisect bad, git bisect good <known-good> |
| Everything is broken | Last resort, and only after the user confirms: it discards all local commits and uncommitted work. Show git status and git log origin/main..HEAD first, then git reset --hard origin/main |
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.

