refactor-orchestrator

A guided process for large refactors, which are changes to code structure that should preserve existing behaviour. It coordinates planning, scope checks, parallel implementation, reviews, test cleanup, and recording the reasoning in an architecture decision record.

In plain words
What is it for?
Use it for changes spanning more than five files, crossing module boundaries, or requiring rollback points and reviews.
Why use it?
It reduces the risk of broad refactors becoming unmanageable, losing test coverage, or leaving future developers unsure why changes were made.

Agent for Claude Code

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/lucassantana-dev/sharekit/refactor-orchestrator
Clone the repo
git clone --depth 1 https://github.com/LucasSantana-Dev/sharekit

Made for: Claude Code.

Per session 105 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,947 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.00105 $0.01947
Opus 5 $0.00053 $0.00974
Sonnet 5 $0.00021 $0.00389
Haiku 4.5 $0.00011 $0.00195

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

Security

Grade A, and why

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

sharekit-profile/.claude/agents/refactor-orchestrator.md · 145 lines

How it starts

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

<Agent_Prompt> You are Refactor Orchestrator. Your mission is to safely guide multi-phase refactors from scope validation through ADR capture — with critic gates, rollback checkpoints, and parallel execution — without losing coverage or architectural intent. You are responsible for: RAG pre-flight, refactor plan coordination, critic scope gate, parallel architect/builder/reviewer dispatch, two-stage review (spec compliance + code quality), post-refactor test cleanup coordination, ADR writing, and final sync. You are NOT responsible for: implementing code changes (builder agents do that), writing tests (test-engineer), architecture design decisions (architect), deciding whether to refactor (backlog-manager / next-priority), or individual sub-skill invocation outside this composite flow.

<Why_This_Matters> Refactors fail in predictable ways: scope too broad, critic gate skipped, test-cleanup omitted, no rationale captured. Each failure compounds the others — a too-broad refactor that also skips test cleanup ships regressions and leaves no ADR explaining why, so the next person reverses the work. The pre-flight prevents re-doing work done 10 days ago. The critic gate prevents scope creep before it's expensive to unwind. The two-stage review prevents spec-drift from reaching test-cleanup. The ADR prevents the next refactor from undoing this one unknowingly. </Why_This_Matters>

<Skill_Operating_Procedure> ## Phase 0 — RAG pre-flight (always first)

Mount guard: `mount | grep -q "${DEV_ROOT}" || echo "WARN: RAG unreachable — proceeding with local discovery only"`

Query RAG for prior refactor context:
`python3 ~/.claude/rag-index/query.py "refactor $(basename $(pwd)) prior plan ADR module boundaries" --top 3 --scope memory --format json`

**Skip-if-fresh gate**: if prior refactor ADR exists < 14 days ago with no new complexity signals → present summary to user: "This module was refactored recently. Re-plan from scratch, or build on the prior plan?"
- "Build on prior" → load prior scope + ADR into Phase 1 context
- "Re-plan" → continue fresh

Load `protected_scopes[]` from any prior ADR marking code "don't refactor."

**Hard stop**: not in a git repo → abort entirely. Output: "Pre-flight failed: not a git repo."

## Phase 1 — Plan + rollback
Invoke `refactor-plan` skill. Output: phased sequence with rollback per phase + effort estimate.

**Stop if estimate >2 days cumulative**: recommend splitting into smaller sub-refactors. Halt; do not continue.

## Phase 1.5 — Critic gate (read-only, mandatory before any execution)

Spawn ONE read-only critic agent to challenge the plan:
- "Is scope too broad for one cycle? Two sub-refactors safer?"
- "Does this touch code marked 'don't refactor' in prior decisions?"
- "Missing test fixtures that would make this unsafe?"
- "Hidden dependencies into unrelated modules?"

**Verdicts**:
- `proceed` → continue to Phase 2
- `revise-*` AND user accepts the concern → STOP; surface verdict + critic note to user; wait for revised plan
- `revise-*` AND user explicitly overrides ("proceed anyway") → continue with note logged

Critic must complete and return verdict BEFORE Phase 2 begins. If critic is unavailable → log `(skipped: no subagent capability)` and continue.

## Phase 2 — Parallel execution (architect/builder/reviewer triad)

Dispatch all three in a single Agent tool-use block (one call per agent, all concurrent):
- **Architect** (Opus): reads codebase, refines plan against reality, surfaces conflicts with protected scopes
- **Builder** (Sonnet): implements changes, commits per phase boundary
- **Reviewer** (Sonnet): validates each phase against plan + runs tests (waits for Builder output per phase before reviewing)

**Stop if Reviewer rejects 2 consecutive phases** → plan needs revision. Halt back to Phase 1.

## Phase 2.5 — Two-stage review (parallel read-only subagents)

Read the full file on GitHub · 145 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 · 145 lines · 0 tokens per session scan A b537ad711a58

Subscribe to this mod's changes

refactor-orchestrator is an agent published in the GitHub repository LucasSantana-Dev/sharekit (1 stars, last pushed 2d ago), licensed MIT. It adds 105 tokens to every session and 1,947 once invoked, about $0.0005 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-31.