Agent skill

TDD Refactor Step

by ruby-git in ruby-git/ruby-git

Guides the REFACTOR step of the TDD cycle — identifying code smells, applying safe refactoring techniques, cleaning test code, and verifying with rubocop.

MITAuto-check passedDevelopment

Install TDD Refactor Step

skills CLI
$ npx skills add ruby-git/ruby-git --skill tdd-refactor-step -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install ruby-git/ruby-git tdd-refactor-step --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/ruby-git/ruby-git.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.github/skills/tdd-refactor-step .claude/skills/tdd-refactor-step && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
tdd-refactor-step
GitHub stars
1.8k
Token cost
~2k tokens
SKILL.md length
789 words
Files
1
Skills in repo
30
Repo updated
First seen
Licence
MIT

At a glance

Guides the REFACTOR step of the TDD cycle — identifying code smells, applying safe refactoring techniques, cleaning test code, and verifying with rubocop.

  • Works in 3 steps: Tests still pass: bundle exec rspec for… → No new rubocop offenses: bundle exec… → Behavior unchanged: No new test was…
  • Tasks that involve Refactoring
  • SKILL.md covers Contents, How to use this skill, Related skills and Decision: refactor or skip, plus 7 more sections
  • Calls bundle and git

What it does

TDD Refactor Step is an agent skill from ruby-git/ruby-git. Guides the REFACTOR step of the TDD cycle — identifying code smells, applying safe refactoring techniques, cleaning test code, and verifying with rubocop. Use during RED-GREEN-REFACTOR when deciding what and how to refactor after making a test pass.

Its SKILL.md is about 2k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Development, covering Refactoring and Test-driven development. The repository describes itself as: Ruby/Git is a Ruby library that can be used to create, read and manipulate Git repositories by wrapping system calls to the git binary. The licence is MIT.

When your agent uses it

  • Tasks that involve Refactoring
  • Tasks that involve Test-driven development

Example prompts

  • “Use the tdd-refactor-step skill to guide the REFACTOR step of the TDD cycle — identifying code smells, applying safe refactoring techniques…”
  • “/tdd-refactor-step”

Workflow steps

3 steps, taken from the first numbered list in SKILL.md.

  1. Tests still pass: bundle exec rspec for the current task's
  2. No new rubocop offenses: bundle exec rubocop $(git diff --name-only HEAD)
  3. Behavior unchanged: No new test was added during REFACTOR — if you need

What it can do on your machine

Read from SKILL.md and the folder at commit f3bf20f. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • bundle
    • git

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use git, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

TDD Refactor Step loads about 2k tokens when it runs. Until then it costs about 67 tokens; SKILL.md has 789 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~67
When it runs · the whole SKILL.md, loaded when a task matches
~2k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from ruby-git/ruby-git at commit f3bf20f, republished under its MIT licence (© ruby-git). 789 words, ~1,960 tokens.

Download SKILL.mdSave it as .claude/skills/tdd-refactor-step/SKILL.md (or your agent's skills folder).
name
tdd-refactor-step
description
Guides the REFACTOR step of the TDD cycle — identifying code smells, applying safe refactoring techniques, cleaning test code, and verifying with rubocop. Use during RED-GREEN-REFACTOR when deciding what and how to refactor after making a test pass.

TDD Refactor Step

Concrete guidance for the REFACTOR step of the RED-GREEN-REFACTOR cycle. Covers code smells to look for, safe refactoring techniques, test code cleanup, rubocop integration, and verification.

Contents

How to use this skill

Invoke this skill during the REFACTOR step of the TDD cycle, after GREEN (all tests pass). This skill expands the guidance in the Development Workflow REFACTOR step.

Typical invocation:

text
I just got to green. Walk me through the REFACTOR step using
the TDD Refactor Step skill.

Decision: refactor or skip

Not every GREEN step needs refactoring. Skip when all of the following are true:

  • No hardcoded values from the GREEN step remain
  • No duplication was introduced between new and existing code
  • No method exceeds ~10 lines
  • No parameter list exceeds 3 positional parameters
  • Rubocop reports no new offenses on changed files
  • Test setup is not duplicated across examples

If any condition is false, proceed with the relevant technique below.

Code smells checklist

Check the code written or modified in this task for these smells, in priority order:

#SmellThresholdAction
1Hardcoded values from GREEN stepAnyGeneralize to actual logic
2Duplication between new code and existing code≥ 3 similar linesExtract shared method or constant
3Long method> 10 lines (body)Extract private helper
4Long parameter list> 3 positional paramsConvert trailing params to keyword arguments
5Inconsistent namingDeviates from file/module conventionsRename to match existing patterns
6Deeply nested conditionals> 2 levelsExtract guard clause or helper
7Feature envyMethod uses another object's data more than its ownMove method or extract delegator
8Dead codeUnreachable branches, unused variablesRemove

Limit yourself to smells in files you touched this task. Broader cleanup belongs in a separate task (add it during REPLAN).

Refactoring techniques

Apply the simplest technique that resolves the smell:

Extract method

Split a long method into a public method and one or more private helpers. Name the helper after what it does, not how:

ruby
# Before
def call(*, **)
  bound = args_definition.bind(*, **)
  objects = Array(bound.object).map { |o| "#{o}\n" }.join
  with_stdin(objects) { |r| run_batch(bound, r) }
end

# After
def call(*, **)
  bound = args_definition.bind(*, **)
  with_stdin(stdin_content(bound)) { |r| run_batch(bound, r) }
end

private

def stdin_content(bound)
  Array(bound.object).map { |o| "#{o}\n" }.join
end
Convert positional to keyword arguments

When a method accumulates optional trailing positional parameters:

ruby
# Before
def initialize(args, options, positionals, exec_names = [], flags = [])

# After
def initialize(args, options, positionals, exec_names: [], flags: [])

Update the single call site at the same time.

Replace conditional with guard clause
ruby
# Before
def validate(value)
  if value
    if value.is_a?(String)
      process(value)
    end
  end
end

# After
def validate(value)
  return unless value
  return unless value.is_a?(String)

  process(value)
end
Introduce constant

When a magic value appears in logic:

ruby
# Before
raise error if version < Git::Version.parse('2.43.0')

# After
MINIMUM_GIT_VERSION = Git::Version.parse('2.43.0')
raise error if version < MINIMUM_GIT_VERSION
Eliminate duplication with shared setup

When two methods share identical preamble or teardown, extract the shared part. If the duplication is in tests, see Test Code Refactoring below.

Show full SKILL.md (354 more words)Show less

Test code refactoring

Test code deserves the same refactoring attention as production code:

SmellTechnique
Duplicated let/before across contextsMove to nearest shared describe or context
Long example bodies (> 5 lines of setup)Extract to let declarations or before block
Repeated literal valuesExtract to let or constant at top of file
Identical examples across filesExtract to shared example group (shared_examples)
Unclear example descriptionsRewrite to state expected behavior, not implementation

Follow the RSpec Unit Testing Standards for the resulting test structure.

Rubocop integration

Run rubocop on changed files after refactoring:

bash
bundle exec rubocop $(git diff --name-only HEAD)

Focus on:

  • Metrics/MethodLength — methods over the configured limit
  • Metrics/ParameterLists — too many parameters
  • Metrics/AbcSize — complexity threshold
  • Style cops — naming, formatting consistency

Auto-correct safe offenses when appropriate:

bash
bundle exec rubocop -a $(git diff --name-only HEAD)

Do not auto-correct Metrics cops — those require structural changes (extract method, split class), not formatting fixes.

Verification

After refactoring, confirm:

  1. Tests still pass: bundle exec rspec <spec_file> for the current task's test file(s)
  2. No new rubocop offenses: bundle exec rubocop $(git diff --name-only HEAD)
  3. Behavior unchanged: No new test was added during REFACTOR — if you need a new test, you skipped a RED step

If any test fails after refactoring, the refactoring changed behavior. Revert and try a smaller change.

Project-specific patterns

Patterns specific to this codebase that the REFACTOR step should enforce:

  • Command classes should not contain parsing logic — if refactoring reveals parsing in a command class, flag it for extraction (separate task)
  • Arguments DSL Bound metadata uses keyword arguments — if adding new metadata fields, follow the keyword argument pattern
  • Error classes inherit from Git::Error — ensure new errors follow the hierarchy in lib/git/errors.rb
  • freeze constants — all new constants should be frozen (CONSTANT = value.freeze)
  • Private methods go below a single private keyword, not inline private def

Boundaries

Things the REFACTOR step must not do:

  • Add new behavior — no new features, no new test cases
  • Change public API — method signatures visible to users stay the same
  • Touch unrelated files — scope to files modified in this task; add broader refactoring to the task list during REPLAN
  • Optimize prematurely — clarity over performance unless profiling data exists
  • Over-abstract — do not create a helper for something used exactly once

© ruby-git, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .github/skills/tdd-refactor-step of ruby-git/ruby-git.

Open the folder on GitHubat commit f3bf20f

Compare with similar skills

TDD Refactor Step next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

TDD Refactor Step compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
TDD Refactor Step this skillruby-git/ruby-git1.8k—~2kAutomated safety check: PassMIT
Skill Writingmillionco/expect3.6k—~1.8kAutomated safety check: PassCustom licence
Go Rigmudrii/openclaw-dashboard457—~2.8kAutomated safety check: PassMIT
Go Rigmudrii/openclaw-dashboard457—~682Automated safety check: PassMIT
Py Rigmudrii/hermesd119—~6.3kAutomated safety check: PassMIT
Happier Implementhappier-dev/happier1.9k—~4.2kAutomated safety check: PassMIT

Similar skills

  • Skill Writing

    millionco/expect

    Write and improve agent skills (SKILL.md files). An agent skill from millionco/expect.

    3.6k GitHub stars~1.8k tokensUpdated 5 mo ago
    DevelopmentAuto-check passed
  • Go Rig

    mudrii/openclaw-dashboard

    A skill your agent uses when building, reviewing, or refactoring Go code that must follow strict design discipline — ATDD/TDD workflow, explicit dependency injection, package-boundary discipline…

    457 GitHub stars~2.8k tokensUpdated 14 days ago
    DevelopmentAuto-check passed
  • Go Rig

    mudrii/openclaw-dashboard

    A skill your agent uses when building, reviewing, or refactoring Go code in this repository.

    457 GitHub stars~682 tokensUpdated 14 days ago
    DevelopmentAuto-check passed
  • Py Rig

    mudrii/hermesd

    A skill your agent uses when building, reviewing, or refactoring Python code that requires strong maintainability discipline: SRP, DRY, OCP, explicit dependency injection, TDD/ATDD workflow, strict…

    119 GitHub stars~6.3k tokensUpdated 6 days ago
    DevelopmentAuto-check passed
  • Happier Implement

    happier-dev/happier

    Implement, change, build, fix, refactor, migrate, or apply accepted review findings in the Happier repositories with canonical-owner discovery, scope-preserving solution economy, TDD, efficient…

    1.9k GitHub stars~4.2k tokensUpdated today
    DevelopmentAuto-check passed
  • Omk Coding

    KaimingWan/oh-my-kiro

    Enforces coding best practices: deep-read before modify, LSP-first navigation, TDD red-green-refactor, minimal changes, self-review, verification.

    107 GitHub stars~2.4k tokensUpdated 6 mo ago
    DevelopmentAuto-check passed

More from ruby-git/ruby-git

All 30 skills in this repo
  • Addresses unresolved pull request review threads and suppressed (low-confidence) Copilot review comments on the current branch, folds each fix into the…

    1.8k GitHub stars~657 tokensUpdated 5 days ago
    Auto-check passed
  • Breaking Change Analysis

    ruby-git/ruby-git

    Assesses what an API change would break before it is made, finds every usage, documents the impact and plans a deprecation or migration path.

    1.8k GitHub stars~1.7k tokensUpdated 5 days ago
    Auto-check passed
  • Diagnoses and fixes failing GitHub Actions runs by identifying the failure, fetching only the relevant logs, finding the root cause and reproducing it locally.

    1.8k GitHub stars~1.9k tokensUpdated 5 days ago
    Auto-check passed
  • Scaffolds and reviews `Git::Commands::*` classes in the ruby-git library, with unit tests, integration tests and YARD docs, using the Base command architecture.

    1.8k GitHub stars~3k tokensUpdated 5 days ago
    Auto-check passed
  • Gem Dependency Management

    ruby-git/ruby-git

    Workflow for updating gem dependencies and fixing CVEs in the ruby-git project: assess with bundle outdated and audit, edit the gemspec, test, then commit with conventional messages.

    1.8k GitHub stars~806 tokensUpdated 5 days ago
    Auto-check passed
  • Migrates a direct command call in Ruby Git's Git::Lib to a Git::Commands class, as part of a Strangler Fig redesign, with a plan, legacy tests and a pull request.

    1.8k GitHub stars~4.4k tokensUpdated 5 days ago
    Auto-check passed

Questions about TDD Refactor Step

What does TDD Refactor Step do?

Guides the REFACTOR step of the TDD cycle — identifying code smells, applying safe refactoring techniques, cleaning test code, and verifying with rubocop. TDD Refactor Step is an agent skill from ruby-git/ruby-git. Guides the REFACTOR step of the TDD cycle — identifying code smells, applying safe refactoring techniques, cleaning test code, and verifying with rubocop.

When should I use TDD Refactor Step?

TDD Refactor Step fits situations like: tasks that involve Refactoring; tasks that involve Test-driven development.

How do I install TDD Refactor Step in Claude Code?

Run `npx skills add ruby-git/ruby-git --skill tdd-refactor-step -a claude-code`. Or copy the skill folder (.github/skills/tdd-refactor-step in ruby-git/ruby-git) into .claude/skills/tdd-refactor-step in your project. Claude Code loads it when a task matches its description.

How do I install TDD Refactor Step in Codex?

Run `npx skills add ruby-git/ruby-git --skill tdd-refactor-step -a codex`. Or copy the skill folder (.github/skills/tdd-refactor-step in ruby-git/ruby-git) into .agents/skills/tdd-refactor-step in your project. Codex loads it when a task matches its description.

Can I use TDD Refactor Step in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add ruby-git/ruby-git --skill tdd-refactor-step -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/tdd-refactor-step, .gemini/skills/tdd-refactor-step, .github/skills/tdd-refactor-step and .opencode/skills/tdd-refactor-step in your project.

What does TDD Refactor Step need to run?

Going by SKILL.md and its folder, TDD Refactor Step needs the command-line tools its instructions call (bundle and git).

Does TDD Refactor Step access the network?

SKILL.md contains no URLs. Its commands use git, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is TDD Refactor Step safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does TDD Refactor Step use?

TDD Refactor Step is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does TDD Refactor Step use?

About 2k tokens (SKILL.md is roughly 7.8k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to TDD Refactor Step?

Skills that share tags, products or a category with TDD Refactor Step: Skill Writing (millionco/expect, 3.6k stars), Go Rig (mudrii/openclaw-dashboard, 457 stars), Go Rig (mudrii/openclaw-dashboard, 457 stars) and Py Rig (mudrii/hermesd, 119 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains TDD Refactor Step?

ruby-git (a GitHub organization) maintains it in ruby-git/ruby-git, which has 1,799 GitHub stars. The repository holds 30 skills in this directory. The repository was last updated on October 2, 2026.

Source: ruby-git/ruby-git on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.