clean:refactor

clean:refactor is a command for coding agents from ruslan-korneev/claude-plugins. It costs 17 tokens per session (821 once invoked), scanned A, original, MIT.

A command that suggests a specific refactoring—a change to code structure that preserves its behavior—for a named code smell, such as a long method, duplicate code, or deeply nested conditions.

In plain words
What is it for?
Use it to improve a specified file by extracting methods or classes, grouping long parameter lists, reducing nesting, and addressing other listed code smells.
Why use it?
It turns a vague code-quality concern into a concrete improvement suggestion. The command reads the relevant code and maps common problems to established refactorings.

Command

Part of the python plugin — 4 skills, 10 commands, 1 agent, 1 hook shipped together

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.

agentmods
npx agentmods add commands/ruslan-korneev/claude-plugins/clean-refactor
Clone the repo
git clone --depth 1 https://github.com/ruslan-korneev/claude-plugins

Or install python, the plugin that ships this one along with the rest of its 4 skills, 10 commands, 1 agent, 1 hook.

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 clean:refactor

README.md
[![agentmods](https://agentmods.dev/badge/commands/ruslan-korneev/claude-plugins/clean-refactor.svg)](https://agentmods.dev/commands/ruslan-korneev/claude-plugins/clean-refactor)
Your own site
<a href="https://agentmods.dev/commands/ruslan-korneev/claude-plugins/clean-refactor"><img src="https://agentmods.dev/badge/commands/ruslan-korneev/claude-plugins/clean-refactor.svg" alt="Measured on agentmods" height="20"></a>
Per session 17 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 821 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found 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 $0.00017 $0.00821
Opus 5 $0.00009 $0.00411
Sonnet 5 $0.00003 $0.00164
Haiku 4.5 $0.00002 $0.00082

Measured 3d ago against content hash 62c51868ca28, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

clean:refactor 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 3d 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.

plugins/python/commands/clean-refactor.md · 184 lines

How it starts

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

Command /clean:refactor

Suggest a specific refactoring for the indicated problem.

Instructions

Step 1: Determine refactoring type

Smell Refactoring
long-method Extract Method
long-params Introduce Parameter Object
god-class Extract Class
primitive Replace Primitive with Object
switch Replace Conditional with Polymorphism
duplicate Extract Method / Pull Up Method
feature-envy Move Method
deep-nesting Replace Nested Conditional with Guard Clauses

Step 2: Read the code

Read the specified file and find the problematic area.

Step 3: Suggest refactoring

Extract Method (long-method)
# Before
def process_order(order):
    # Validate (10 lines)
    ...
    # Calculate (15 lines)
    ...
    # Save (10 lines)
    ...

# After
def process_order(order):
    validate_order(order)
    totals = calculate_totals(order)
    save_order(order, totals)

def validate_order(order): ...
def calculate_totals(order): ...
def save_order(order, totals): ...
Introduce Parameter Object (long-params)
# Before
def create_user(name, email, age, city, country, phone): ...

# After
@dataclass
class CreateUserRequest:
    name: str
    email: str
    age: int
    city: str
    country: str
    phone: str

def create_user(request: CreateUserRequest): ...
Extract Class (god-class)
# Before
class UserManager:
    def create_user(self): ...
    def send_email(self): ...
    def generate_report(self): ...

# After
class UserRepository:
    def create(self): ...

class EmailService:
    def send(self): ...

class ReportGenerator:
    def generate(self): ...
Replace Primitive with Object
# Before
email: str = "[email protected]"

# After
@dataclass(frozen=True)
class Email:
    value: str

    def __post_init__(self):
        if "@" not in self.value:
            raise ValueError(f"Invalid email: {self.value}")

Read the full file on GitHub · 184 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. 3d ago First seen · 184 lines · 17 tokens per session scan A 62c51868ca28

Subscribe to this mod's changes

clean:refactor is a command published in the GitHub repository ruslan-korneev/claude-plugins (4 stars, last pushed 6mo ago), licensed MIT. It adds 17 tokens to every session and 821 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.