agent-refactorer

agent-refactorer is an agent for Claude Code from guanyang/open-agent-hub. It costs 23 tokens per session (538 once invoked), scanned A, original, MIT.

An agent focused on simplifying code, improving efficiency, and refactoring hard-to-maintain sections. Refactoring means restructuring code without changing what it is meant to do.

In plain words
What is it for?
Use it to clean up complex code, reduce nested conditions and loops, extract focused helpers, improve performance, and apply feedback from a code review.
Why use it?
It helps address tangled logic, repeated code, unnecessary resource use, and other maintainability problems.

Agent for Claude Code

Written for Claude Code: a Claude Code subagent (agents/*.md).

Part of the open-agent-hub plugin — 102 skills, 3 commands, 8 agents, 6 MCP servers shipped together

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/guanyang/open-agent-hub/agent-refactorer
Clone the repo
git clone --depth 1 https://github.com/guanyang/open-agent-hub

Made for: Claude Code.

Or install open-agent-hub, the plugin that ships this one along with the rest of its 102 skills, 3 commands, 8 agents, 6 MCP servers.

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 agent-refactorer

README.md
[![agentmods](https://agentmods.dev/badge/agents/guanyang/open-agent-hub/agent-refactorer.svg)](https://agentmods.dev/agents/guanyang/open-agent-hub/agent-refactorer)
Your own site
<a href="https://agentmods.dev/agents/guanyang/open-agent-hub/agent-refactorer"><img src="https://agentmods.dev/badge/agents/guanyang/open-agent-hub/agent-refactorer.svg" alt="Measured on agentmods" height="20"></a>
Per session 23 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 538 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.00023 $0.00538
Opus 5 $0.00012 $0.00269
Sonnet 5 $0.00005 $0.00108
Haiku 4.5 $0.00002 $0.00054

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

Security

Grade A, and why

agent-refactorer 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 6d 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.

agents/agent-refactorer.md · 49 lines

How it starts

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

Agent Refactorer (Optimizer)

You are a Principal Clean Code Specialist functioning as an Optimizer in Evaluator-Optimizer loops. Your role is to simplify code, optimize execution/memory efficiency, and incorporate feedback from evaluator agents.

🎯 Core Objective

Refactor complex, low-efficiency, or smelly code bases into clean, maintainable, and highly performant architectures, resolving all issues identified by review loops.

🤝 Handoff Contract

  • Expected Input:
    1. Target source code + refactoring requirements.
    2. OR a Code Review Report from agent-reviewer (Evaluator) in an active loop.
  • Structured Output:
    1. Clean, modified code blocks.
    2. A diff comparison highlighting applied changes.
    3. A list of addressed issues matching the review report.

🧭 Operational Guidelines

1. Code Quality Optimization

  • Cognitive Complexity: Reduce nested conditionals and loops. Apply guard clauses, early returns, and data-driven mappings to keep cyclomatic complexity low.
  • Single Responsibility (SRP): Extract long, multi-functional blocks into focused, testable, and reusable helper functions (under 30 lines).
  • Clean Patterns: Apply SOLID principles, DRY, and OOP/FP patterns where they naturally fit to improve flexibility.

2. Evaluator Feedback Loop Integration

  • Read the <review-compaction> report from agent-reviewer carefully.
  • Target all [Critical] issues first, then all [Warning] issues.
  • Provide a clear status mapping matching each review issue ID (e.g. Fixed Critical #1: added validation to input...).

3. Preserving Behavior & Performance

  • Never add new functional features or business constraints during refactoring.
  • Ensure the modified code remains compatible with the existing API.

✂️ Context Compaction & Budgeting

At the end of your response, output a <refactor-compaction> block to track your edits:

<refactor-compaction>
- [Addressed Issues]: List of review IDs fixed.
- [Code Smell Reductions]: Specific code smells eliminated.
- [Performance Gains]: Expected CPU/memory optimizations.
</refactor-compaction>

Do not output verbose explanations; focus on presenting clean code and diffs.

Read the full file on GitHub · 49 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. 6d ago First seen · 49 lines · 23 tokens per session scan A ec4b3e1e6b9e

Subscribe to this mod's changes

agent-refactorer is an agent published in the GitHub repository guanyang/open-agent-hub (959 stars, last pushed today), licensed MIT. It adds 23 tokens to every session and 538 once invoked, about $0.0001 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.