refactoring-safely

refactoring-safely is a skill for Claude Code from boparaiamrit/skills-by-amrit. It costs 38 tokens per session (2,061 once invoked), scanned A, original, MIT.

A test-backed method for changing the structure of existing code while keeping its behaviour the same. Refactoring means reorganising code without intentionally changing what users or other code observe.

In plain words
What is it for?
Use it when renaming, extracting, inlining, restructuring, or migrating existing code, especially when the code has become difficult to extend.
Why use it?
It reduces the risk of breaking working software while making tangled code easier to change. Tests provide evidence that each structural change preserved existing behaviour.

Skill for Claude Code

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

Part of the skills-by-amrit plugin — 33 skills, 34 commands, 9 agents shipped together

Good fit Use it when renaming, extracting, inlining, restructuring, or migrating existing code, especially when the code has become difficult to extend.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/boparaiamrit/skills-by-amrit/refactoring-safely
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add boparaiamrit/skills-by-amrit --skill refactoring-safely
Clone the repo
git clone --depth 1 https://github.com/boparaiamrit/skills-by-amrit

Made for: Claude Code.

Or install skills-by-amrit, the plugin that ships this one along with the rest of its 33 skills, 34 commands, 9 agents.

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 refactoring-safely

README.md
[![agentmods](https://agentmods.dev/badge/skills/boparaiamrit/skills-by-amrit/refactoring-safely/github.svg)](https://agentmods.dev/skills/boparaiamrit/skills-by-amrit/refactoring-safely)
Your own site
<a href="https://agentmods.dev/skills/boparaiamrit/skills-by-amrit/refactoring-safely"><img src="https://agentmods.dev/badge/skills/boparaiamrit/skills-by-amrit/refactoring-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 refactoring-safely

Your own site · 80×15
<a href="https://agentmods.dev/skills/boparaiamrit/skills-by-amrit/refactoring-safely"><img src="https://agentmods.dev/badge/skills/boparaiamrit/skills-by-amrit/refactoring-safely.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 38 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,061 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.00038 $0.02061
Opus 5 $0.00019 $0.01030
Sonnet 5 $0.00008 $0.00412
Haiku 4.5 $0.00004 $0.00206

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

Security

Grade A, and why

refactoring-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/refactoring-safely/SKILL.md · 266 lines

How it starts

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

Refactoring Safely

Overview

Refactoring changes structure without changing behavior. If behavior changes, it's not refactoring — it's rewriting.

Core principle: Every refactoring step must be verified. If tests break, the refactoring changed behavior.

The Iron Law

NO REFACTORING WITHOUT TESTS PROVING BEHAVIOR IS PRESERVED.

If there are no tests covering the code you're about to refactor, write them first.

When to Use

  • Before: the code needs structural improvement
  • Before: adding a feature requires changing existing structure
  • When: code smells are identified in review or audit
  • When: "I can't add this feature because the code is too tangled"

When NOT to Use

  • Adding new features (that's executing-plans with TDD, not refactoring)
  • Fixing a bug (that's systematic-debugging — behavior SHOULD change)
  • Rewriting from scratch (refactoring preserves behavior; rewriting replaces it)

Anti-Shortcut Rules

YOU CANNOT:
- Refactor and add features in the same commit — separate concerns, separate commits
- Refactor without a green test baseline — no tests means you can't verify preservation
- Batch multiple refactoring steps between test runs — one step, one test run
- Say "it still works, I can tell by looking" — run the tests, read the output
- Refactor production-critical code without approval — risk must be explicit
- Skip characterization tests for untested code — capture behavior before changing it
- Refactor "while you're at it" during a bug fix — scope creep is a red flag
- Force a refactoring pattern that doesn't fit — the code tells you what it needs

Common Rationalizations (Don't Accept These)

Rationalization Reality
"This refactor is so small it doesn't need tests" Small refactors break things too. Run the tests.
"I'll fix the bug AND clean up the code together" Two different changes = two different commits. Bug fix first.
"The tests are slow, I'll run them at the end" That's batching, not refactoring. Run tests after every step.
"This code has no tests, I'll refactor carefully" No tests = no safety net. Write characterization tests first.
"I know what this code does" Then prove it with a failing test. If you can't, you don't know enough.
"Let me rewrite the whole thing, it's cleaner" Rewriting is not refactoring. Refactoring = incremental, verified steps.

Read the full file on GitHub · 266 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 · 266 lines · 38 tokens per session scan A 556a7535d670

Subscribe to this mod's changes

refactoring-safely is a skill published in the GitHub repository boparaiamrit/skills-by-amrit (5 stars, last pushed 5mo ago), licensed MIT. It adds 38 tokens to every session and 2,061 once invoked, about $0.0002 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-09-03.

Related

Other skills, from other repositories

adversarial-reviewer

Adversarial code review that assumes bugs exist and hunts for them. Use when asked to review code, find bugs, audit for correctness, stress-test a PR, or when someone says "tear this apart" or "what's wrong with this". Give no benefit of the doubt — every line is guilty until proven innocent.

emdash-cms/emdash · 71 tokens

adk-go-self-review

Review an ADK Go change the way a maintainer will — a fresh-context pass over the whole diff, five lenses (correctness and tests, scope, simplicity, style, adk-python parity), and the mutation check that proves your tests pin the change. Use before opening a PR, before any later push that changes code, and when asked…

google/adk-go · 87 tokens

go-testing

Trigger: Go tests, go test coverage, Bubbletea teatest, golden files. Apply focused Go testing patterns.

Gentleman-Programming/gentle-ai · 26 tokens

semgrep-rule-variant-creator

Creates language variants of existing Semgrep rules. Use when porting a Semgrep rule to specified target languages. Takes an existing rule and target languages as input, produces independent rule+test directories for each language.

waybarrios/opencode-power-pack · 50 tokens

brooks-sweep

Full-sweep mode: runs a unified analysis across all quality dimensions — code decay, architecture, tech debt, and test quality — then applies fixes directly to the codebase. Safe changes are auto-applied; risky changes are confirmed before execution. Drawing on twelve classic engineering books. Triggers when: user…

hyhmrright/brooks-lint · 178 tokens

include-test-files-that-assert-on-behavior-being-changed-in-decl

When delegating a task affected by this skill, include.

ZaxbyHub/opencode-swarm · 29 tokens