askill
refactoring

refactoringSafety 85Repository

Refactor code safely: extract, rename, simplify, and reorganize without changing behavior. Use when the user asks to refactor, extract function, rename, simplify, or clean up this code.

0 stars
1.2k downloads
Updated 2/14/2026

Package Files

Loading files...
SKILL.md

Refactoring Skill

Core Philosophy

"Behavior stays the same; structure improves."

Change structure and names, not observable behavior. Small steps, with tests (or quick verification) after each step.


Protocol

1. Establish Safety

  • Tests: If tests exist, ensure they pass before and after. Add minimal tests for critical behavior if missing.
  • Scope: Refactor one concern at a time (e.g. one function, one type, one file). Avoid mixing refactor with new features or bug fixes in the same commit when possible.

2. Common Operations

OperationApproach
Extract function/methodIdentify cohesive block, extract, name by intent, replace call site(s).
RenameUse IDE rename (symbol/identifier) so all references update; verify tests.
MoveMove to the right module/class; update imports and references.
Simplify conditionalsGuard clauses, early returns, replace nested conditionals with clear branches or lookup.
Remove duplicationExtract shared logic; parameterize or abstract; avoid over-abstracting too early.
Split large function/fileExtract by responsibility; keep public surface clear.

3. Order of Work

  1. Understand current behavior (and tests).
  2. Pick one refactor; do it; run tests (or smoke-check).
  3. Commit or stage; repeat.
  4. If tests are missing and refactor is risky, add a minimal test first, then refactor.

4. Commands

  • Run tests after changes: npm test, pytest, go test ./..., etc., per project.
  • Search for references before rename/move: grep or IDE "Find references".

5. When NOT to Refactor

  • Low-traffic, stable code - If no one touches it and it works, leave it alone.
  • Before understanding - Don't refactor code you don't fully understand yet; read and test first.
  • Mixed with features/fixes - Don't combine refactoring with behavior changes in the same commit.
  • Without tests - If there are no tests and you can't quickly add them, the risk of silent breakage is high.
  • Under time pressure - Refactoring under deadline pressure leads to half-done changes that are worse than the original.

6. Large-Scale Refactoring

For refactors spanning multiple files or modules:

  1. Map the scope - Identify all affected files, imports, and call sites before starting.
  2. Plan the sequence - Order changes to minimize broken intermediate states (e.g., introduce new interface first, then migrate callers, then remove old code).
  3. Feature branch - Always use a dedicated branch for large refactors.
  4. Incremental commits - One logical change per commit; each commit should leave tests passing.
  5. Parallel safety - If using parallel subagents (RLM skill), ensure changes don't conflict across files.

7. Performance Implications

  • Measure before and after if refactoring hot paths (use the performance skill for profiling).
  • Extra abstractions add indirection — acceptable for clarity but watch for overhead in tight loops.
  • Data structure changes (e.g., array → map) can affect performance positively or negatively; benchmark if critical.

8. Cross-Skill Integration

SituationSkill to invoke
Need tests before refactoringtesting skill
Refactoring reveals a security issuesecurity-reviewer skill
Refactoring changes API surfacecode-reviewer skill
Refactoring affects performance-critical codeperformance skill

Checklist

  • No intentional behavior change; only structure and names.
  • Tests pass (or equivalent verification) after each logical step.
  • Renames and moves are consistent (all references updated).
  • Commits are focused (one refactor type or one area per commit when practical).
  • Large-scale refactors have a clear plan and incremental commits.
  • Performance-sensitive code benchmarked before and after (if applicable).

Install

Download ZIP
Requires askill CLI v1.0+

AI Quality Score

88/100Analyzed 2/19/2026

High-quality refactoring skill with clear triggers, comprehensive protocol, tables for operations, cross-skill integration, and practical checklist. Well-structured and reusable across projects. Minor deduction for generic content that could be more project-specific, but overall excellent skill document.

85
90
90
90
95

Metadata

Licenseunknown
Version-
Updated2/14/2026
Publishermicaelmalta

Tags

apisecuritytesting