refactor-agent

refactor-agent is a skill for Claude Code, Codex from chandrudp29/skillhub. It costs 32 tokens per session (1,321 once invoked), scanned A, original, MIT.

A guide for reorganising code while keeping its behaviour the same, such as splitting long functions or removing repeated code.

In plain words
What is it for?
Use it to extract functions, reduce complexity, remove duplication, improve names, and check tests before and after refactoring.
Why use it?
It reduces the risk of breaking software while making difficult code easier to understand and change.

Skill for Claude CodeCodex

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 skills/chandrudp29/skillhub/refactor-agent
Any agent
npx skills add chandrudp29/skillhub --skill refactor-agent
Clone the repo
git clone --depth 1 https://github.com/chandrudp29/skillhub

Made for: Claude Code, Codex.

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-agent

README.md
[![agentmods](https://agentmods.dev/badge/skills/chandrudp29/skillhub/refactor-agent.svg)](https://agentmods.dev/skills/chandrudp29/skillhub/refactor-agent)
Your own site
<a href="https://agentmods.dev/skills/chandrudp29/skillhub/refactor-agent"><img src="https://agentmods.dev/badge/skills/chandrudp29/skillhub/refactor-agent.svg" alt="Measured on agentmods" height="20"></a>
Per session 32 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,321 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.00032 $0.01321
Opus 5 $0.00016 $0.00660
Sonnet 5 $0.00006 $0.00264
Haiku 4.5 $0.00003 $0.00132

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

Security

Grade A, and why

refactor-agent 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.

skills/refactor-agent/SKILL.md · 201 lines

How it starts

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

Refactor Agent

Safe refactoring that improves code without breaking it. Tests before, tests after.

When to Use

  • "This function is too long"
  • "This code is hard to understand"
  • "There's too much duplication"
  • "Cyclomatic complexity is too high"
  • Before adding a feature to messy code

The Refactoring Rule

Never refactor and change behavior in the same commit.

Refactoring = same inputs, same outputs, better structure. If you're changing behavior, that's a different commit.

Before You Refactor

  1. Make sure tests exist. If they don't, write them first.
  2. Run the tests. They must be green before you start.
  3. Understand what the code does — don't refactor code you don't understand.
  4. Identify the specific smell you're fixing. Don't refactor everything at once.

The Six Most Valuable Refactors

1. Extract Function

When a function does more than one thing, or a block of code deserves a name:

# Before — what does this block do?
def process_order(order):
    total = 0
    for item in order.items:
        price = item.price
        if item.is_member:
            price = price * 0.9
        if item.quantity > 10:
            price = price * 0.85
        total += price * item.quantity
    
    if total > 1000:
        order.shipping = 0
    else:
        order.shipping = 15
    
    order.total = total + order.shipping
    order.status = "confirmed"
    send_confirmation_email(order)

# After — each piece has a name
def process_order(order):
    order.total = calculate_order_total(order)
    order.shipping = calculate_shipping(order.total)
    order.status = "confirmed"
    send_confirmation_email(order)

def calculate_item_price(item) -> float:
    price = item.price
    if item.is_member:
        price *= 0.9
    if item.quantity > 10:
        price *= 0.85
    return price * item.quantity

def calculate_order_total(order) -> float:
    return sum(calculate_item_price(item) for item in order.items)

def calculate_shipping(order_total: float) -> float:
    return 0 if order_total > 1000 else 15

Read the full file on GitHub · 201 lines

Files

What ships with it

1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

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 · 201 lines · 32 tokens per session scan A 110c052d057f

Subscribe to this mod's changes

refactor-agent is a skill published in the GitHub repository chandrudp29/skillhub (13 stars, last pushed 2mo ago), licensed MIT. It adds 32 tokens to every session and 1,321 once invoked, about $0.0002 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-30.

Related

Other skills, from other repositories

aposd-audit

Quantitative design audit. Counts pass-throughs, duplication, doc gaps, naming issues, and exceptions across 5 dimensions, scored 0-4.

mhenke/john-ousterhout-skills · 36 tokens

refactoring-patterns

Use this skill when improving existing code without changing its behavior. It defines when and how to refactor safely.

ApexIQ/skillsmith · 27 tokens

evolutionary-naming

Use when refactoring code with poor names, when asked to improve naming, or when a user struggles to name a class/method/variable. Symptoms include -Manager/-Util suffixes, single-letter variables, process/handle/do verbs, primitive obsession, god methods with multiple responsibilities. Two modes — audit (broad scan…

kawasima/evolutionary-naming · 86 tokens

software-code-refactoring

Improve production code quality while preserving all existing test behavior. Commonly used for the Refactor phase of TDD red-green-refactor, but applicable to any codebase with tests. Use when production code works but needs cleanup — reducing duplication, improving naming, simplifying complexity, aligning with…

stencila/stencila · 102 tokens

simplify-codebase

Simplification audit or authorized codebase simplification whose stated objective is to remove accidental complexity. Use for evidence-backed deletion or consolidation of dead code, duplicate state, redundant APIs or layers, ownerless abstractions, obsolete compatibility or design records, and over-engineering in any…

tt-a1i/simplify-codebase · 93 tokens

cyclomatic-complexity

Refactor code to reduce cyclomatic complexity so it stays readable, maintainable, and aligned with the long-term vision of the codebase, not just optimized for AI comprehension. Use whenever the user asks to refactor, simplify, clean up, or review code quality; mentions complexity, maintainability, readability…

saurabhkumar8112/cyclomatic-complexity-skill · 103 tokens