Refactoring

From andresdiegolanda/design-first-ai · View interactive version

Refactoring is an AI agent skill from the GitHub repository andresdiegolanda/design-first-ai. Team standard for improving existing code without changing behaviour. Use when refactoring code.

How to use this skill

Skill file

Skill: Refactoring

When to load it: When improving existing code without changing observable behaviour.


What This Skill Does

Applies the team's refactoring philosophy to a specific piece of code. Proposes

improvements that reduce complexity, remove duplication, and align with project

conventions — without changing the public interface or adding unrequested behaviour.

Output is a proposed change with explanation of what each transformation does and why.


Rules

  1. Preserve the public contract. Method signatures, return types, and exception types

visible to callers must not change unless the refactoring scope explicitly includes them.

  1. Propose incremental changes. One transformation per pass — extract, rename, simplify,

or inline. Not all at once.

  1. Identify the specific problem first. State what is wrong (duplication, premature

abstraction, unclear naming, violation of a project convention) before proposing a fix.

  1. Stop at the boundary of the stated problem. Do not refactor code adjacent to the

target unless it is required to complete the transformation safely.

  1. Validate test coverage before changing. If the code under refactoring has no tests,

say so before proposing structural changes.


Pattern

Opening prompt structure:

I need to refactor [ComponentName / method / file].

Problem: [what is wrong — duplication / complexity / convention violation / other]

Constraints:
- Do not change the public interface
- Do not change observable behaviour
- Follow [specific convention from Layer 1 or Layer 2]

Current code:
[paste the code]

Propose the refactored version. Explain each transformation.
Do not change anything not related to the stated problem.

Response structure the skill produces:

Problem identified: [one sentence]

Transformations:
1. [transformation name] — [what changed and why]
2. [transformation name] — [what changed and why]

Refactored code:
[code]

Public interface unchanged: [confirm or flag deviations]
Tests required: [list any new tests needed to verify the transformation]

Design Constraints

are separate phases

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.