code-refactoring

code-refactoring is a skill for Claude Code, Codex from myths-labs/muse. It costs 33 tokens per session (1,266 once invoked), scanned A, original, MIT.

A refactoring guide for improving code structure and maintainability without changing what the code does.

In plain words
What is it for?
Use it to simplify legacy code, reduce complexity, extract focused functions, and decide when refactoring is safe.
Why use it?
It helps identify common code problems, such as long methods or deeply nested conditions, while preserving existing behavior.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it to simplify legacy code, reduce complexity, extract focused functions, and decide when refactoring is safe.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/myths-labs/muse/code-refactoring
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.

Any agent
npx skills add myths-labs/muse --skill code-refactoring
Clone the repo
git clone --depth 1 https://github.com/myths-labs/muse

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 code-refactoring

README.md
[![agentmods](https://agentmods.dev/badge/skills/myths-labs/muse/code-refactoring/github.svg)](https://agentmods.dev/skills/myths-labs/muse/code-refactoring)
Your own site
<a href="https://agentmods.dev/skills/myths-labs/muse/code-refactoring"><img src="https://agentmods.dev/badge/skills/myths-labs/muse/code-refactoring/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 code-refactoring

Your own site · 80×15
<a href="https://agentmods.dev/skills/myths-labs/muse/code-refactoring"><img src="https://agentmods.dev/badge/skills/myths-labs/muse/code-refactoring.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 33 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,266 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. Third-party audits
  • NVIDIA SkillSpector warn 7 Sept 2026
SkillSpector: 1 finding, up to high

These are SkillSpector’s own severities. On a checked sample its high-severity flags on skills were ~96% false positives — a documented command, a public API, a “never do X” rule — so we show them as a caution to read, not a verdict. Why →

  • high Rogue Agent · line 113
    Skill modifies its own code, configuration, or behavior at runtime. Self-modification enables an agent to escalate privileges, disable safety constraints, or install persistent backdoors.
    Fix: Prevent the skill from modifying its own code, SKILL.md, or configuration files. Treat skill files as read-only at runtime.
How audits are shown
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.1 $0.00033 $0.01266
Opus 5.5 $0.00013 $0.00506
Sonnet 5.5 $0.00007 $0.00253
Haiku 4.5 $0.00003 $0.00127

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

Security

Grade A, and why

code-refactoring 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 3mo 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/toolkit/code-refactoring/SKILL.md · 210 lines

How it starts

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

Code Refactoring

Refactoring Principles

When to Refactor

  • Before adding new features (make change easy, then make easy change)
  • After getting tests passing (red-green-refactor)
  • When you see code smells
  • During code review feedback

When NOT to Refactor

  • Without tests covering the code
  • Under tight deadlines with no safety net
  • Code that will be replaced soon
  • When you don't understand what the code does

Common Code Smells

Long Methods

// BEFORE: Method doing too much
function processOrder(order: Order) {
  // 100 lines of validation, calculation, notification, logging...
}

// AFTER: Extract into focused methods
function processOrder(order: Order) {
  validateOrder(order);
  const total = calculateTotal(order);
  saveOrder(order, total);
  notifyCustomer(order);
}

Deeply Nested Conditionals

// BEFORE: Arrow code
function getDiscount(user: User, order: Order) {
  if (user) {
    if (user.isPremium) {
      if (order.total > 100) {
        if (order.items.length > 5) {
          return 0.2;
        }
      }
    }
  }
  return 0;
}

// AFTER: Early returns (guard clauses)
function getDiscount(user: User, order: Order) {
  if (!user) return 0;
  if (!user.isPremium) return 0;
  if (order.total <= 100) return 0;
  if (order.items.length <= 5) return 0;
  return 0.2;
}

Primitive Obsession

// BEFORE: Primitives everywhere
function createUser(name: string, email: string, phone: string) {
  if (!email.includes('@')) throw new Error('Invalid email');
  // more validation...
}

// AFTER: Value objects
class Email {
  constructor(private value: string) {
    if (!value.includes('@')) throw new Error('Invalid email');
  }
  toString() { return this.value; }
}

function createUser(name: string, email: Email, phone: Phone) {
  // Email is already validated
}

Feature Envy

// BEFORE: Method uses another object's data extensively
function calculateShipping(order: Order) {
  const address = order.customer.address;
  const weight = order.items.reduce((sum, i) => sum + i.weight, 0);
  const distance = calculateDistance(address.zip);
  return weight * distance * 0.01;
}

// AFTER: Move method to where the data is
class Order {
  calculateShipping() {
    return this.totalWeight * this.customer.shippingDistance * 0.01;
  }
}

Read the full file on GitHub · 210 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. 3mo ago First seen · 210 lines · 33 tokens per session scan A db4d95074849

Subscribe to this mod's changes

code-refactoring is a skill published in the GitHub repository myths-labs/muse (39 stars, last pushed 24d ago), licensed MIT. It adds 33 tokens to every session and 1,266 once invoked, about $0.0001 per session on Opus 5.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

code-refactoring compared with skills from other repositories

code-refactoring next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
code-refactoringmyths-labs/museSkill3924d agoMITA33Claude Code, Codex
mex-statechartmex-memory/mexSkill1.8kyesterdayMITA73Codex
contextstream-coachcontextstream/mcp-serverSkill49todayMITA103Claude Code, Codex
agent-coachcontextstream/mcp-serverSkill49todayMITA106Claude Code, Codex
engramPatdolitse/piia-engramSkill1663d agoAGPL-3.0A175Claude Code
context-receiptscaioribeiroclw-pixel/pluribusSkill154mo agoMITA33Claude Code, Codex
evidence-attestationcaioribeiroclw-pixel/pluribusSkill154mo agoMITA32Claude Code, Codex