refactoring-safely

refactoring-safely is a skill for Claude Code from AnastasiyaW/codex-claude-code-config. It costs 221 tokens per session (1,722 once invoked), scanned A, original, MIT.

A disciplined way to reorganize existing code while keeping its behavior unchanged. It uses tests that capture current behavior before making small structural changes.

In plain words
What is it for?
Use it to extract or inline code, move features, reorganize data, simplify conditionals, and safely improve code with characterization tests and frequent checks.
Why use it?
It separates code cleanup from feature changes, making failures easier to understand and reducing the risk of accidentally changing what the software does.

Skill for Claude Code

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

Part of the claude-code-config plugin — 57 skills, 8 agents shipped together

Good fit Use it to extract or inline code, move features, reorganize data, simplify conditionals, and safely improve code with characterization tests and frequent checks.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/anastasiyaw/codex-claude-code-config/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 AnastasiyaW/codex-claude-code-config --skill refactoring-safely
Clone the repo
git clone --depth 1 https://github.com/AnastasiyaW/codex-claude-code-config

Made for: Claude Code.

Or install claude-code-config, the plugin that ships this one along with the rest of its 57 skills, 8 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/anastasiyaw/codex-claude-code-config/refactoring-safely.svg)](https://agentmods.dev/skills/anastasiyaw/codex-claude-code-config/refactoring-safely)
Your own site
<a href="https://agentmods.dev/skills/anastasiyaw/codex-claude-code-config/refactoring-safely"><img src="https://agentmods.dev/badge/skills/anastasiyaw/codex-claude-code-config/refactoring-safely.svg" alt="Measured on agentmods" height="20"></a>
Per session 221 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,722 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. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
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.00221 $0.01722
Opus 5 $0.00111 $0.00861
Sonnet 5 $0.00044 $0.00344
Haiku 4.5 $0.00022 $0.00172

Measured today against content hash b66703881863, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-07, 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 today.

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

How it starts

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

Refactoring safely — changing shape without changing behaviour

Refactoring is a behaviour-preserving transformation. If behaviour changed, that was not a refactor, it was a rewrite with optimistic branding — and the reason large restructures fail is almost always that the two were done in one step.

The rule that makes the rest work

Never restructure and change behaviour in the same commit. Alternate deliberately: refactor (green → green, no behaviour change), then change behaviour (with a new test). When both happen at once, a failing test cannot tell you which half broke it.

Before touching anything: the net

Legacy code is code without tests, regardless of age. So:

  1. Characterization tests first. Not tests of what it should do — tests of what it does, including behaviour you consider wrong. Their job is to detect change, not to judge it. Wrong-but-tested behaviour gets fixed later, on purpose, in its own commit.
  2. Cover the seams you are about to cut, not the whole file. Coverage of the region under the knife is what matters.
  3. Confirm they fail when you break something. A characterization test that passes against deliberately broken code is worse than none — run that check once.
  4. Know how to revert. Small commits, one transformation each.

Smells, and what each one actually indicates

Smell Underlying problem Transformation
Long function Several jobs in one scope Extract function, split by level of abstraction
Large module Several reasons to change in one file Move features into modules that own their state
Long parameter list A missing object, or a hidden mode flag Introduce parameter object; split by behaviour
Feature envy Method uses another object's data more than its own Move method to where the data lives
Shotgun surgery One decision spread across files Gather it into one owner
Divergent change One file changing for unrelated reasons Split by reason to change
Primitive obsession A concept represented as a string or dict everywhere Introduce a type; put its rules with it
Duplicated decision One rule expressed in several places Extract and give it one home

Read the full file on GitHub · 132 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. today Changed · +12 lines b66703881863
  2. 8d ago First seen · 120 lines · 221 tokens per session scan A 117415c55843

Subscribe to this mod's changes

refactoring-safely is a skill published in the GitHub repository AnastasiyaW/codex-claude-code-config (149 stars, last pushed today), licensed MIT. It adds 221 tokens to every session and 1,722 once invoked, about $0.0011 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-30.