refactor-safely

refactor-safely is a skill for Claude Code from the-open-agent/oss-skills. It costs 109 tokens per session (2,049 once invoked), scanned A, original, Apache-2.0.

A set of practices for changing a codebase's internal structure while keeping the interfaces that other people use working.

In plain words
What is it for?
It helps plan targeted refactors, split a large codebase into packages, rename or move public symbols, and change internal architecture behind a stable interface.
Why use it?
It reduces the risk that a large cleanup, rewrite, or move of public functions will break users or waste months of work.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Needs its repository: it runs a file that does not travel with it, so clone the repository first. The line is npx jscodeshift -t ./codemods/v4-rename-parse.js src/ # JS/TS.

Part of the oss-skills plugin — 18 skills shipped together

Good fit It helps plan targeted refactors, split a large codebase into packages, rename or move public symbols, and change internal architecture behind a stable interface.

Compare 6 skills from other repositories ↓
Install

Getting it into your agent

It runs from inside its repository, so the clone comes first — what it calls does not travel with the file alone.

Clone the repo
git clone --depth 1 https://github.com/the-open-agent/oss-skills
agentmods
npx agentmods add skills/the-open-agent/oss-skills/refactor-safely

Made for: Claude Code.

Or install oss-skills, the plugin that ships this one along with the rest of its 18 skills.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for refactor-safely

README.md
[![agentmods](https://agentmods.dev/badge/skills/the-open-agent/oss-skills/refactor-safely/github.svg)](https://agentmods.dev/skills/the-open-agent/oss-skills/refactor-safely)
Your own site
<a href="https://agentmods.dev/skills/the-open-agent/oss-skills/refactor-safely"><img src="https://agentmods.dev/badge/skills/the-open-agent/oss-skills/refactor-safely/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for refactor-safely

Your own site · 80×15
<a href="https://agentmods.dev/skills/the-open-agent/oss-skills/refactor-safely"><img src="https://agentmods.dev/badge/skills/the-open-agent/oss-skills/refactor-safely.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 109 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,049 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00109 $0.02049
Opus 5 $0.00055 $0.01025
Sonnet 5 $0.00022 $0.00410
Haiku 4.5 $0.00011 $0.00205

Measured 9d ago against content hash ccf90de50d8e, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

refactor-safely scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 9d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/refactor-safely/SKILL.md · 179 lines

How it starts

The opening of the file, as written. The whole thing — 179 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Refactoring Safely

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.

First: should you?

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.

Preconditions

Do not start until all of these hold:

  1. Characterization tests exist. Before changing anything, write tests that pin current behavior — including behavior you think is wrong. Bugs get depended upon; those tests tell you which ones.
  2. The public API surface is snapshotted and asserted in CI (see api-design).
  3. The refactor is sequenced into reviewable PRs. Nobody can review 5,000 lines, including you in three weeks.
  4. main stays releasable at every commit. A long-lived refactor branch accumulates conflicts and blocks everyone else's work.

Read the full file on GitHub · 179 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 9d ago First seen · 179 lines · 109 tokens per session scan A ccf90de50d8e

Subscribe to this mod's changes

refactor-safely is a skill published in the GitHub repository the-open-agent/oss-skills (5 stars, last pushed 1mo ago), licensed Apache-2.0. It adds 109 tokens to every session and 2,049 once invoked, about $0.0005 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

cn-check

Install and run the Continue CLI (cn) to execute AI agent checks on local code changes. Use when asked to "run checks", "lint with AI", "review my changes with cn", or set up Continue CI locally.

continuedev/continue · 49 tokens

mindos

MindOS: local knowledge assistant & shared KB. Keeps decisions, notes, SOPs, debugging lessons, research findings, preferences across sessions/agents. Core: save notes, search KB, organize files, run workflows, review, append CSV, hand off context, distill lessons. NOT for app source or paths outside KB. Triggers…

GeminiLight/MindOS · 136 tokens

superlint

This skill describes the mandatory standard operating procedure for using our internal SuperLint tool. Use this when tasks require fixing code quality issues according to corporate standards.

mgechev/skillgrade · 0 tokens

pr-review

Review a GitHub pull request and post one formal review — advance the existing discussion and give precision-first, high-signal feedback. Judgement on the diff, not a build gate — CI validates that it builds, and a targeted probe is allowed as evidence. Use when asked to review a PR or on a cron PR scan.

nearform/lastlight · 69 tokens

PR Etiquette

This skill should be used when responding to maintainer review feedback, writing or reviewing PR descriptions, following up on dormant PRs, validating PR quality before submission, or deciding how to communicate with maintainers. Sibling to oss-contribution and contribution-ethics.

costajohnt/oss-autopilot · 57 tokens

pr-comment

Answer a maintainer's question about an open PR with concrete, code-cited evidence. The PR-side counterpart to issue-comment — for questions tied to the diff, not a full review.

nearform/lastlight · 41 tokens