refactoring-best-practices

refactoring-best-practices is a skill for Claude Code, Codex from OKHP3/skillz. It costs 86 tokens per session (1,246 once invoked), scanned A, original, MIT.

Guidance for safely improving existing or legacy code while keeping its current behavior. It covers small refactoring steps, tests, and ways to isolate difficult dependencies.

In plain words
What is it for?
Use it to add tests around current behavior, separate code from databases or external services, improve error handling, and reorganize responsibilities incrementally.
Why use it?
It reduces the risk of breaking working software during cleanup or redesign. It helps you make progress without relying on a large rewrite.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it to add tests around current behavior, separate code from databases or external services, improve error handling, and reorganize responsibilities incrementally.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/okhp3/skillz/refactoring-best-practices
View source ↗ OKHP3/skillz
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 OKHP3/skillz --skill refactoring-best-practices
Clone the repo
git clone --depth 1 https://github.com/OKHP3/skillz

Made for: Claude Code, Codex.

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-best-practices

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

Your own site · 80×15
<a href="https://agentmods.dev/skills/okhp3/skillz/refactoring-best-practices"><img src="https://agentmods.dev/badge/skills/okhp3/skillz/refactoring-best-practices.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 86 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,246 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.00086 $0.01246
Opus 5 $0.00043 $0.00623
Sonnet 5 $0.00017 $0.00249
Haiku 4.5 $0.00009 $0.00125

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

Security

Grade A, and why

refactoring-best-practices 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 6d 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.

community/refactoring-best-practices/SKILL.md · 114 lines

How it starts

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

Refactoring Best Practices

Use this skill when the main challenge is changing existing code safely.

Working Style

  1. Protect behavior before improving design.
  2. Prefer small reversible moves over dramatic rewrites.
  3. Add feedback before adding abstraction.
  4. Change one responsibility at a time.
  5. Let the current pain point decide the next move.

Safe Refactoring Workflow

  1. Observe current behavior.

    • Identify outputs, side effects, and error paths.
    • Identify what must not change.
  2. Add feedback.

    • Prefer characterization tests around visible behavior.
    • Add logs or temporary probes only when tests are not enough.
  3. Find a seam.

    • Isolate time, file system, network, framework globals, singletons, and external APIs.
    • Create the narrowest possible boundary around the risky dependency.
  4. Choose the next move.

    • extract method
    • extract class
    • introduce value object
    • introduce first-class collection
    • move method
    • replace conditional with polymorphism
    • separate construction from behavior
    • extract a Domain Event and one secondary subscriber
  5. Re-run feedback after every meaningful step.

High-Value Refactoring Moves

  • Replace a cohesive domain parameter group with a Value Object; use a Parameter Object when the group has no shared domain meaning or invariant.
  • Break large services into role-focused collaborators.
  • Move business rules out of controllers, scripts, and utility classes.
  • Replace type codes and unstable conditionals with explicit roles.
  • Wrap infrastructure behind ports or adapters.
  • Split classes when different method clusters change for different reasons.

Red Flags

  • Big-bang rewrites.
  • New abstractions without a protected behavior baseline.
  • Splitting code into tiny classes without a clearer model.
  • Introducing inheritance only to make tests easier.
  • Refactoring based on aesthetics alone while ignoring risk.

Decision Rules

Refactor now when

  • the same knowledge is duplicated in multiple places
  • the code is blocking a real change
  • the next feature would deepen coupling or duplication
  • the current structure makes defects likely

Read the full file on GitHub · 114 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. 6d ago First seen · 114 lines · 86 tokens per session scan A 16dd3e5c1492

Subscribe to this mod's changes

refactoring-best-practices is a skill published in the GitHub repository OKHP3/skillz (3 stars, last pushed yesterday), licensed MIT. It adds 86 tokens to every session and 1,246 once invoked, about $0.0004 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

ontoly-software-graph

Use Ontoly's deterministic Software Graph and MCP capabilities for architecture review, request tracing, dependency analysis, configuration lookup, and impact analysis before falling back to source-file search.

anbeime/skill · 41 tokens

openclaw-diagnose

Diagnose and fix OpenClaw gateway and node host issues. Use when openclaw services have warnings, connection failures, pairing errors, or port conflicts.

soulmachine/skills · 39 tokens

lxd-docker-firewall-conflict

Diagnose and fix the well-known Docker/LXD firewall conflict on a host running both. Docker sets the iptables FORWARD chain policy to DROP and accepts only its own bridges, so forwarded traffic from the LXD bridge (lxdbr0) is silently dropped and LXD containers/VMs get no outbound internet (the host itself is fine).…

soulmachine/skills · 255 tokens

baoyu-diagram

Create professional, dark-themed SVG diagrams of any type — architecture diagrams, flowcharts, sequence diagrams, structural diagrams, mind maps, timelines, illustrative/conceptual diagrams, and more. Use this skill whenever the user asks for any kind of technical or conceptual diagram, visualization of a system…

JimLiu/baoyu-skills · 146 tokens

log-analyzer

A log-analysis helper that reads application and system logs to find unusual patterns and likely causes. Logs are records of events such as errors, requests, warnings, and service activity.

laolaoshiren/claude-code-skills-zh · 24 tokens

Reverse Engineering & Binary Analysis

Binary analysis, assembly interpretation, disassembly, decompilation, firmware RE, and protocol reverse engineering.

Masriyan/Claude-Code-CyberSecurity-Skill · 26 tokens