refactoring

refactoring is a skill for Claude Code, Codex from DevelopersGlobal/ai-agent-skills. It costs 22 tokens per session (647 once invoked), scanned A, original, MIT.

A method for changing code's internal structure without changing what it does. Tests are used to confirm that the existing behavior remains unchanged.

In plain words
What is it for?
Use it when code is hard to understand or extend, when duplication is risky, or before adding a feature to a messy area.
Why use it?
It makes difficult or duplicated code safer to improve and helps catch accidental behavior changes during cleanup.

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/developersglobal/ai-agent-skills/refactoring
Any agent
npx skills add DevelopersGlobal/ai-agent-skills --skill refactoring
Clone the repo
git clone --depth 1 https://github.com/DevelopersGlobal/ai-agent-skills

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 refactoring

README.md
[![agentmods](https://agentmods.dev/badge/skills/developersglobal/ai-agent-skills/refactoring.svg)](https://agentmods.dev/skills/developersglobal/ai-agent-skills/refactoring)
Your own site
<a href="https://agentmods.dev/skills/developersglobal/ai-agent-skills/refactoring"><img src="https://agentmods.dev/badge/skills/developersglobal/ai-agent-skills/refactoring.svg" alt="Measured on agentmods" height="20"></a>
Per session 22 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 647 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.00022 $0.00647
Opus 5 $0.00011 $0.00324
Sonnet 5 $0.00004 $0.00129
Haiku 4.5 $0.00002 $0.00065

Measured 4d ago against content hash 20508140cd99, 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 4d 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 · 78 lines

How it starts

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

Overview

Refactoring changes the internal structure of code without changing its external behavior. The keyword is "without" — if behavior changes, it's not refactoring, it's modification. This skill enforces safe refactoring with tests as the safety net.

When to Use

  • When code is hard to understand or extend
  • When duplication makes maintenance risky
  • Before adding a feature to a messy area of code
  • Never: "while also adding feature X" — refactor separately

Process

Step 1: Establish a Safety Net

  1. Before touching a single line: ensure there are tests covering the code to be refactored.
  2. If tests are missing: add characterization tests first. These capture current behavior, not desired behavior.
  3. Run the tests. They should all pass. This is your baseline.

Verify: Tests pass. They cover the code being refactored.

Step 2: Refactor in Micro-Steps

  1. Make the smallest meaningful change.
  2. Run tests after EVERY change — not after 10 changes.
  3. If tests break: revert immediately and take a smaller step.
  4. Never batch multiple refactoring changes together.

Verify: Tests pass after every individual change.

Step 3: One Thing at a Time

  1. Refactoring types cannot be mixed in one step:
    • Extract method → separate commit
    • Rename → separate commit
    • Move → separate commit
  2. "Refactor and also fix this" is not refactoring — it's two PRs.

Verify: This commit does exactly one type of refactoring.

Step 4: Verify No Behavior Change

  1. Run the full test suite.
  2. If integration/E2E tests exist: run them too.
  3. Compare external API responses before and after (if applicable).

Verify: All tests pass. No observable behavior change.

Common Rationalizations (and Rebuttals)

Excuse Rebuttal
"I'll add tests after refactoring" You can't verify a behavior-preserving refactor without tests before the refactor.
"This change is obviously safe" Obvious safety is how production incidents happen. Run the tests.
"I'll just do a quick cleanup" "Quick cleanup" that changes behavior is a bug, not a refactor.

Read the full file on GitHub · 78 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. 4d ago First seen · 78 lines · 22 tokens per session scan A 20508140cd99

Subscribe to this mod's changes

refactoring is a skill published in the GitHub repository DevelopersGlobal/ai-agent-skills (65 stars, last pushed 4mo ago), licensed MIT. It adds 22 tokens to every session and 647 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-30.

Related

Other skills, from other repositories

code-review-and-quality

Conducts multi-axis code review. Use before merging any change. Use when reviewing code written by yourself, another agent, or a human. Use when you need to assess code quality across multiple dimensions before it enters the main branch.

addyosmani/agent-skills · 51 tokens

constraint-driven-development

Establishes a project's quality bar as a written contract and stops agents quietly lowering it. Interviews the user on which dimensions matter, supplies sane default thresholds when they have no number in mind, records everything in CONSTRAINTS.md, and watches the diff for a weakened bar — new @ts-ignore or…

addyosmani/agent-skills · 154 tokens

performance-optimization

Optimizes application performance across frontend, backend, queries, and databases. Use when performance requirements exist, when you suspect performance regressions, when Core Web Vitals or load times need improvement, when N+1 query patterns need fixing, or when profiling reveals bottlenecks.

addyosmani/agent-skills · 59 tokens

api-and-interface-design

Guides stable API and interface design. Use when designing APIs, module boundaries, or any public interface. Use when creating REST or GraphQL endpoints, defining type contracts between modules, or establishing boundaries between frontend and backend.

addyosmani/agent-skills · 49 tokens

code-simplification

Simplifies code for clarity. Use when refactoring code for clarity without changing behavior. Use when code works but is harder to read, maintain, or extend than it should be. Use when reviewing code that has accumulated unnecessary complexity.

addyosmani/agent-skills · 51 tokens

doubt-driven-development

Subjects every non-trivial decision to a fresh-context adversarial review before it stands. Use when correctness matters more than speed, when working in unfamiliar code, when stakes are high (production, security-sensitive logic, irreversible operations), or any time a confident output would be cheaper to verify now…

addyosmani/agent-skills · 67 tokens