Refactoring Safely

Guides incremental code refactoring with tests-first discipline and separate commits for behavior changes.

Updated Dec 4, 2025
One-click install
npx skills add https://github.com/dallascrilley/dowser --skill refactoring-safely-dallascrilley
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: Refactoring Safely
Source: https://github.com/dallascrilley/dowser/tree/main/skills/refactoring-safely
Command: npx skills add https://github.com/dallascrilley/dowser --skill refactoring-safely-dallascrilley

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Refactoring without tests or mixing structural changes with bug fixes makes code changes risky, hard to review, and difficult to revert. This Skill enforces a disciplined process so every refactoring preserves behavior and stays verifiable. ## Core Features & Use Cases - Three Iron Laws: Enforces tests before refactoring, one change at a time, and never mixing refactoring with bug fixes or features. - Step-by-Step Process: Provides a repeatable workflow of verifying tests, making one structural change, running the suite, and committing. - Bug Discovery Protocol: Defines exactly how to stash refactoring work, fix a discovered bug in a separate commit, and resume. - Use Case: While extracting methods from a 300-line function, you discover a validation bug. The Skill directs you to stash the refactoring, write a failing test, fix and commit the bug separately, then continue the extraction incrementally. ## Quick Start Ask the AI to help refactor a function using the refactoring-safely skill, extracting one method at a time with tests run after each change.

Frequently Asked Questions about Refactoring Safely

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

FAQPage Schema
How do I refactor code safely without breaking existing behavior?▼

Ensure passing tests exist first, then make one structural change at a time, running the full test suite after each change and committing separately. If no tests exist, write them and watch them pass before touching any code structure.

Should I fix a bug I find while refactoring?▼

No, never mix bug fixes with refactoring in the same commit. Stash your refactoring work, write a failing test for the bug, fix and commit it separately, then resume refactoring. Mixing behavior and structure changes makes failures impossible to diagnose.

Can I refactor code that has no tests?▼

No, refactoring untested code is unsafe because nothing verifies behavior is preserved. Add tests first, confirm they pass, then refactor. Manual verification is not a substitute for automated tests.

How do I refactor a large function with hundreds of lines?▼

Use the incremental pattern: extract one section, run tests, commit, then repeat for each remaining section. Extracting everything at once makes it impossible to identify which change broke the tests and blocks deployment until finished.

Why should refactoring and bug fixes be separate commits?▼

Separate commits keep behavior changes distinct from structure changes, so test failures have a clear cause, reviews evaluate one concern at a time, and a bad bug fix can be reverted without losing good refactoring work.