# Orchestrated Refactor (orch-refine-code)

> Orchestrates a behavior-preserving refactor: confirm tests are green, restructure in small steps, keep tests green, review, and commit behind gates.

- Category: [Refactoring](https://www.myskills.tools/en/categories/refactoring/)
- Source: Community · Affaan Mustafa
- Repository: https://github.com/affaan-m/ECC/tree/main/skills/orch-refine-code (commit db7f2a6)
- SKILL.md: https://github.com/affaan-m/ECC/blob/main/skills/orch-refine-code/SKILL.md
- Install command: `npx skills add affaan-m/ECC --skill orch-refine-code`
- License: MIT
- Compatible with: Claude Code, Codex, Cursor, Copilot, OpenCode
- Permissions: read-repo ✓, write-files ✓, shell ✓, network ✗
- Status: Scan passed
- A rule scan cannot catch every risk. Read this skill's SKILL.md and check its permissions before installing.
- ⚠ Creates a git commit after Gate 2 confirmation, and cleanup sweeps may delete dead code.

## Core rule

The diff must be behavior-neutral; if behavior is meant to change at all, this is the wrong skill.

## Execution Phases

1. **Confirm tests are green** — Before touching code, confirm the relevant tests exist and pass; add characterization tests first if coverage is thin.
2. **Plan the restructure** — Plan the restructure with the orch-pipeline engine and stop at Gate 1 for approval.
3. **Restructure in small steps** — Move in small steps, re-running tests after each; delegate dead-code and duplication sweeps to the refactor-cleaner agent (knip, depcheck, ts-prune).
4. **Review** — Run a code review on the behavior-neutral diff.
5. **Gated commit** — Stop at Gate 2 for confirmation, then commit with a refactor: prefix.

## Permissions (summarised from SKILL.md)

| Capability | Needed | Details |
|---|---|---|
| File writes | Required | Restructures code across multiple files and adds characterization tests when needed. |
| Command execution | Required | Runs the test suite, tools such as knip, depcheck and ts-prune, and git commit. |
| Network outbound | Not required | The skill does not call for network access. |

## SKILL.md frontmatter (YAML)

```yaml
---
name: orch-refine-code
description: Orchestrate a behavior-preserving refactor — confirm tests are green, restructure without changing behavior, keep tests green, review, and gated commit. Use when the structure should improve but behavior must not change.
metadata:
  origin: ECC
---
```

Home: https://www.myskills.tools/en/ · URL: https://www.myskills.tools/en/skills/orch-refine-code/
