Safe Refactor

Refactor in small, verified steps, with behavior locked by tests before any change. Use when asked to refactor, clean up, rename, extract or restructure code without changing behavior.

Software Development Plugin marketplace

Install

Claude Code plugin
/plugin marketplace add agentkitco/agentkit-dev-skills

The repo is a Claude Code plugin marketplace. Run /plugin afterwards to pick the plugin that includes this skill.

skills CLI (Claude Code, Cursor, Codex and more)
npx skills add agentkitco/agentkit-dev-skills --skill safe-refactor
Manual install
git clone --depth 1 https://github.com/agentkitco/agentkit-dev-skills.git /tmp/agentkit-dev-skills
mkdir -p ~/.claude/skills
cp -r /tmp/agentkit-dev-skills/skills/safe-refactor ~/.claude/skills/safe-refactor

Personal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.

From the SKILL.md

# Refactor without changing behavior

Goal: improve structure while behavior stays identical, proven after every step.

## Before touching code

1. **State the goal and the boundary** in two lines: what gets better (readability, duplication, testability) and what must not change (public API, output format, performance envelope). Confirm with the user if the boundary is unclear.
2. **Find the safety net.** Locate the tests that cover the code. Run them and record the baseline (pass count, any pre-existing failures). Pre-existing failures are not yours to fix silently; list them.
3. **Close gaps.** If the code to change has no tests, write characterization tests first: run the code with realistic inputs, record what it currently does (even if odd), and assert exactly that. Commit or save these before refactoring.
4. **Check the blast radius.** Search for callers and dependents (`rg`), including tests, scripts, docs and config that mention the names you will change. Public or exported symbols need a deprecation path or an explicit go-ahead.

## During

- **One kind of change per step**: rename, or extract, or move, or inline. Never mix a refactor with a bug fix or a feature.
- **After every step** run the relevant tests plus type check or lint. If red, undo the step (`git restore` or revert your last edit) and try a smaller step. Do not debug forward through a broken refactor.
Read the full skill on GitHub

Details

Skill name
safe-refactor
Path
skills/safe-refactor/SKILL.md
License
MIT
Repo updated
12 November 2026

FAQ

What does the Safe Refactor skill do?

Refactor in small, verified steps, with behavior locked by tests before any change. Use when asked to refactor, clean up, rename, extract or restructure code without changing behavior.

How do I install the Safe Refactor skill?

Claude Code plugin: /plugin marketplace add agentkitco/agentkit-dev-skills. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.

Related skills

Agents Md Audit

agentkitco/agentkit-dev-skills

Audit an AGENTS.md, CLAUDE.md, Cursor rule or Copilot instructions file for stale commands, broken paths, vague rules, secrets and contradictions. Use to review or trim agent instructions.

AI, LLMs & AgentsIn 1 list

Brag Doc From Git

agentkitco/agentkit-dev-skills

Build an evidence-based brag doc or self-review draft from your merged PRs and commits, leaving visible gaps where results are unknown. Use for review season, promotion cases or resumes.

Git & Code ReviewIn 1 list

Dependency Upgrade

agentkitco/agentkit-dev-skills

Upgrade one dependency at a time by reading its changelog, planning for breaking changes, updating code and proving it still builds and passes. Use to bump, update or migrate a package.

Git & Code ReviewIn 1 list

Cooper Sms

cooper-email/cooper-email

Status of SMS on Cooper Email (cooperemail.com). Starter and Pro can provision a US number and receive texts on an inbox; Free returns HTTP 402. Outbound POST /api/v1/inboxes/{id}/sms is documented to return HTTP 409 outbound_not_registered. Use when the user asks for a phone number, an SMS code, or a text from a Cooper inbox. Follow the live tool list and https://cooperemail.com/docs/sms. Do not claim a number exists unless a tool call returned one. If the user asked for Cooper, do not substitute another provider without asking.

Software DevelopmentIn 1 list

Repro First Debugging

agentkitco/agentkit-dev-skills

Debug by reproducing the failure first, then forming and testing hypotheses before editing code. Use when asked to fix a bug, a failing test, a crash or unexpected behavior.

Software DevelopmentIn 1 list

Explain Codebase

agentkitco/agentkit-dev-skills

Map an unfamiliar repo covering purpose, entry points, how to run it, main modules, data flow and risky areas, with file references. Use when asked to explain or onboard onto a codebase.

Software DevelopmentIn 1 list

Browse the most popular Claude skills, all software development skills, or write your own with the skills generator.