code-cleanup
Skill1 starsChanged 49 days agoMITView on GitHub
Safe, behavior-preserving code cleanup and refactoring workflow for recently changed, staged, or user-selected code. Use when asked to clean up code before a commit, improve readability, simplify/refactor without changing behavior, apply project coding conventions, review staged diffs for maintainability issues, or organize small validation-backed cleanup batches.
8 other projects use a version of this.
Adopted by
Most recently taken up by
- TidalPaladin/skillstheir own version, first seen Nov 8, 2026
- edloidas/skillstheir own version, first seen Nov 1, 2026
- snappedly/skillstheir own version, first seen Oct 13, 2026
- CorySchulz/skillstheir own version, first seen Oct 13, 2026
- hempq/symfony-claude-codetheir own version, first seen Oct 9, 2026
- evanpersinger/claude-skillstheir own version, first seen Aug 16, 2026
Other versions8 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 8
- jenreh/appkit★ 4same name
- CorySchulz/skills★ 2same name
- edloidas/skills★ 2same name
- snappedly/skills★ 2same name
- hempq/symfony-claude-code★ 1same name
- TidalPaladin/skills★ 1same name
- evanpersinger/claude-skills★ 0same name
- szmidtpiotr/ClaudeCode-Tools★ 0same name
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 repository21 other files it gives its agents.
- a11y-auditSkill
- agentic-peer-reviewSkill
- changelog-to-videoSkill
- cinematic-hyperframesSkill
- endpoint-surface-mapSkill
- field-web-performanceSkill
- french-accountingSkill
- google-ai-seo-fundamentalsSkill
- google-ai-seo-optimizationSkill
- ground-truthSkill
- harness-testingSkill
- impossible-by-designSkill
- legacy-code-reviewSkill
- merchant-feed-auditSkill
- merge-time-ci-economicsSkill
- postgres-privilege-auditSkill
- provider-canarySkill
- repo-wide-dead-code-sweepSkill
- security-hardeningSkill
- website-ai-agent-readinessSkill
- youtube-video-editingSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
25 rules. 0 are common, 25 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 8 edited versions we read keep these.
25
Distinctive
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 12
Use this skill to make existing code easier to read, safer to maintain, and more consistent with the surrounding project without changing …
- Distinctive: line 17
Follow the repository's local conventions before generic style preferences.
- Distinctive: line 18
Keep scope tight. Prefer recently changed files, staged hunks, or the specific files the user named.
- Distinctive: line 21
Avoid cleanup that is only personal taste.
- Distinctive: line 25
Staged cleanup: default when staged changes exist and the user asks for pre-commit cleanup.
- Distinctive: line 26
Changed-file cleanup: use when there are no staged changes or the user asks for uncommitted work.
- Distinctive: line 27
Targeted cleanup: use for explicit files, directories, symbols, or a commit SHA.
- Distinctive: line 28
Full-file cleanup: use only when the user asks for a deeper pass.
- Distinctive: line 35
Run or inspect git status, the relevant diff, and the touched file list.
- Distinctive: line 37
Read nearby code to match naming, error handling, component structure, data flow, and abstraction style.
- Distinctive: line 41
Do not refactor around an active suspected bug unless the user asks to fix it first.
- Distinctive: line 45
Look for unclear names, avoidable nesting, duplicated logic with a shared concept, oversized functions, mixed abstraction levels, dead …
- Distinctive: line 49
Prefer small batches grouped by dependency chain or file proximity.
- Distinctive: line 50
Start with mechanical, low-risk changes before structural extraction or cross-module movement.
- Distinctive: line 51
Keep public API and exported behavior stable unless the user authorized a broader refactor.
- Distinctive: line 54
Run focused tests for touched behavior when possible.
- Distinctive: line 55
Run type checks, lint, format, or pre-commit hooks when the project already defines them and they fit the touched scope.
- Distinctive: line 56
If validation fails after cleanup, inspect whether the failure is related.
- Distinctive: line 64
Use these questions on the changed behavior before creating another abstraction:
- Distinctive: line 68
Remove dead code only with evidence from entrypoints, dynamic registration, public exports, generated references and external consumers.
- Distinctive: line 95
Prefer duplication when extraction would hide simple logic or force unnecessary jumping between files.
- Distinctive: line 96
Prefer explicit steps over compact chains when debugging or reviewing would be harder.
- Distinctive: line 97
Keep an abstraction when it names a real concept, owns repeated behavior, or matches a project pattern.
- Distinctive: line 99
If a proposed cleanup is not obviously better, leave it alone and mention it as a possible follow-up.
- Distinctive: line 107
Do not modify test assertions just to make cleanup pass.
“Common” is measured: kept by at least 6 in 10 of the 8 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
Code Cleanup
Use this skill to make existing code easier to read, safer to maintain, and more consistent with the surrounding project without changing what it does.
Core Rules
- Preserve behavior. Treat bug fixes, feature changes, and public API changes as separate work unless the user explicitly includes them.
- Follow the repository's local conventions before generic style preferences. Read relevant project instructions, nearby code, package scripts, and config files before editing.
- Keep scope tight. Prefer recently changed files, staged hunks, or the specific files the user named.
- Protect user work. Inspect
git statusbefore edits and do not revert or overwrite unrelated changes. - Validate proportionally. Run the most relevant existing tests, type checks, linters, or formatters for touched code. If a validation command is unavailable or too broad for the change, say so.
- Avoid cleanup that is only personal taste. A change should improve intent, reduce real complexity, remove duplication, or align with established project patterns.
Scope Modes
- Staged cleanup: default when staged changes exist and the user asks for pre-commit cleanup. Review
git diff --cachedand edit only files represented in the staged work unless the user allows propagation. - Changed-file cleanup: use when there are no staged changes or the user asks for uncommitted work. Review
git diffplus named files or recent edits. - Targeted cleanup: use for explicit files, directories, symbols, or a commit SHA. Keep edits inside that target unless a dependency update is required.
- Full-file cleanup: use only when the user asks for a deeper pass. Keep behavior stable and validate more broadly.
State the selected scope briefly before editing when it affects risk or validation.
Workflow
- Discover context
- Run or inspect
git status, the relevant diff, and the touched file list. - Identify language, framework, package manager, and available commands from files such as
package.json,pyproject.toml,go.mod,Cargo.toml,Makefile, CI config, and repo docs. - Read nearby code to match naming, error handling, component structure, data flow, and abstraction style.
- Run or inspect
- Screen exclusions
- Skip generated, vendored, third-party, minified, migration-generated, or scheduled-for-deletion code.
- Do not refactor around an active suspected bug unless the user asks to fix it first.
- Flag high-churn or cross-branch conflicts when visible, but do not block small safe edits solely on churn.
- Find cleanup candidates
- Look for unclear names, avoidable nesting, duplicated logic with a shared concept, oversized functions, mixed abstraction levels, dead code, stale comments, nested ternaries, flag arguments, and error handling tangled with primary logic.
- Note bug risks separately from cleanup opportunities. Do not silently fold bug fixes into cleanup.
- Batch edits
- Prefer small batches grouped by dependency chain or file proximity.
- Start with mechanical, low-risk changes before structural extraction or cross-module movement.
- Keep public API and exported behavior stable unless the user authorized a broader refactor.
- Validate
- Run focused tests for touched behavior when possible.
- Run type checks, lint, format, or pre-commit hooks when the project already defines them and they fit the touched scope.
- If validation fails after cleanup, inspect whether the failure is related. Fix cleanup-caused failures; report unrelated pre-existing failures clearly.
- Report
- Summarize what changed, what was intentionally left alone, and which validation commands ran.
- Mention any bugs or follow-up cleanup candidates that were not addressed.
Structural quality before style
Use these questions on the changed behavior before creating another abstraction:
- Identify the existing owner of each business rule and trace its actual callers. Search for semantic duplicates and unfinished migrations, not only identical lines. Reuse that owner; do not create a parallel service, validator, retry loop or source of truth.
- Trace the blast radius through direct and dynamic consumers, persistence, configuration and deployment units. Verify the affected boundary rather than merely the edited helper.
- Remove dead code only with evidence from entrypoints, dynamic registration, public exports, generated references and external consumers. Static analyzer output alone is a lead.
- Reject speculative adapters, one-use wrappers, redundant validation and broad exception handling that hides failures. Keep validation at real trust boundaries; a fallback must preserve the explicit contract and expose failure.
- Derive expected behavior from requirements and contracts. A test that reproduces the implementation's mistake is not a regression check. For a confirmed defect, show the check failing before the fix and passing afterwards.
- Report the canonical owner, affected consumers, verified simplification and remaining uncertainty. Fewer lines alone are not evidence of better behavior.
For an entire cohort, use agentic-peer-review; for recurring structural defects, use impossible-by-design. Keep this pass proportional to the actual change.
Transformation Guide
Apply these only when they make the code easier to understand in context:
| Signal | Prefer |
Vague names such as data, info, tmp, or res | Rename to communicate role or domain meaning |
| Deep nesting or arrow-shaped conditionals | Guard clauses, early returns, or clearer branching |
| Repeated logic with one real concept | Extract a function, constant, or helper with a meaningful name |
| Long function with separable responsibilities | Extract cohesive blocks; keep call order readable |
| Dense one-liners or nested ternaries | Explicit intermediate variables, if/else, or switch |
| Comments that restate code | Remove the comment or improve naming |
| Non-obvious business rule or magic value | Add a short why-focused comment or named constant |
| Unused imports, variables, branches, or helpers | Remove only when clearly unused and not part of a public surface |
| Function mutates and returns derived data | Split command/query behavior when the split is natural |
| Boolean flag changes behavior | Split into named functions when call sites become clearer |
Conflict Rules
- Correctness beats clarity; clarity beats cleverness; local convention beats generic advice.
- Prefer duplication when extraction would hide simple logic or force unnecessary jumping between files.
- Prefer explicit steps over compact chains when debugging or reviewing would be harder.
- Keep an abstraction when it names a real concept, owns repeated behavior, or matches a project pattern.
- Inline an abstraction when its name merely repeats the implementation.
- If a proposed cleanup is not obviously better, leave it alone and mention it as a possible follow-up.
Validation Heuristics
- For purely mechanical edits, a focused type check, lint, or affected test can be enough.
- For structural refactors, run affected tests plus the relevant type/import checks.
- For cross-module changes, validate all known consumers and check for stale imports or circular dependencies where tooling exists.
- For hot paths, large loops, rendering code, parsers, and data transformations, avoid extraction or allocation changes unless the readability gain is worth the performance risk.
- Do not modify test assertions just to make cleanup pass. Add or adjust tests only when exposing an extracted unit or preserving behavior more directly.
Anti-Patterns
- Refactoring without understanding the current behavior.
- Mixing unrelated formatting churn into logic cleanup.
- Renaming symbols for preference rather than clarity.
- Introducing a new abstraction for one small call site.
- Removing duplication that is only coincidentally similar.
- Compacting code until the reader must mentally expand it.
- Touching unrelated files to make the diff look cleaner.
- Continuing after cleanup-caused validation failures without investigating.
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.

