refactoring

A process for reorganising code while keeping its existing behaviour. Refactoring means improving the internal structure without intentionally changing what the program does.

In plain words
What is it for?
Use it to split up large functions, remove duplicated code, simplify complex conditions, shorten parameter lists, and improve how code is organised.
Why use it?
It reduces the risk of breaking working code during cleanup or restructuring. The process uses tests, dependency checks, and small changes to provide evidence that behaviour was preserved.

Skill for Claude CodeCodex

Part of the agents-atlas plugin — 24 skills 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 skills/avinashp/agentsatlas/refactoring
Any agent
npx skills add AvinashP/AgentsAtlas --skill refactoring
Clone the repo
git clone --depth 1 https://github.com/AvinashP/AgentsAtlas

Made for: Claude Code, Codex.

Or install agents-atlas, the plugin that ships this one along with the rest of its 24 skills.

Per session 28 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,215 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.00028 $0.01215
Opus 5 $0.00014 $0.00607
Sonnet 5 $0.00006 $0.00243
Haiku 4.5 $0.00003 $0.00121

Measured 3d ago against content hash 7a6f29596d88, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, 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 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/refactoring/SKILL.md · 240 lines

How it starts

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

Refactoring Skill

Restructure code safely while preserving behavior.

Workflow

1. Verify Test Coverage

Before refactoring, ensure tests exist:

# Run existing tests
npm test
pytest
go test ./...

If no tests cover the code:

  1. Write characterization tests first
  2. These capture current behavior (even if buggy)
  3. Then refactor with confidence

2. Understand Current Structure

Map the code:

  • What are the dependencies?
  • Who calls this code?
  • What does it depend on?
  • What's the data flow?
# Find usages
grep -r "functionName" --include="*.ts"

# Find dependencies
grep -r "import.*from.*module" --include="*.ts"

3. Plan the Refactoring

Identify the target state:

  • What's the problem with current code?
  • What's the desired structure?
  • What's the smallest step toward that?

Choose your approach:

Situation Approach
Large function Extract methods
Duplicated code Extract shared function
Complex conditionals Replace with polymorphism
Long parameter list Introduce parameter object
Feature envy Move method to data's class
Data clump Extract class

4. Execute in Small Steps

The safe refactoring cycle:

1. Make ONE small change
2. Run tests
3. Commit if green
4. Repeat

Never skip steps:

  • Don't combine multiple refactorings
  • Don't "fix bugs" while refactoring
  • Don't add features while refactoring

5. Verify Behavior Preserved

# Run full test suite
npm test

# Check for regressions
npm run test:e2e

# Manual smoke test if needed

Quick Reference

Safe Refactorings (Automated)

Most IDEs can do these automatically:

Refactoring Shortcut (VS Code)
Rename F2
Extract function Ctrl+Shift+R
Extract variable Ctrl+Shift+R
Inline variable Ctrl+Shift+R
Move to file Drag in explorer

Common Patterns

Extract Function
// Before
function processOrder(order) {
  // validate
  if (!order.items.length) throw new Error('Empty order');
  if (!order.customer) throw new Error('No customer');

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

  // apply discount
  if (order.coupon) {
    total *= (1 - order.coupon.discount);
  }

  return { ...order, total };
}

// After
function processOrder(order) {
  validateOrder(order);
  const total = calculateTotal(order);
  return { ...order, total };
}

function validateOrder(order) {
  if (!order.items.length) throw new Error('Empty order');
  if (!order.customer) throw new Error('No customer');
}

function calculateTotal(order) {
  const subtotal = order.items.reduce(
    (sum, item) => sum + item.price * item.quantity,
    0
  );
  return order.coupon
    ? subtotal * (1 - order.coupon.discount)
    : subtotal;
}

Read the full file on GitHub · 240 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 · 240 lines · 28 tokens per session scan A 7a6f29596d88

Subscribe to this mod's changes

refactoring is a skill published in the GitHub repository AvinashP/AgentsAtlas (7 stars, last pushed 3mo ago), licensed MIT. It adds 28 tokens to every session and 1,215 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.

Related

Other skills, from other repositories

audit-agents-skills

Audit Claude Code agents, skills, and commands for quality and production readiness. Use when evaluating skill quality, checking production readiness scores, or comparing agents against best-practice templates.

FlorianBruniaux/claude-code-plugins · 41 tokens

eval-agents

Audit Claude Code agents defined in .claude/agents/ for description specificity, model tier appropriateness, tools scoping, and system prompt quality. Detects dispatch ambiguity between agents, flags over-permissive tool grants, and checks for human-in-the-loop patterns that break programmatic orchestration. Use when…

FlorianBruniaux/claude-code-plugins · 93 tokens

eval-hooks

Audit Claude Code hooks defined in settings.json files for validity, performance safety, and correctness. Resolves each command against the filesystem, checks exit-code strategy for blocking hooks, flags missing timeouts, and reviews interactive vs async patterns. Use when setting up hooks for the first time…

FlorianBruniaux/claude-code-plugins · 78 tokens

check-cache-bugs

Audit Claude Code setup for cache bugs (CC#40524): sentinel, --resume/--continue, attribution header + ArkNill B3/B4/B5.

FlorianBruniaux/claude-code-plugins · 38 tokens

eval-skills

Audit all skills in the current project for frontmatter completeness, effort level appropriateness, allowed-tools scoping, and content quality. Produces a scored report with effort-level recommendations for each skill. Use when onboarding to a new project, reviewing skill quality before shipping, or adding effort…

FlorianBruniaux/claude-code-plugins · 67 tokens

autoresearch

Autonomous improvement loop: scan codebase metrics, scaffold experiment files, run agent-driven iterations until metric improves.

FlorianBruniaux/claude-code-plugins · 24 tokens