code-refactor

A guide for changing existing code while keeping its observable behavior the same. It covers tasks such as splitting files, extracting methods, renaming, removing unused code, and reducing duplication.

In plain words
What is it for?
Use it for safe refactoring of files, functions, duplicated code, names, comments, or unused symbols. It also helps verify that the changes preserve existing behavior.
Why use it?
It helps make code easier to read, change, and test without accidentally changing what the software does. Broad cleanup is broken into smaller proposed steps for approval.

Skill for Claude CodeCodex

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.

agentmods
npx agentmods add skills/bahayonghang/my-ai-cli-toolkit/code-refactor
Any agent
npx skills add bahayonghang/my-ai-cli-toolkit --skill code-refactor
Clone the repo
git clone --depth 1 https://github.com/bahayonghang/my-ai-cli-toolkit

Made for: Claude Code, Codex.

Per session 97 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,946 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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 $0.00097 $0.01946
Opus 5 $0.00048 $0.00973
Sonnet 5 $0.00019 $0.00389
Haiku 4.5 $0.00010 $0.00195

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

Security

Grade A, and why

code-refactor 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 2d 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/development-workflows/code-refactor/SKILL.md · 174 lines

How it starts

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

Code Refactor

Refactor existing code without changing behavior. The skill's job is to make code easier to understand, modify, and test while keeping the observable contract stable.

Refactoring is not a license for broad cleanup. Treat every edit as a behavior-preserving transformation with evidence, a bounded target, and verification.

Default Behavior

Choose the mode from the user's scope.

  • Broad request: If the user says things like "refactor this module", "clean up this project", or "optimize the code structure", inspect first, propose safe refactor slices, and wait for user approval before broad edits.
  • Narrow request: If the user names a file, function, duplicated block, dead symbol, or specific cleanup, directly implement the smallest safe slice and verify it.
  • Review-only request: If the user asks for an independent diff or PR review (functional regressions, concurrency, test gaps) without asking to edit, use code-auditor. If the user asks for code quality review or maintainability findings without asking to edit, use code-quality-review.
  • Architecture/RFC request: If the user wants deep-module design, module-boundary candidates, or an architecture RFC rather than a behavior-preserving refactor, treat that as a separate design effort and surface it instead of refactoring in place.

Refactor Types

Classify the requested work before editing. A task may include more than one type, but execute one coherent slice at a time.

Type Use when Good outcome
Module split A file or subsystem mixes unrelated responsibilities Files align with functional modules, ownership, and test boundaries
Function/method extraction One function has multiple small behaviors or hidden phases Public API stays small; private helpers name meaningful substeps
Duplicate consolidation Similar logic appears repeatedly and may drift A shared helper removes real duplication without adding thin indirection
Naming cleanup Names hide intent, encode stale details, or force readers to inspect implementation Names are concise, intention-revealing, and consistent with local style
Comment cleanup Comments repeat code, miss invariants, or hide key assumptions Comments explain why, contracts, edge cases, and non-obvious decisions
Dead-code removal Code appears uncalled, stale, or orphaned Removal is backed by call-site, export, framework, and verification checks

Read the full file on GitHub · 174 lines

Files

What ships with it

1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

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. 2d ago First seen · 174 lines · 97 tokens per session scan A ea94a9d34864

Subscribe to this mod's changes

code-refactor is a skill published in the GitHub repository bahayonghang/my-ai-cli-toolkit (16 stars, last pushed 2d ago), licensed MIT. It adds 97 tokens to every session and 1,946 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-30.

Related

Other skills, from other repositories

absolute-simplify

Use when the user wants to simplify, clean up, refactor, tidy, or refine code — their staged/unstaged git changes or a target file/path. Reduces complexity, flattens nesting, removes redundancy and dead code, scores each change by value (holding low-value churn), then runs tests to prove nothing broke. Invoke on…

maddhruv/absolute · 178 tokens

arch-optimize

架构优化技能 v3.2:六大衰退风险扫描(R1-R6)、质量度量(MI/CC/健康分)、回归防护。五阶段工作流配 4 个零依赖本地脚本(archscan/depgraph/riskdiagnose/qualitymetrics/regressionguard),全部输出 JSON。在架构审查、技术债评估、代码重构、质量提升、工程结构评审时调用。.

bfxh/arch-optimize · 103 tokens

code-simplification

Simplifies code for clarity. Use when refactoring code for clarity without changing behavior. Use when code works but is harder to read, maintain, or extend than it should be. Use when reviewing code that has accumulated unnecessary complexity.

vanja-emichi/a0_agent_skills · 51 tokens

refactoring

Improve code structure without changing behavior using proven refactoring patterns. Use when cleaning up code, reducing duplication, improving readability, or restructuring modules.

asgarovf/locusai · 31 tokens

software-code-refactoring

Improve production code quality while preserving all existing test behavior. Commonly used for the Refactor phase of TDD red-green-refactor, but applicable to any codebase with tests. Use when production code works but needs cleanup — reducing duplication, improving naming, simplifying complexity, aligning with…

stencila/stencila · 102 tokens

simplify-codebase

Simplification audit or authorized codebase simplification whose stated objective is to remove accidental complexity. Use for evidence-backed deletion or consolidation of dead code, duplicate state, redundant APIs or layers, ownerless abstractions, obsolete compatibility or design records, and over-engineering in any…

tt-a1i/simplify-codebase · 93 tokens