refactor-clean

refactor-clean is a command for Claude Code from HermeticOrmus/LibreUIUX-Claude-Code. It costs 15 tokens per session (5,416 once invoked), scanned A, a copy of refactor-clean, MIT.

A code-refactoring command that examines code for duplication, overly complex structures, weak naming, tight coupling, and other maintainability problems, then suggests cleaner designs.

In plain words
What is it for?
Use it to simplify functions and classes, address SOLID design problems, remove dead or duplicated code, and improve performance.
Why use it?
It helps make existing code easier to change and understand while identifying design and performance issues that can cause future problems.

Command for Claude Code

Written for Claude Code: argument-hint in frontmatter.

Part of the code-refactoring plugin — 3 commands, 1 agent shipped together

Good fit Use it to simplify functions and classes, address SOLID design problems, remove dead or duplicated code, and improve performance.

Compare 6 commands from other repositories ↓
Install with agentmods
npx agentmods add commands/hermeticormus/libreuiux-claude-code/refactor-clean
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/HermeticOrmus/LibreUIUX-Claude-Code

Made for: Claude Code.

Or install code-refactoring, the plugin that ships this one along with the rest of its 3 commands, 1 agent.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for refactor-clean

README.md
[![agentmods](https://agentmods.dev/badge/commands/hermeticormus/libreuiux-claude-code/refactor-clean/github.svg)](https://agentmods.dev/commands/hermeticormus/libreuiux-claude-code/refactor-clean)
Your own site
<a href="https://agentmods.dev/commands/hermeticormus/libreuiux-claude-code/refactor-clean"><img src="https://agentmods.dev/badge/commands/hermeticormus/libreuiux-claude-code/refactor-clean/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for refactor-clean

Your own site · 80×15
<a href="https://agentmods.dev/commands/hermeticormus/libreuiux-claude-code/refactor-clean"><img src="https://agentmods.dev/badge/commands/hermeticormus/libreuiux-claude-code/refactor-clean.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 15 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 5,416 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin 95% copy Near-identical to another mod in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00015 $0.05416
Opus 5.5 $0.00006 $0.02166
Sonnet 5.5 $0.00003 $0.01083
Haiku 4.5 $0.00002 $0.00542

Measured 19d ago against content hash e10422a00e53, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

refactor-clean scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 19d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

Origin

This is a copy

95% identical to refactor-clean — 195 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

plugins/code-refactoring/commands/refactor-clean.md · 891 lines

How it starts

The opening of the file, as written. The whole thing — 891 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Refactor and Clean Code

You are a code refactoring expert specializing in clean code principles, SOLID design patterns, and modern software engineering best practices. Analyze and refactor the provided code to improve its quality, maintainability, and performance.

Context

The user needs help refactoring code to make it cleaner, more maintainable, and aligned with best practices. Focus on practical improvements that enhance code quality without over-engineering.

Requirements

$ARGUMENTS

Instructions

1. Code Analysis

First, analyze the current code for:

  • Code Smells

    • Long methods/functions (>20 lines)
    • Large classes (>200 lines)
    • Duplicate code blocks
    • Dead code and unused variables
    • Complex conditionals and nested loops
    • Magic numbers and hardcoded values
    • Poor naming conventions
    • Tight coupling between components
    • Missing abstractions
  • SOLID Violations

    • Single Responsibility Principle violations
    • Open/Closed Principle issues
    • Liskov Substitution problems
    • Interface Segregation concerns
    • Dependency Inversion violations
  • Performance Issues

    • Inefficient algorithms (O(n²) or worse)
    • Unnecessary object creation
    • Memory leaks potential
    • Blocking operations
    • Missing caching opportunities

2. Refactoring Strategy

Create a prioritized refactoring plan:

Immediate Fixes (High Impact, Low Effort)

  • Extract magic numbers to constants
  • Improve variable and function names
  • Remove dead code
  • Simplify boolean expressions
  • Extract duplicate code to functions

Method Extraction

# Before
def process_order(order):
    # 50 lines of validation
    # 30 lines of calculation
    # 40 lines of notification

# After
def process_order(order):
    validate_order(order)
    total = calculate_order_total(order)
    send_order_notifications(order, total)

Class Decomposition

  • Extract responsibilities to separate classes
  • Create interfaces for dependencies
  • Implement dependency injection
  • Use composition over inheritance

Read the full file on GitHub · 891 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 19d ago Changed · +5 lines · +15 tokens per session e10422a00e53
  2. 1mo ago First seen · 886 lines · 0 tokens per session scan A 0248be1656d7

Subscribe to this mod's changes

refactor-clean is a command published in the GitHub repository HermeticOrmus/LibreUIUX-Claude-Code (115 stars, last pushed 15d ago), licensed MIT. It adds 15 tokens to every session and 5,416 once invoked, about $0.0001 per session on Opus 5.5. A static security scan graded it A with 0 findings. It is 95% identical to refactor-clean, differing in 195 lines, and is treated as a copy.