Improves code structure while guaranteeing behavior remains unchanged.

Install

mkdir -p .claude/skills/refactor-safe && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/13115" && unzip -o skill.zip -d .claude/skills/refactor-safe && rm skill.zip

Installs to .claude/skills/refactor-safe

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Safely refactor code while preserving behavior. Use for cleanup, modularization, extracting functions, reducing duplication, improving boundaries, or preparing a feature.
170 chars✓ has a “when” trigger
Intermediate

Key capabilities

  • Define refactor target and non-goals
  • Inspect existing tests and add characterization tests
  • Make small, structure-preserving changes
  • Run targeted checks after each step
  • Avoid formatting-only churn

How it works

The skill guides through a procedure of defining targets, inspecting tests, making small changes, and running checks to improve code structure.

Inputs & outputs

You give it
Codebase to refactor
You get back
Before/after structure, files changed, behavior-preservation evidence, remaining cleanup opportunities

When to use refactor-safe

  • Extracting functions
  • Reducing code duplication
  • Improving module boundaries
  • Cleaning up legacy code

About this skill

Safe Refactor Skill

Goal

Improve structure without changing observable behavior.

Procedure

  1. Define the refactor target and non-goals.
  2. Inspect existing tests. If weak, add characterization tests when practical.
  3. Make the smallest structure-preserving change.
  4. Run targeted checks after each meaningful step.
  5. Avoid formatting-only churn unless formatter is part of the repo workflow.
  6. Do not change public APIs, schema, or behavior unless explicitly requested.

Output

  • Before/after structure.
  • Files changed.
  • Behavior-preservation evidence.
  • Remaining cleanup opportunities.

When not to use it

  • When the goal is to change public APIs
  • When the goal is to change schema
  • When the goal is to change behavior without explicit request

Limitations

  • The skill does not change public APIs, schema, or behavior unless explicitly requested
  • The skill avoids formatting-only churn unless a formatter is part of the repo workflow

How it compares

This skill provides a structured, step-by-step procedure for refactoring with an emphasis on preserving behavior, unlike an unstructured approach that might introduce regressions.

Compared to similar skills

refactor-safe side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
refactor-safe (this skill)01moNo flagsIntermediate
software-architecture3336moNo flagsIntermediate
effective-go3239moNo flagsBeginner
solid-principles579moNo flagsIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

You might also like

software-architecture

davila7

Guide for quality focused software architecture. This skill should be used when users want to write code, design architecture, analyze code, in any case that relates to software development.

333868

effective-go

openshift

Apply Go best practices, idioms, and conventions from golang.org/doc/effective_go. Use when writing, reviewing, or refactoring Go code to ensure idiomatic, clean, and efficient implementations.

323536

solid-principles

SmidigStorm

Enforce SOLID principles (Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion) in object-oriented design. Use when writing or reviewing classes and modules.

57236

typescript-review

metabase

Review TypeScript and JavaScript code changes for compliance with Metabase coding standards, style violations, and code quality issues. Use when reviewing pull requests or diffs containing TypeScript/JavaScript code.

39178

react-modernization

wshobson

Upgrade React applications to latest versions, migrate from class components to hooks, and adopt concurrent features. Use when modernizing React codebases, migrating to React Hooks, or upgrading to latest React versions.

21134

ast-grep

ast-grep

Guide for writing ast-grep rules to perform structural code search and analysis. Use when users need to search codebases using Abstract Syntax Tree (AST) patterns, find specific code structures, or perform complex code queries that go beyond simple text search. This skill should be used when users ask to search for code patterns, find specific language constructs, or locate code with particular structural characteristics.

17135

Search skills

Search the agent skills registry