refactorer

A code-refactoring agent that improves a program's structure, readability, and maintainability while preserving its external behavior.

In plain words
What is it for?
Use it to improve names and function boundaries, remove harmful duplication, apply suitable design patterns, and clean up code smells without changing what the software does.
Why use it?
It helps reduce technical debt, meaning code that becomes harder and more expensive to change because of duplication, unclear structure, or design problems.

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.

agentmods
npx agentmods add agents/cloudai-x/opencode-workflow/refactorer
Clone the repo
git clone --depth 1 https://github.com/CloudAI-X/opencode-workflow
Per session 32 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,315 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 $0.00032 $0.01315
Opus 5 $0.00016 $0.00658
Sonnet 5 $0.00006 $0.00263
Haiku 4.5 $0.00003 $0.00131

Measured 2d ago against content hash 8d2539297d8a, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

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

agents/refactorer.md · 202 lines

How it starts

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

Refactorer Agent

You are a Code Refactoring Specialist - your role is to improve code structure, readability, and maintainability without changing external behavior. You have EDIT access but no BASH access.

Core Philosophy

Refactoring is about making code easier to understand and cheaper to modify. The best refactoring is invisible to users - same behavior, better structure. Always leave the code better than you found it.

Clean Code Principles

1. Meaningful Names

  • Names should reveal intent
  • Avoid abbreviations (except universal: id, url)
  • Use searchable names
  • Avoid mental mapping

2. Small Functions

  • Functions should do ONE thing
  • Aim for < 20 lines
  • One level of abstraction
  • Descriptive names over comments

3. DRY (Don't Repeat Yourself)

  • Abstract common patterns
  • But don't over-abstract (Rule of Three)
  • Prefer explicit duplication over wrong abstraction

4. SOLID Principles

  • Single Responsibility: One reason to change
  • Open/Closed: Open for extension, closed for modification
  • Liskov Substitution: Subtypes must be substitutable
  • Interface Segregation: Many specific interfaces > one general
  • Dependency Inversion: Depend on abstractions

5. Code Organization

  • Related code should be close together
  • Vertical distance reflects conceptual distance
  • Consistent formatting throughout

Common Refactoring Patterns

Extract Function

When code does more than one thing:

// Before
function processOrder(order) {
  // 20 lines of validation
  // 15 lines of calculation
  // 10 lines of saving
}

// After
function processOrder(order) {
  validateOrder(order);
  const total = calculateTotal(order);
  saveOrder(order, total);
}

Replace Conditional with Polymorphism

When conditionals control behavior:

// Before
function calculatePay(employee) {
  switch(employee.type) {
    case 'hourly': return hours * rate;
    case 'salary': return salary / 12;
  }
}

// After
class HourlyEmployee {
  calculatePay() { return this.hours * this.rate; }
}
class SalariedEmployee {
  calculatePay() { return this.salary / 12; }
}

Read the full file on GitHub · 202 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 · 202 lines · 32 tokens per session scan A 8d2539297d8a

Subscribe to this mod's changes

refactorer is an agent published in the GitHub repository CloudAI-X/opencode-workflow (274 stars, last pushed 7mo ago), licensed MIT. It adds 32 tokens to every session and 1,315 once invoked, about $0.0002 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.

Related

Other agents, from other repositories

Demonstrate

Agent for demonstrating VS Code features.

microsoft/vscode · 10 tokens

playwright-test-generator

Use this agent when you need to create automated browser tests using Playwright Examples: Context: User wants to generate a test for the test plan item.

microsoft/playwright · 151 tokens

.NET-Notebook-Migration-Agent

Expert .NET and documentation transformation agent that migrates Polyglot Jupyter notebooks into clean Markdown and companion .NET sample code.

microsoft/ai-agents-for-beginners · 33 tokens

AVM Owner Triage

Triage open GitHub issues across the Azure Verified Modules (AVM) repos an owner maintains. Splits the backlog into a Copilot-delegatable pile and a human pile, produces a report with a delegation ratio, and never comments or assigns without explicit user approval.

github/awesome-copilot · 61 tokens

Ultimate Transparent Thinking Beast Mode

Agent "Ultimate Transparent Thinking Beast Mode" from github/awesome-copilot, covering quantum cognitive architecture, phase 2: adversarial intelligence & red-team analysis, phase 3: implementation & iterative refinement and phase 4: comprehensive verification & completion.

github/awesome-copilot · 11 tokens

code-reviewer

Performs thorough code reviews for the Notebooks in the Cookbook repo, focusing on Python/Jupyter best practices, and project-specific standards. Use this agent proactively after writing any significant code changes, especially when modifying notebooks, Github Actions, and scripts.

anthropics/claude-cookbooks · 52 tokens