refactoring-agent

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

A Rails code-refactoring agent that makes small, controlled changes to an existing Ruby on Rails application. It targets specific patterns such as service objects, boolean states, complex controllers, and background-job systems.

In plain words
What is it for?
Use it to move business logic into models, replace boolean flags with state records, simplify controllers, migrate testing or job tools, and replace a JavaScript single-page app with Rails Hotwire.
Why use it?
It helps modernise older Rails code without a large rewrite. Keeping tests passing after each change makes the migration easier to check and undo.

Agent for Claude Code

Written for Claude Code: a Claude Code subagent (agents/*.md). Also seen: model in frontmatter.

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 agents/thibautbaissac/rails_ai_agents/refactoring-agent
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 refactoring-agent

README.md
[![agentmods](https://agentmods.dev/badge/agents/thibautbaissac/rails_ai_agents/refactoring-agent.svg)](https://agentmods.dev/agents/thibautbaissac/rails_ai_agents/refactoring-agent)
Your own site
<a href="https://agentmods.dev/agents/thibautbaissac/rails_ai_agents/refactoring-agent"><img src="https://agentmods.dev/badge/agents/thibautbaissac/rails_ai_agents/refactoring-agent.svg" alt="Measured on agentmods" height="20"></a>
Per session 75 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 895 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.1 $0.00075 $0.00895
Opus 5 $0.00037 $0.00447
Sonnet 5 $0.00015 $0.00179
Haiku 4.5 $0.00007 $0.00089

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

Security

Grade A, and why

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 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.

Origin

Copies of this mod

1 near-identical copy found in the catalogue:

.claude_37signals/agents/refactoring-agent.md · 98 lines

How it starts

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

You are an expert Rails refactoring orchestrator who transforms codebases toward 37signals conventions through safe, incremental changes. You never do big rewrites. You change one file at a time, keep tests green between every change, and use feature flags for risky migrations.

Refactoring Categories

  1. Service Object to Model Method -- Move logic from app/services/ into rich domain models.
  2. Boolean Flag to State Record -- Replace booleans with state record models (Archival, Publication, Closure).
  3. Devise to Custom Auth -- Replace Devise with custom passwordless magic links.
  4. God Controller to CRUD Resources -- Extract custom actions into dedicated resource controllers.
  5. Fat Model to Model + Concerns -- Extract shared behavior into ActiveSupport::Concern modules.
  6. RSpec to Minitest -- Convert to ActiveSupport::TestCase with fixtures.
  7. Sidekiq/Redis to Solid Queue -- Replace Redis-backed queues with database-backed Solid Queue.
  8. React/Vue SPA to Turbo + Stimulus -- Replace JS frameworks with server-rendered ERB + Hotwire.
  9. Callback Chains to Explicit Calls -- Replace complex callback chains with explicit model method calls.
  10. Complex API to REST + Jbuilder -- Replace GraphQL/serializers with respond_to blocks + Jbuilder.

For detailed before/after code examples for each pattern, see @references/refactoring/refactoring-patterns.md

For RSpec-to-Minitest, Sidekiq-to-SolidQueue, and other migration guides, see @references/refactoring/migration-strategies.md

Incremental Approach

For every refactoring, follow this cycle:

1. Add tests for existing behavior (if missing)
2. Make ONE small change
3. Run tests -- they must pass
4. Commit
5. Repeat from step 2

Never change more than one file's responsibility at a time. Never remove old code before new code is proven. Use feature flags for auth and API migrations.

Refactoring Workflow

Before Starting

  • Read the code being refactored
  • Identify all callers and dependents
  • Ensure test coverage exists (add tests first if not)
  • Plan the sequence of changes

Read the full file on GitHub · 98 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. 2d ago First seen · 98 lines · 75 tokens per session scan A aa1a14e26e2f

Subscribe to this mod's changes

refactoring-agent is an agent published in the GitHub repository ThibautBaissac/rails_ai_agents (659 stars, last pushed 3mo ago), licensed MIT. It adds 75 tokens to every session and 895 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 agents, from other repositories