/oss-skills:refactor-safelyfrom oss-skills
Guides safe refactoring of code others depend on, covering strangler-fig migration, compatibility shims, codemods, feature flags, and sequencing into reviewable PRs. Helps decide when to rewrite vs. refactor incrementally.
Ships in oss-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
In a private codebase a refactor is a Tuesday. In a public one it is a coordination problem with strangers who did not agree to be coordinated.
The Second System Effect is real and rewrites kill projects. Before agreeing:
| Reason to refactor | Verdict |
|---|---|
| A specific bug class keeps recurring here | Yes — targeted refactor |
| New feature is genuinely blocked by the structure | Yes — refactor exactly enough to unblock |
| Performance ceiling hit, profiled and proven | Yes |
| Onboarding contributors repeatedly stall in this file | Yes |
| "The code is ugly" | No — write tests instead, and reconsider in a month |
| "I'd write it differently now" | No |
| "Let's move to " | Only with a user-facing reason |
| "Full rewrite, v2, from scratch" | Almost never — see below |
The full rewrite trap. A from-scratch v2 means: shipping nothing for months, maintaining v1 anyway, re-discovering every edge case that the ugly code in v1 was silently handling, and a migration your users may simply decline. Projects have died here. If the user wants a rewrite, propose the strangler-fig alternative first, and only lose that argument once.
Rewriting is genuinely correct when the original's core assumption is wrong — single-threaded when it must be concurrent, synchronous when it must stream, a data model that cannot express the domain. Incremental refactoring cannot fix an axiom.
Do not start until all of these hold:
api-design).main stays releasable at every commit. A long-lived refactor branch
accumulates conflicts and blocks everyone else's work.# Establish a behavioral baseline before touching anything
make test # must be green
git tag pre-refactor-baseline
cargo public-api > api-baseline.txt # or api-extractor / dir() snapshot
The pattern that lets you replace a system while it stays in production.
Each step ships. Each step is revertible. At no point is main broken. This is slower
in wall-clock time than a rewrite and dramatically faster in time-to-working-software.
The rule: never break the old path in the same release that introduces the new one.
// v3.1 — new home, old path still works
export { parseConfig } from './config/parse.js';
/** @deprecated Import from `pkg/config` instead. Removed in v4.0.0. */
export function parse(opts: Options) {
warnOnce('parse() moved to parseConfig() in pkg/config. Removed in v4.0.0.');
return parseConfig(opts);
}
Sequence: v3.1 adds the new path and deprecates the old → v3.x keeps both, warning once per process → v4.0 removes the old path, with a migration guide and a codemod.
For renames inside a package, keep the change mechanical and separate:
git mv src/utils.ts src/text/normalize.ts
# rename-only commit, no logic changes — reviewable in 30 seconds
Mixing a rename with a behavior change produces a diff where the behavior change is invisible. Reviewers will miss it. This is one of the most reliable ways to ship a bug.
If a migration requires more than about ten mechanical edits per user, write the codemod. The adoption difference is enormous — a one-command migration gets run; a 20-step guide gets deferred until the user is on an unsupported version filing bugs.
npx jscodeshift -t ./codemods/v4-rename-parse.js src/ # JS/TS
python -m libcst.tool codemod v4_rename src/ # Python
comby 'parse(:[args])' 'parseConfig(:[args])' -i -f .go # language-agnostic
cargo fix --edition # Rust editions
Ship it in the repo under codemods/, test it against your own codebase first, and
link it from the migration guide and the deprecation warning message.
A good refactor PR series, in order:
git diff -M --stat showing pure renames.Each PR states in its description: what changed, what did not, and how to verify. Label
the series (refactor/parser) and track it in a single meta-issue so contributors know
which files are moving and can avoid conflicts.
docs-architecture).# API surface diff — the highest-signal check
cargo public-api diff pre-refactor-baseline
npx api-extractor run --local && git diff etc/
# Behavioral equivalence on real inputs
for f in fixtures/*; do diff <(old-bin "$f") <(new-bin "$f") || echo "DIFF: $f"; done
# Downstream smoke test: run your top dependents' suites against the new version
# (npm: `npm pack` + install into their repo; Python: `pip install -e .`)
For widely-depended-upon libraries, test against real downstream consumers before release. Rust's crater and Go's module proxy analysis are the industrial versions; the manual version — cloning your five biggest dependents and running their tests — catches most of it and takes an afternoon.
.git-blame-ignore-revs, and never do it again.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
refactoring, strangler-fig, migration, compatibility, codemods, feature-flags
Other plugins' skills for the same job
npx claudepluginhub the-open-agent/oss-skills --plugin oss-skills18 skills in this plugin
/api-designDesign public interfaces for libraries and tools that other people depend on. Use when designing or reviewing a public API surface, deciding what to export, naming functions and CLI flags, adding configuration options, planning deprecations, or when the user asks "is this a good API" or "how do I change this without breaking users". Covers minimal surface area, error design, async and extension patterns, CLI ergonomics, config precedence, and stability guarantees. Also use before a 1.0 release to freeze the interface./ci-pipelinesDesign continuous integration for an open-source repository. Use when setting up GitHub Actions from scratch, when CI is slow or flaky, when adding a build matrix across OS and language versions, when configuring caching, or when handling PRs from forks that need secrets. Covers workflow structure, concurrency and cancellation, caching strategy, required checks and branch protection, self-hosted runner risks, and keeping CI cheap. Also use for "our CI takes 40 minutes" or "why is CI failing on forks"./code-reviewReview a pull request the way a good open-source maintainer does. Use when reviewing an incoming PR, when the user asks "review this PR" or "is this ready to merge", when triaging a stale PR queue, or when writing review feedback to an external contributor. Covers what to check and in what order, severity levels, phrasing feedback so people come back, handling large or unwanted PRs, first-time contributors, AI-generated submissions, and closing PRs kindly. Complements the built-in /code-review command by adding the maintainer and community dimension./contributor-experienceTurn users into contributors and make their first PR succeed. Use when a project gets stars but no contributions, when first-time PRs stall or get abandoned, when writing or improving CONTRIBUTING.md, when setting up a dev environment that works on the first try, or when the user asks "how do I get contributors" or "why does nobody contribute". Covers the contribution funnel, good first issues, local setup, mentorship, recognition, and onboarding a contributor into a maintainer./dependency-hygieneManage a project's dependencies so they stay small, current, and safe. Use when deciding whether to add a dependency, auditing an existing dependency tree, configuring Dependabot or Renovate, dealing with upgrade churn or a flood of bot PRs, resolving version conflicts, choosing between dependency ranges and pinning, or removing an unmaintained dependency. Also use for "our install is huge", "too many Dependabot PRs", or before publishing a library that others will depend on./docs-architectureStructure and write project documentation beyond the README. Use when docs have sprawled into an unnavigable pile, when users keep asking questions the docs already answer, when choosing a docs site generator (Docusaurus, MkDocs, VitePress, mdBook, Sphinx), or when planning a docs information architecture. Covers the Diataxis framework (tutorial/how-to/reference/explanation), versioning docs across releases, API reference generation, doc testing, and migration guides. Also use for "write docs for this project" or "our docs are bad".