refactoring

refactoring is a skill for Claude Code from asgarovf/locusai. It costs 31 tokens per session (1,441 once invoked), scanned A, original, MIT.

A code-cleanup guide for improving structure and readability while keeping the software’s behavior unchanged. Refactoring includes techniques such as splitting large functions and removing duplicated logic.

In plain words
What is it for?
Use it to reduce duplication, simplify large functions or classes, improve readability, reorganize modules, and prepare code for new features.
Why use it?
It provides a safer way to clean up difficult code by requiring tests before and after each change.

Skill for Claude Code

Written for Claude Code: allowed-tools in frontmatter.

Good fit Use it to reduce duplication, simplify large functions or classes, improve readability, reorganize modules, and prepare code for new features.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/asgarovf/locusai/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 asgarovf/locusai --skill refactoring
Clone the repo
git clone --depth 1 https://github.com/asgarovf/locusai

Made for: Claude Code.

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 refactoring

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

Your own site · 80×15
<a href="https://agentmods.dev/skills/asgarovf/locusai/refactoring"><img src="https://agentmods.dev/badge/skills/asgarovf/locusai/refactoring.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 31 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,441 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 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.00031 $0.01441
Opus 5.5 $0.00012 $0.00576
Sonnet 5.5 $0.00006 $0.00288
Haiku 4.5 $0.00003 $0.00144

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

Security

Grade A, and why

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 1mo 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/refactoring/SKILL.md · 215 lines

How it starts

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

Refactoring

When to use this skill

  • Code is hard to read or understand
  • Duplicated logic across multiple places
  • Functions or classes are too large
  • Adding a feature requires touching too many files
  • Code smells identified during review
  • Preparing code for a new feature

Golden rule

Refactoring must not change behavior. Tests should pass before and after. If no tests exist, write them first.

# Run tests before starting
npm test  # or pytest, go test, etc.
# Make refactoring changes
# Run tests after every change
npm test

Common refactoring patterns

Extract function

When a block of code does one distinct thing:

// Before
function processOrder(order: Order) {
  // validate
  if (!order.items.length) throw new Error('Empty order');
  if (order.items.some(i => i.quantity <= 0)) throw new Error('Invalid quantity');
  if (!order.customerId) throw new Error('No customer');

  // calculate total
  let total = 0;
  for (const item of order.items) {
    total += item.price * item.quantity;
  }
  const tax = total * 0.1;
  const finalTotal = total + tax;

  // save
  db.save({ ...order, total: finalTotal });
}

// After
function validateOrder(order: Order): void {
  if (!order.items.length) throw new Error('Empty order');
  if (order.items.some(i => i.quantity <= 0)) throw new Error('Invalid quantity');
  if (!order.customerId) throw new Error('No customer');
}

function calculateTotal(items: OrderItem[]): number {
  const subtotal = items.reduce((sum, i) => sum + i.price * i.quantity, 0);
  return subtotal * 1.1; // includes 10% tax
}

function processOrder(order: Order) {
  validateOrder(order);
  const total = calculateTotal(order.items);
  db.save({ ...order, total });
}

Replace conditional with polymorphism

// Before: switch on type
function calculateShipping(order: Order): number {
  switch (order.shippingType) {
    case 'standard': return order.weight * 1.5;
    case 'express': return order.weight * 3.0 + 10;
    case 'overnight': return order.weight * 5.0 + 25;
    default: throw new Error('Unknown shipping type');
  }
}

// After: strategy pattern
const shippingStrategies: Record<string, (weight: number) => number> = {
  standard: (weight) => weight * 1.5,
  express: (weight) => weight * 3.0 + 10,
  overnight: (weight) => weight * 5.0 + 25,
};

function calculateShipping(order: Order): number {
  const strategy = shippingStrategies[order.shippingType];
  if (!strategy) throw new Error('Unknown shipping type');
  return strategy(order.weight);
}

Read the full file on GitHub · 215 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. 1mo ago First seen · 215 lines · 31 tokens per session scan A d7b74ef53d3d

Subscribe to this mod's changes

refactoring is a skill published in the GitHub repository asgarovf/locusai (23 stars, last pushed 7mo ago), licensed MIT. It adds 31 tokens to every session and 1,441 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

Other skills, from other repositories

refactoring-patterns

Apply safe refactoring patterns to improve code structure without changing behavior. Use when cleaning up code, reducing technical debt, or improving maintainability.

summarybotng/summarybot-ng · 33 tokens

refactoring-workflow

Improve the structure of existing code without changing its behaviour, in small verified steps under a green test suite. Use when the user asks to refactor, clean up, restructure or simplify code, wants to reduce duplication or coupling, is preparing a codebase for a feature it cannot currently accommodate, or when…

personamanagmentlayer/pcl · 83 tokens

code-quality-review

A code-review guide for judging whether software stays easy to understand, change, test, and extend.

bahayonghang/my-ai-cli-toolkit · 149 tokens

code-refactor

A guide for changing existing code while keeping its observable behavior the same. It covers tasks such as splitting files, extracting methods, renaming, removing unused code, and reducing duplication.

bahayonghang/my-ai-cli-toolkit · 110 tokens

arch-optimize

A software architecture review workflow that scans a codebase for structural risks and measures code quality. It checks issues such as overly complex code, repeated knowledge, changes spreading across many files, circular dependencies, and distorted domain models.

bfxh/arch-optimize · 114 tokens

refactor-agent

Safe, systematic code refactoring — extract functions, reduce complexity, eliminate duplication, improve naming. Use when improving code structure without changing behavior.

chandrudp29/skillhub · 32 tokens