agentleFS
looties-iolooties-io/looties-skills/code-cleanup/SKILL.md

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

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
  1. Distinctive:

    Use this skill to make existing code easier to read, safer to maintain, and more consistent with the surrounding project without changing …

    line 12
  2. Distinctive:

    Follow the repository's local conventions before generic style preferences.

    line 17
  3. Distinctive:

    Keep scope tight. Prefer recently changed files, staged hunks, or the specific files the user named.

    line 18
  4. Distinctive:

    Avoid cleanup that is only personal taste.

    line 21
  5. Distinctive:

    Staged cleanup: default when staged changes exist and the user asks for pre-commit cleanup.

    line 25
  6. Distinctive:

    Changed-file cleanup: use when there are no staged changes or the user asks for uncommitted work.

    line 26
  7. Distinctive:

    Targeted cleanup: use for explicit files, directories, symbols, or a commit SHA.

    line 27
  8. Distinctive:

    Full-file cleanup: use only when the user asks for a deeper pass.

    line 28
  9. Distinctive:

    Run or inspect git status, the relevant diff, and the touched file list.

    line 35
  10. Distinctive:

    Read nearby code to match naming, error handling, component structure, data flow, and abstraction style.

    line 37
  11. Distinctive:

    Do not refactor around an active suspected bug unless the user asks to fix it first.

    line 41
  12. Distinctive:

    Look for unclear names, avoidable nesting, duplicated logic with a shared concept, oversized functions, mixed abstraction levels, dead …

    line 45
  13. Distinctive:

    Prefer small batches grouped by dependency chain or file proximity.

    line 49
  14. Distinctive:

    Start with mechanical, low-risk changes before structural extraction or cross-module movement.

    line 50
  15. Distinctive:

    Keep public API and exported behavior stable unless the user authorized a broader refactor.

    line 51
  16. Distinctive:

    Run focused tests for touched behavior when possible.

    line 54
  17. Distinctive:

    Run type checks, lint, format, or pre-commit hooks when the project already defines them and they fit the touched scope.

    line 55
  18. Distinctive:

    If validation fails after cleanup, inspect whether the failure is related.

    line 56
  19. Distinctive:

    Use these questions on the changed behavior before creating another abstraction:

    line 64
  20. Distinctive:

    Remove dead code only with evidence from entrypoints, dynamic registration, public exports, generated references and external consumers.

    line 68
  21. Distinctive:

    Prefer duplication when extraction would hide simple logic or force unnecessary jumping between files.

    line 95
  22. Distinctive:

    Prefer explicit steps over compact chains when debugging or reviewing would be harder.

    line 96
  23. Distinctive:

    Keep an abstraction when it names a real concept, owns repeated behavior, or matches a project pattern.

    line 97
  24. Distinctive:

    If a proposed cleanup is not obviously better, leave it alone and mention it as a possible follow-up.

    line 99
  25. Distinctive:

    Do not modify test assertions just to make cleanup pass.

    line 107

“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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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 status before 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 --cached and 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 diff plus 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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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:

SignalPrefer
Vague names such as data, info, tmp, or resRename to communicate role or domain meaning
Deep nesting or arrow-shaped conditionalsGuard clauses, early returns, or clearer branching
Repeated logic with one real conceptExtract a function, constant, or helper with a meaningful name
Long function with separable responsibilitiesExtract cohesive blocks; keep call order readable
Dense one-liners or nested ternariesExplicit intermediate variables, if/else, or switch
Comments that restate codeRemove the comment or improve naming
Non-obvious business rule or magic valueAdd a short why-focused comment or named constant
Unused imports, variables, branches, or helpersRemove only when clearly unused and not part of a public surface
Function mutates and returns derived dataSplit command/query behavior when the split is natural
Boolean flag changes behaviorSplit 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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.