refactor

Identify and apply behavior-preserving refactoring changes with tests kept green.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/sofer/.agents --skill refactor-sofer
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor
Source: https://github.com/sofer/.agents/tree/main/skills/refactor
Command: npx skills add https://github.com/sofer/.agents --skill refactor-sofer

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill helps teams clean up implementation code while ensuring tests remain green, reducing technical debt without altering observable behavior.

Core Features & Use Cases

  • Identify and extract refactoring opportunities to improve readability
  • Apply small, deterministic changes that preserve behaviour and keep tests green
  • Document and version changes for auditing and review

Quick Start

Run the test suite and begin by applying a small, verifiable refactor that preserves behavior.

Frequently Asked Questions about refactor

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor code to improve readability without breaking existing behavior?

To refactor code without altering behavior, you identify opportunities like extract-method or rename, apply small deterministic changes, and verify tests stay green. This preserves outward behavior while improving maintainability.

What is the red-green-refactor workflow for maintaining code quality?

The red-green-refactor workflow is a test-driven cycle where you write failing tests, make them pass, then polish the implementation. The refactor step focuses on extract-constant and simplification techniques to improve readability while keeping tests green.

Do I need a green test baseline before starting a code refactor?

Yes, a green test baseline is required before refactoring. You must run the test suite to confirm all tests pass, then apply small, verifiable changes step by step to ensure behavior remains unchanged throughout the process.

How do I apply extract-method and rename techniques to clean up technical debt?

You apply extract-method and rename techniques by making small, deterministic changes to the codebase. Each refactoring step must preserve observable behavior, keep tests green, and be documented for auditing and review purposes.

What's the best way to document refactoring changes for code review?

The best way to document refactoring changes is to record each small step taken during the process. Versioning and documenting changes like extract-constant or simplification actions ensures the refactoring can be audited and reviewed effectively.

When should I avoid refactoring code that lacks test coverage?

You should avoid refactoring code without a green test baseline. The process requires verifiable, small step changes to preserve outward behavior, which is impossible to confirm safely if the test suite is not passing beforehand.