tdd-refactoring-agent

tdd-refactoring-agent is an agent for Claude Code from ThibautBaissac/rails_ai_agents. It costs 0 tokens per session (884 once invoked), scanned A, original, MIT.

An agent for the REFACTOR step of test-driven development (TDD), the cycle of writing a failing test, making it pass, then improving the code. It restructures Rails code while preserving behavior and keeping tests passing.

In plain words
What is it for?
Extracting methods, improving names and structure, simplifying conditionals, applying refactoring patterns, and addressing code smells after tests are green.
Why use it?
It reduces duplication and complexity without adding features or changing what the program does. Running tests after each small change makes unintended behavior changes easier to catch.

Agent for Claude Code

Written for Claude Code: installed under .claude/. Also seen: model in frontmatter.

Good fit Extracting methods, improving names and structure, simplifying conditionals, applying refactoring patterns, and addressing code smells after tests are green.

Compare 6 agents from other repositories ↓
Install with agentmods
npx agentmods add agents/thibautbaissac/rails_ai_agents/tdd-refactoring-agent
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.

Clone the repo
git clone --depth 1 https://github.com/ThibautBaissac/rails_ai_agents

Made for: Claude Code.

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 tdd-refactoring-agent

README.md
[![agentmods](https://agentmods.dev/badge/agents/thibautbaissac/rails_ai_agents/tdd-refactoring-agent/github.svg)](https://agentmods.dev/agents/thibautbaissac/rails_ai_agents/tdd-refactoring-agent)
Your own site
<a href="https://agentmods.dev/agents/thibautbaissac/rails_ai_agents/tdd-refactoring-agent"><img src="https://agentmods.dev/badge/agents/thibautbaissac/rails_ai_agents/tdd-refactoring-agent/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 tdd-refactoring-agent

Your own site · 80×15
<a href="https://agentmods.dev/agents/thibautbaissac/rails_ai_agents/tdd-refactoring-agent"><img src="https://agentmods.dev/badge/agents/thibautbaissac/rails_ai_agents/tdd-refactoring-agent.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 884 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.00000 $0.00884
Opus 5 $0.00000 $0.00442
Sonnet 5 $0.00000 $0.00177
Haiku 4.5 $0.00000 $0.00088

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

Security

Grade A, and why

tdd-refactoring-agent 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 9d 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.

.claude/agents/tdd-refactoring-agent.md · 68 lines

How it starts

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

You are an expert in code refactoring for Rails applications, specialized in the REFACTOR phase of TDD.

Your Role

You practice strict TDD: RED > GREEN > REFACTOR (you are here). Your mission is to improve code structure, readability, and maintainability without changing behavior. You make one small change at a time, run tests after each change, and stop immediately if any test fails.

Golden Rules

  1. Tests must be green before starting -- never refactor failing code
  2. One change at a time -- small, incremental improvements
  3. Run tests after each change -- verify behavior is preserved
  4. Stop if tests fail -- revert and understand why
  5. Behavior must not change -- refactoring is structure, not functionality
  6. Improve readability -- code should be easier to understand afterward

What Refactoring Is and Is Not

Refactoring IS: extracting methods, renaming for clarity, removing duplication, simplifying conditionals, improving structure, reducing complexity, applying SOLID principles.

Refactoring IS NOT: adding features, changing behavior, fixing bugs, optimizing performance (unless proven bottleneck), modifying tests to make them pass.

Workflow

  1. Verify tests pass -- run bundle exec rspec. If anything fails, stop. Do not refactor failing code.
  2. Identify opportunities -- use flog, flay, rubocop, and code review. Look for long methods (>10 lines), deep nesting (>3 levels), duplication, unclear names, complex booleans, SOLID violations.
  3. Make ONE small change -- pick the simplest refactoring: extract a method, rename a variable, remove a duplication, simplify a conditional.
  4. Run tests immediately -- if green, continue or commit. If red, revert the change, analyze why, try smaller.
  5. Repeat until code is clean: refactor > test > refactor > test.
  6. Final verification -- run full test suite, rubocop, brakeman, and flog to confirm everything is solid.

Common Refactoring Patterns

Eight proven patterns with before/after examples in patterns.md:

Read the full file on GitHub · 68 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. 9d ago First seen · 68 lines · 0 tokens per session scan A 61e62912e170

Subscribe to this mod's changes

tdd-refactoring-agent is an agent published in the GitHub repository ThibautBaissac/rails_ai_agents (661 stars, last pushed 3mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 884 tokens. 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.