# ReFactory: Project-Wide Code Refactorer

> Audit entire repositories for DRY violations, bloated logic, tight coupling, and O(N²) bottlenecks—then execute behavior-preserving, approval-gated refactorings with surgical diffs and zero wasted tokens.

ReFactory: Project-Wide Code Refactorer is a free AI agent skill on Agensi by yuvalB, in Code Quality & Review. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: Free
- Creator: [yuvalB](https://www.agensi.io/creators/yuvalb)
- Category: [Code Quality & Review](https://www.agensi.io/skills/code-quality-review)
- Version: 1.0
- Last updated: 2026-11-19
- Security: scan passed (2026-11-19); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/refactory-project-wide-code-refactorer
- Tags: code-review, testing, api, refactoring, technical-debt, typescript, python, code-refactoring

## About this skill

Asking an AI agent to "clean up my codebase" usually ends in one of two disasters: sweeping, unapproved rewrites that silently break edge cases, or bloated full-file reprints that burn through your token budget. **Project-Wide Code Refactorer** turns your coding agent into a disciplined Principal Refactoring Architect that audits multi-file repositories, delivers a prioritized blueprint first, and executes surgical, behavior-preserving refactorings only after you approve the plan.

### What it does
- **Four-dimension codebase audit:** Systematically detects `DRY Violations`, `High Complexity / Bloated Logic` (God functions, >3-level nesting), `Tight Coupling / SOLID` leaks, and `Algorithmic / Performance Bottlenecks` (such as $O(N^2)$ lookups).
- **Two-phase approval gate (Plan Before Mutate):** Outputs a deterministic, prioritized Refactoring Blueprint ranked by **Impact vs. Effort/Risk** (`P1`–`P3`) and pauses for your confirmation before editing multiple files in place.
- **Strict behavioral equivalence:** Preserves 100% of external behavior, public API signatures, error semantics, null/undefined handling, and async edge cases while mapping every cross-file call-site update.
- **Quality-first token efficiency:** Avoids reading unrelated files and emits minimal surgical Before/After hunks instead of full-file reprints—cutting token waste without ever dropping edge cases or verification steps.
- **Built-in regression verification:** Detects project test runners (`package.json`, `pyproject.toml`, `Cargo.toml`) and runs existing test suites before and after structural changes, concluding with a Regression Verification Checklist.
- **International, language-adaptive output:** Explains architectural trade-offs and reports in whatever language you write in (defaulting to English) while keeping code blocks, file paths, and symbols strictly in English.

### How it works
1. **Scope & Test Discovery:** Inspects project manifests, directory structure, entry points, and test runners. If a large monorepo scope is ambiguous, it asks which module to prioritize before scanning.
2. **Targeted Dependency Mapping:** Maps shared utilities, data flow, and high-complexity slices without reading unrelated files.
3. **Prioritized Refactoring Blueprint (Phase 1):** Delivers a structured audit using the included `references/refactoring-report-template.md`, ranking every finding (`REF-01`, `REF-02`, ...) by impact and risk, then waits at the Approval Gate.
4. **Incremental Execution & Surgical Diffs (Phase 2):** Applies approved changes in atomic steps with concrete Before/After hunks, complete cross-file call-site updates, and concise architectural rationales.
5. **Silent Verification & Test Run:** Validates behavioral equivalence, cross-file integrity, and zero premature abstractions via a pre-output rubric, then verifies against your test suite.

### Frameworks & tools
- **Compatible AI Agents & IDEs:** Claude Code, Cursor, Windsurf, Cline, Antigravity, GitHub Copilot Workspace, and any agent supporting `SKILL.md` / system prompt workflows.
- **Languages & Stacks:** Language-agnostic—works across TypeScript/JavaScript, Python, Rust, Go, Java, C/C++, and multi-module repositories.
- **Agent Tool Types:** File read/write tools for workspace scanning and surgical edits, plus optional shell/terminal execution for running project test suites.

### Why this beats prompting it yourself
A generic prompt like *"refactor this repo to be cleaner"* gives the model no guardrails against cosmetic churn, premature abstractions, broken cross-file imports, or uncontrolled multi-file rewrites. This skill embeds a complete architectural constitution (`SYSTEM_PROMPT.md`), an operational workflow (`SKILL.md`), a deterministic reporting template (`references/refactoring-report-template.md`), and a structured `blueprint.xml` specification—enforcing a plan-before-mutate workflow, measurable smell criteria, surgical diffs, and a five-point silent verification rubric on every run.

### Use cases
- Auditing legacy multi-file services before a major feature sprint or team handoff.
- Eliminating duplicated validation, auth, and data-fetching logic across API routes and controllers.
- Flattening deeply nested business logic (>3 levels) into readable, testable pure functions.
- Decoupling domain logic from database, UI, or transport layers without altering public contracts.
- Replacing hidden $O(N^2)$ loops and redundant allocations with linear-time data structures.

## Requires

Pure Markdown & XML skill—nothing to install. Works across any language or repository (JS/TS, Python, Rust, Go, etc.) inside agentic IDEs and CLI tools. Always presents an approval-gated blueprint before editing multiple files. Existing project test runner (e.g., Jest, Vitest, Pytest, Cargo test)……

## Known limitations

This is a pure prompt-and-template architectural skill with no bundled AST parser or compiler plugin, so cross-file call-site tracking and behavioral equivalence depend on your host model's reasoning quality and context window—very large monorepos should be scoped module-by-module to prevent context drift. Automated regression checks rely on the repository already having an executable test suite; on untested legacy code, the agent provides a manual verification checklist and recommended tests rather than programmatic proof of zero regressions. The skill is intentionally scoped to behavior-preserving refactoring and is not designed for greenfield feature development, changing business requirements, or purely cosmetic formatting passes.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the ReFactory: Project-Wide Code Refactorer skill from Agensi" and describe your task.
3. Your agent loads the skill from Agensi when it needs it. Nothing is downloaded.

## Frequently asked questions

### Does this require installing any CLI tools, dependencies, or MCP servers?

No. It is a pure Markdown and XML skill package with zero external dependencies. Drop it into your agent's skills directory or load the instructions into your IDE/CLI agent and start auditing repositories immediately.

### Which AI coding agents, programming languages, and spoken languages are supported?

It works in any agent or IDE that supports skills or custom system instructions—including Claude Code, Cursor, Windsurf, Cline, and Antigravity. It is programming-language agnostic (TypeScript/JavaScript, Python, Rust, Go, Java, C/C++, etc.) and responds in whatever spoken language you write in (defaulting to English) while keeping code, file paths, and symbols strictly in English.

### How is this different from just asking my AI agent to "refactor my codebase"?

Generic prompts often trigger unapproved multi-file rewrites, premature abstractions, or bloated full-file outputs that waste tokens and introduce silent regressions. This skill enforces a strict Two-Phase Approval Gate (Plan Before Mutate), audits across four concrete smell dimensions, outputs a deterministic Prioritized Smells Matrix, emits surgical Before/After diffs, and runs a five-point Silent Verification Rubric before every response.

### How does it avoid breaking production behavior during multi-file refactors?

Behavioral equivalence is a hard guardrail: the agent never changes public interfaces without mapping every internal consumer and flagging breaking changes, preserves exact null/error/async edge cases, executes approved edits in atomic steps, and runs your existing test suite before and after structural transformations whenever tests are present.

### What does "Quality-First Token Efficiency" mean in practice?

Task correctness always comes first—the agent will never skip edge cases, call-site updates, or verification steps to save tokens. Instead, it cuts waste by inspecting only relevant manifests and dependency slices, outputting minimal surgical Before/After hunks rather than reprinting untouched files, and keeping explanations crisp and filler-free.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
