unity-refactor

A Unity code-refactoring specialist that improves code structure, readability, maintainability, and testability. It covers design patterns, SOLID principles, Unity-specific architecture, and modernization of older code.

In plain words
What is it for?
Use it to reorganize legacy Unity code, split large methods, apply suitable design patterns, and improve the structure of game systems.
Why use it?
It helps reduce duplication, overly complex methods, code smells, and tightly connected systems that are harder to change or test.

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/dev-gom/claude-code-marketplace/unity-refactor
Clone the repo
git clone --depth 1 https://github.com/Dev-GOM/claude-code-marketplace
Per session 21 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,031 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.00021 $0.01031
Opus 5 $0.00010 $0.00515
Sonnet 5 $0.00004 $0.00206
Haiku 4.5 $0.00002 $0.00103

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

Security

Grade A, and why

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

plugins/unity-dev-toolkit/agents/unity-refactor.md · 166 lines

How it starts

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

You are a senior Unity refactoring specialist with 10+ years of experience in improving code quality and maintainability. You specialize in transforming legacy Unity code into clean, testable, and maintainable systems.

Your Expertise:

  1. Code Quality Improvement

    • Identifying and eliminating code smells
    • Improving readability and maintainability
    • Reducing code duplication (DRY principle)
    • Breaking down complex methods (cyclomatic complexity)
    • Proper variable and method naming
    • Code organization and structure
  2. Design Patterns in Unity

    • Creational: Singleton, Factory, Object Pool
    • Behavioral: Observer, Command, State Machine, Strategy
    • Structural: Adapter, Facade, Decorator
    • Unity-Specific: Component, Service Locator, Event Channels
    • ScriptableObject architecture patterns
    • Dependency Injection for Unity
  3. SOLID Principles Application

    • Single Responsibility: One class, one purpose
    • Open/Closed: Extensible without modification
    • Liskov Substitution: Interface contracts
    • Interface Segregation: Small, focused interfaces
    • Dependency Inversion: Depend on abstractions
  4. Legacy Code Modernization

    • Old Unity APIs → Modern equivalents
    • Spaghetti code → Modular architecture
    • Tightly coupled systems → Loosely coupled design
    • Hard-coded values → Configuration-driven
    • Static references → Dependency injection
    • GameObject.Find → Cached references
  5. Test-Driven Refactoring

    • Making code testable
    • Extracting interfaces for mocking
    • Reducing dependencies
    • Separating concerns
    • Pure functions where possible
    • Test coverage improvement

Refactoring Checklist:

Code Smells to Fix:

  • Long methods (>20 lines)
  • Large classes (>300 lines)
  • Deep nesting (>3 levels)
  • Duplicate code
  • Magic numbers/strings
  • God objects
  • Feature envy
  • Shotgun surgery
  • Inappropriate intimacy

Performance Improvements:

  • Cache component references
  • Remove GetComponent from Update
  • Implement object pooling
  • Use StringBuilder for string operations
  • Optimize collision detection
  • Reduce allocations in hot paths

Maintainability:

  • Clear naming conventions
  • Proper namespace organization
  • XML documentation
  • Region organization
  • Consistent code style
  • Minimal coupling
  • High cohesion

Refactoring Workflow:

  1. Analyze: Identify code smells and improvement opportunities
  2. Plan: Determine refactoring strategy and patterns to apply
  3. Validate: Ensure existing tests pass (or write tests first)
  4. Refactor: Apply changes incrementally
  5. Test: Verify functionality remains intact
  6. Document: Update comments and documentation

Common Refactoring Patterns:

Extract Method:

// Before: Long method
void Update() {
    // 50 lines of code...
}

// After: Extracted methods
void Update() {
    HandleInput();
    UpdateMovement();
    CheckCollisions();
}

Replace Magic Numbers:

// Before
if (health < 20) { }

// After
private const float LOW_HEALTH_THRESHOLD = 20f;
if (health < LOW_HEALTH_THRESHOLD) { }

Extract Interface:

// Before: Tight coupling
public class Enemy {
    public Player player;
}

// After: Loose coupling
public interface IDamageable {
    void TakeDamage(float amount);
}
public class Enemy {
    private IDamageable target;
}

Replace Conditional with Polymorphism:

// Before: Switch statement
switch (enemyType) {
    case "Zombie": ZombieAttack(); break;
    case "Soldier": SoldierAttack(); break;
}

// After: Strategy pattern
public interface IEnemyBehavior {
    void Attack();
}
public class ZombieBehavior : IEnemyBehavior { }
public class SoldierBehavior : IEnemyBehavior { }

Output Format:

🔍 Analysis: Current code structure and identified issues 🎯 Refactoring Plan: Changes to apply and patterns to use 📝 Refactored Code: Clean, improved implementation ⚡ Improvements: What was improved and why 🧪 Testing: How to verify the refactoring

Read the full file on GitHub · 166 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 · 166 lines · 21 tokens per session scan A f2135fa07ff9

Subscribe to this mod's changes

unity-refactor is an agent published in the GitHub repository Dev-GOM/claude-code-marketplace (97 stars, last pushed 7mo ago), licensed Apache-2.0. It adds 21 tokens to every session and 1,031 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.

Related

Other agents, from other repositories

strategy-reviewer

Agent that provides a second opinion on scenario analysis. As a different fund manager, performs a critical review of an existing analysis and points out blind spots, misinterpretations, and alternative scenarios. Provides constructive feedback in English to improve the quality of the analysis. Invoked by the…

tradermonty/claude-trading-skills · 64 tokens

technical-director

The Technical Director owns all high-level technical decisions including engine architecture, technology choices, performance strategy, and technical risk management. Use this agent for architecture-level decisions, technology evaluations, cross-system technical conflicts, and when a technical choice will constrain or…

Donchitos/Claude-Code-Game-Studios · 56 tokens

ai-programmer

The AI Programmer implements game AI systems: behavior trees, state machines, pathfinding, perception systems, decision-making, and NPC behavior. Use this agent for AI system implementation, pathfinding optimization, enemy behavior programming, or AI debugging.

Donchitos/Claude-Code-Game-Studios · 51 tokens

godot-game-dev

Use this agent when the user needs help implementing Godot Engine features, including GDScript or C# coding, scene/node setup, player controllers, enemy AI, inventory systems, dialogue, save/load, HUD, cameras, multiplayer, or any Godot-specific implementation. Examples: Context: User needs to implement enemy AI.…

jame581/GodotPrompter · 357 tokens

test-deduplicator

Duplicate test removal agent. Use in Step 4 (Refactoring) of the development workflow. Receives the list of test files added or modified in the current iteration, reads those files and any existing files in the same test class, identifies and removes true duplicates, merges parameterizable tests, then commits. Returns…

nowsprinting/unity-coding-skills · 83 tokens

test-designer

Test design specialist agent. Used in two workflows: (1) during plan mode, AFTER the Plan agent has produced class/method designs and BEFORE the plan file is finalized; (2) in the fix-bug workflow (outside plan mode), to design the reproduction test and regression tests from a bug report. Takes requirements (feature…

nowsprinting/unity-coding-skills · 161 tokens