gf-refactor

gf-refactor is a skill for Claude Code from byx-darwin/gitflow-cli. It costs 100 tokens per session (4,504 once invoked), scanned A, original, MIT.

A step-by-step method for changing code structure without changing its behavior, using named techniques such as extracting a function or replacing a conditional with polymorphism. It requires existing test coverage and checks the build and tests after each change.

In plain words
What is it for?
It is for applying behavior-preserving refactors, simplifying complex code, and keeping tests passing during the refactoring stage of test-driven development.
Why use it?
It limits the risk of breaking working code during cleanup by making one structural change at a time and verifying the result.

Skill for Claude Code

Written for Claude Code: allowed-tools in frontmatter.

Part of the gitflow-cli plugin — 30 skills shipped together

Good fit It is for applying behavior-preserving refactors, simplifying complex code, and keeping tests passing during the refactoring stage of test-driven development.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/byx-darwin/gitflow-cli/gf-refactor
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 byx-darwin/gitflow-cli --skill gf-refactor
Clone the repo
git clone --depth 1 https://github.com/byx-darwin/gitflow-cli

Made for: Claude Code.

Or install gitflow-cli, the plugin that ships this one along with the rest of its 30 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 gf-refactor

README.md
[![agentmods](https://agentmods.dev/badge/skills/byx-darwin/gitflow-cli/gf-refactor/github.svg)](https://agentmods.dev/skills/byx-darwin/gitflow-cli/gf-refactor)
Your own site
<a href="https://agentmods.dev/skills/byx-darwin/gitflow-cli/gf-refactor"><img src="https://agentmods.dev/badge/skills/byx-darwin/gitflow-cli/gf-refactor/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 gf-refactor

Your own site · 80×15
<a href="https://agentmods.dev/skills/byx-darwin/gitflow-cli/gf-refactor"><img src="https://agentmods.dev/badge/skills/byx-darwin/gitflow-cli/gf-refactor.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 100 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 4,504 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.00100 $0.04504
Opus 5.5 $0.00040 $0.01802
Sonnet 5.5 $0.00020 $0.00901
Haiku 4.5 $0.00010 $0.00450

Measured 24d ago against content hash 2595be74d11b, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

gf-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 24d 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/gf-refactor/SKILL.md · 321 lines

How it starts

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

gf-refactor — Fowler Catalog-Driven Behavior-Preserving Refactoring

Executes RED→GREEN→REFACTOR's third stage: applies Fowler's refactoring catalog to code that already has test coverage, one technique at a time, verifying build and tests after every step. Downstream of /gf-smell (finds problems) — this skill fixes them structurally, never behaviorally.

Preconditions

  • Target code has test coverage; if not, do not refactor it — see When NOT to Refactor
  • Language layer's build/test tooling installed — see references/<lang>.md
  • Clean working tree before starting (uncommitted changes make the Safety Protocol's revert step ambiguous)

When to Use

English 中文 Context
refactor this function 重构这个函数 apply a technique, not rewrite
extract function / method 提炼函数 reduce size/complexity
replace conditional with polymorphism 以多态取代条件表达式 eliminate type-code branching
clean up while keeping tests green 边清理边保绿 TDD REFACTOR stage
is this refactor safe 这个重构安全吗 semantic risk question

When NOT to Use

Scenario Why Not Use Instead
Finding smells/candidates in the first place This skill acts on candidates, it does not hunt for them /gf-smell
Pre-delivery quality gate This skill changes structure, not gate pass/fail /gf-quality
Any change to observable behavior is wanted Not a refactor by definition Regular TDD RED→GREEN change, separate commit

When NOT to Refactor

Scenario Why Not
Code path has 无测试覆盖 Nothing verifies behavior was preserved; write the test first, or refuse
The technique is tagged 条件等价/可能变更 and its precondition is unverified Downgrade to suggestion per Semantic Safety Boundary — do not touch the code
A behavior change is also wanted alongside Split into two changes; refactor first (green), then the behavior change as its own commit
Code is about to be deleted No return on refactoring investment

Read the full file on GitHub · 321 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. 24d ago Changed · +1 lines 2595be74d11b
  2. 28d ago First seen · 320 lines · 100 tokens per session scan A b7b7dc4495a3

Subscribe to this mod's changes

gf-refactor is a skill published in the GitHub repository byx-darwin/gitflow-cli (3 stars, last pushed 22d ago), licensed MIT. It adds 100 tokens to every session and 4,504 once invoked, about $0.0004 per session on Opus 5.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-19.

Related

Other skills, from other repositories

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

software-test-review

Evaluate the quality of TDD tests against slice acceptance criteria, codebase conventions, and Red-phase execution results, producing a structured review with Accept or Revise recommendations. Use when tests written during the Red phase of red-green-refactor need quality review — checking coverage of acceptance…

stencila/stencila · 127 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

ring:running-dev-cycle

Running the backend dev cycle: implements every task in a rolling-wave plan.md (ring:writing-plans format) for a Go/TS service, driving specialist agents through Gate 0 implementation/TDD, Gate 8 parallel review, and Gate 9 validation per epic, elaborating later phases at each phase boundary. Use when starting or…

LerianStudio/ring · 122 tokens

gentle-ai

Use Gentle AI harness discipline for Pi work: clarify first, preserve OpenSpec artifacts, use strict TDD where available, delegate through subagents when useful, and protect review workload.

Gentleman-Programming/gentle-pi · 40 tokens

ring:instrumenting-streaming-events

Instrumenting streaming events: wires lib-streaming event emission end-to-end into a Lerian Go service via a 13-gate cycle (catalog, Builder bootstrap, Emit sites, outbox, HTTP manifest, NoopEmitter fallback, integration and chaos tests), dispatching ring:backend-go under TDD. Consumes the validated…

LerianStudio/ring · 102 tokens