Skip to content
Back to skills

Refactoring Skill

ASecurity

Safe refactoring discipline — characterize existing behavior before changing structure, move in small reversible steps, never mix refactoring with feature work.

  • 3 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 5, 2026
developmentjavascriptpythongojavareactrefactoringgit

Security analysis

A100/100

Pro scans all 21 files and shows the line behind each finding

Scanned October 1, 2026

npx -y skills add sharmapuneet1510/awesome-prompts --skill skills --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Refactoring Skill?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Refactoring Skill
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/sharmapuneet1510-refactoring-skill/badge)](https://www.skillsdirectory.com/skills/sharmapuneet1510-refactoring-skill)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: Refactoring Skill
version: 1.1
description: >
  Safe refactoring discipline — characterize existing behavior before changing
  structure, move in small reversible steps, never mix refactoring with feature work.
applies_to: [java, python, javascript, react, refactoring]
tags: [refactoring, code-quality, technical-debt]
---

# Refactoring Skill — v1.1

## Quick Card

> Read this card first. Load a section below only when the task needs it.

| | |
|---|---|
| **Use when** | Restructuring code without changing behaviour — `architect:refactor`, or before a feature that the current shape blocks |
| **Skip when** | The change also alters behaviour — split it: refactor commit, then behaviour commit |
| **Inputs** | The code, a concrete trigger, characterization tests |
| **Produces** | Smaller, reviewable refactor commits with tests green after each |
| **Steps** | 1. Characterize behaviour with tests → 2. Confirm the trigger → 3. Bound the scope → 4. Small moves, tests after each → 5. Commit separately from behaviour changes |
| **Done when** | §5 checklist passes; public contracts unchanged unless that was the goal |
| **Load on demand** | §2 before you start · §3 safe moves · §4 never mix |
| **Run report** | `html_report_skill` — adds: Moves applied, in order |
| **Pairs with** | `test_skill`, `oop_skill`, `adr_skill` (Refactoring type) |

---

## 1. Definition

Refactoring changes code's internal structure without changing its observable behavior. If behavior changes, it's not a refactor — it's a feature change or a bug fix, and it needs its own commit and its own tests.

## 2. Before You Start

1. **Characterize current behavior.** If there's no test covering the code you're about to restructure, write one first (a characterization test — it documents what the code *does*, not what it *should* do).
2. **Confirm the trigger.** Refactor because a specific task needs it (adding a feature is hard because of tangled state; a bug is hiding because of duplicated logic), not speculatively. "This could be cleaner" is not a trigger on its own.
3. **Scope it.** Decide the boundary up front — one class, one module — and don't let it creep while you're in there.

## 3. Safe Refactoring Moves

Small, reversible, test-after-each-step:
- **Extract function/method** — pull a block into a named function; verify tests still pass.
- **Rename** — for clarity, never as a drive-by; use IDE rename tooling to catch every reference.
- **Inline** — collapse a needless indirection (a wrapper that does nothing but call through).
- **Move** — relocate a method/field to the class that actually owns the responsibility.
- **Replace conditional with polymorphism** — when a type-switch keeps growing, model the variants as types instead.
- **Introduce parameter object** — when a function's parameter list keeps growing, group related parameters.

Each move should be small enough that if it breaks something, `git diff` immediately shows why.

## 4. Never Mix Refactoring With Behavior Change

The #1 way refactors go wrong: "while I'm in here, let me also fix this bug / add this feature." This makes the diff impossible to review confidently, since a reviewer can't tell if a given line changed *because* of the restructuring or is an *actual* behavior change.

- Refactor first, commit, then make the behavior change as a separate commit.
- Or, if the bug fix is trivial and unrelated to the refactor's scope, do it first as its own commit, then refactor on top.

## 5. Checklist

✅ Characterization test exists (or was added) before restructuring
✅ Trigger for the refactor is a concrete task, not speculation
✅ Scope is bounded and stated up front
✅ Moves are small and independently verifiable
✅ Tests pass after every move, not just at the end
✅ No behavior change bundled into the same commit
✅ Public interfaces/contracts unchanged unless that was the explicit goal

---
> Inspired by ideas from [ai-boost/awesome-prompts](https://github.com/ai-boost/awesome-prompts) (GPL-3.0) — content rewritten, not copied. See `docs/reference/credits.md`.

Files in this skill

  • README.md10.2 KB
  • adr_skill.md8.4 KB
  • agent_skill_design_skill.md3.1 KB
  • apache_camel_skill.md15.5 KB
  • apache_pulsar_skill.md17.1 KB
  • ba_create_skill.md18.9 KB
  • backend_skill.md22.1 KB
  • code_documentation_skill.md13.4 KB
  • code_formatting_skill.md11.7 KB
  • code_health_skill.md9.8 KB
  • code_review_skill.md36.7 KB
  • context_builder_skill.md11.7 KB
  • current_tech_spec_skill.md6.3 KB
  • database_skill.md18.4 KB
  • debugging_skill.md3.4 KB
  • error_handling_skill.md18.4 KB
  • frontend_skill.md23.6 KB
  • java_advanced_skill.md15 KB
  • jira_html_report_skill.md15.5 KB
  • jira_incremental_spec_generator_skill.md19.7 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…