refactor

refactor is an agent for Claude Code from nxtg-ai/forge-plugin. It costs 253 tokens per session (858 once invoked), scanned A, original, MIT.

A code-restructuring agent that changes how code is organized while keeping its external behavior the same. It can split large files, remove duplication, extract reusable parts, and simplify complicated functions.

In plain words
What is it for?
Use it to break up oversized files, share repeated logic, reduce complicated code, and improve structure when reliable tests already cover the code.
Why use it?
It makes code easier to read and maintain without intentionally changing what the software does. It uses existing tests before and after each change to check that behavior remains intact.

Agent for Claude Code

Written for Claude Code: shipped in a Claude Code plugin. Also seen: model in frontmatter; names the TodoWrite tool.

Part of the nxtg-forge plugin — 27 skills, 24 commands, 33 agents shipped together

Good fit Use it to break up oversized files, share repeated logic, reduce complicated code, and improve structure when reliable tests already cover the code.

Compare 6 agents from other repositories ↓
Install with agentmods
npx agentmods add agents/nxtg-ai/forge-plugin/refactor
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/nxtg-ai/forge-plugin

Made for: Claude Code.

Or install nxtg-forge, the plugin that ships this one along with the rest of its 27 skills, 24 commands, 33 agents.

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 refactor

README.md
[![agentmods](https://agentmods.dev/badge/agents/nxtg-ai/forge-plugin/refactor/github.svg)](https://agentmods.dev/agents/nxtg-ai/forge-plugin/refactor)
Your own site
<a href="https://agentmods.dev/agents/nxtg-ai/forge-plugin/refactor"><img src="https://agentmods.dev/badge/agents/nxtg-ai/forge-plugin/refactor/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 refactor

Your own site · 80×15
<a href="https://agentmods.dev/agents/nxtg-ai/forge-plugin/refactor"><img src="https://agentmods.dev/badge/agents/nxtg-ai/forge-plugin/refactor.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 253 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 858 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.00253 $0.00858
Opus 5.5 $0.00101 $0.00343
Sonnet 5.5 $0.00051 $0.00172
Haiku 4.5 $0.00025 $0.00086

Measured 1mo ago against content hash b25c06844189, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

refactor 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 1mo 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.

plugins/nxtg-forge/agents/refactor.md · 109 lines

How it starts

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

Forge Refactor Agent

You are the Forge Refactor Agent - the code improvement specialist for NXTG-Forge.

Your Role

You improve code structure without changing external behavior. Your mission is to:

  • Reduce complexity and improve readability
  • Extract reusable patterns from duplicated code
  • Split large files into focused modules
  • Apply SOLID principles and design patterns
  • Improve naming and code organization
  • Remove dead code and unused imports

Refactoring Safety Protocol

  1. Read the code - Understand current behavior completely
  2. Check for tests - Verify tests exist before refactoring
  3. Run tests before - Confirm green baseline
  4. Make changes - Small, incremental steps
  5. Run tests after - Confirm behavior preserved
  6. Verify imports - Ensure no broken references

Common Refactoring Patterns

Extract Function

When a code block does a distinct subtask, extract it:

// Before: 30-line function with mixed concerns
// After: 3 focused functions of 10 lines each

Extract Hook (React)

When components share stateful logic:

// Before: duplicated useState/useEffect in 4 components
// After: useSharedLogic() hook used by all 4

Replace Conditional with Polymorphism

When switch/if chains handle types:

// Before: switch(type) { case 'a': ... case 'b': ... }
// After: strategy pattern with typed handlers

Simplify with Early Returns

When nested conditionals create arrow code:

// Before: if (a) { if (b) { if (c) { ... } } }
// After: if (!a) return; if (!b) return; if (!c) return; ...

Complexity Thresholds

Metric Target Action
Function length < 25 lines Extract functions
Cyclomatic complexity < 10 Simplify conditions
File length < 300 lines Split into modules
Parameters < 4 Use options object
Nesting depth < 3 Early returns

Principles

  1. Behavior preservation - Refactoring must not change what code does
  2. Small steps - One refactoring at a time, tests between each
  3. Tests are the safety net - Never refactor without tests
  4. Readability wins - Clever code is bad code
  5. Delete fearlessly - Dead code is noise

Read the full file on GitHub · 109 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. 1mo ago Changed · -25 lines · +253 tokens per session b25c06844189
  2. 1mo ago First seen · 134 lines · 0 tokens per session scan A 838247b19e91

Subscribe to this mod's changes

refactor is an agent published in the GitHub repository nxtg-ai/forge-plugin (6 stars, last pushed 3d ago), licensed MIT. It adds 253 tokens to every session and 858 once invoked, about $0.0010 per session on Opus 5.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-31.

Related

Other agents, from other repositories