Skip to content
Back to skills

Workflow Refactor

ASecurity

[Workflow] Use when restructuring, reorganizing, or cleaning up code without changing behavior.

  • 3 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 9, 2026
businessgoapisecurityperformance

Works with

  • api

Security analysis

A100/100

Scanned October 5, 2026

npx -y skills add duc01226/easy-claude --skill workflow-refactor --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Workflow Refactor?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Workflow Refactor
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/duc01226-workflow-refactor-easy-claude/badge)](https://www.skillsdirectory.com/skills/duc01226-workflow-refactor-easy-claude)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: workflow-refactor
version: 1.0.0
description: '[Workflow] Use when restructuring, reorganizing, or cleaning up code without changing behavior.'
disable-model-invocation: false
---

## Quick Summary

**Goal:** Restructure existing code without changing its observable behavior, proven by the same test scope green before and after the change plus a converged change review — cheap on a small local cleanup, thorough on a wide or risky restructure.

**Use this** to restructure, reorganize, rename, extract, simplify or pay down technical debt while behavior stays fixed. A change the user wants to behave differently is a feature (`workflow-feature`) or a bugfix (`workflow-bugfix`); a single trivial rename in one file fits a direct edit plus test and review.

**Key rules:**

- **MUST** triage size, kind and risk FIRST — the triage picks which recommended skills run and how deep.
- **MUST** prove behavior preservation: the affected test scope is green BEFORE any change (baseline gate) and green AFTER it (final gate); cover untested touched behavior with characterization tests first.
- **MUST** search 3+ local examples of the target pattern before planning and follow the project's architecture, code hierarchy and naming from `docs/project-config.json` → `workflowPatterns`.
- **NEVER** change an assertion or expected value to make a refactor pass — that is a behavior change and needs the user's approval.

## Size & Kind Triage (first action)

Classify the refactor before choosing steps and record the result in the workflow report:

- **Size** (guidance, not a law): **XS** 1–3 files / ≤100 changed lines · **S** ≤15 files · **M** ≤60 · **L** ≤300 · **XL** >300 (mechanical renames can reach thousands).
- **Kind** (all that apply): local cleanup · extract/move/rename · cross-module restructure · public contract/API surface · data/schema/persistence · security-sensitive · performance-driven · dead-code removal · test-only · tooling/config.
- **Risk:** irreversible, data, security, cross-module. Escalate depth on risk and ambiguity, not on file count alone.

| Triage result | Typical route through the recommended skills |
| --- | --- |
| XS/S, one module, no contract/data surface | investigate → baseline test → short plan → execute → review → test → close |
| M, or cross-module | keep one lean plan; add characterization tests where the baseline shows a coverage gap |
| L/XL, public contract/data/security, or ambiguous target structure | add `/plan --mode=validate`; execute in bounded batches per module with one report per batch, baseline and final test per batch plus a full-scope final run |

## Required Quality Gates

Non-negotiable — `/workflow-end` checks each against its evidence before the run closes:

1. **Baseline green** (`/test`, gate, before any change) — the test command, scope and pass summary for the code the refactor touches. A red baseline stops the refactor: report it, or route the failure to `workflow-bugfix`; never refactor on a red base.
2. **Touched behavior is guarded** — every behavior the refactor touches has a test that would fail if it changed; otherwise characterization tests are written first and proven green on the unrefactored code. For lifecycle/state logic, tests assert persisted transitions and invalid-transition rejection.
3. **Behavior preserved** (`/test`, gate, after the change and after review fixes) — the baseline scope plus any characterization tests run green in THIS run; test code changed only mechanically (imports, renamed symbols, moved paths).
4. **Review converged** (`/workflow-review-changes`, gate, INLINE in the main session) — validated blocking findings fixed and the fixed state re-reviewed.
5. **Run closed** — `/workflow-end` (top-level only).

Specs normally do not change in a refactor; the spec steps below run only when canonical specs or TCs point at code or tests the refactor moved, or a preserved invariant lacks a TC. Any observable behavior, public contract or docs/spec boundary change means the work is no longer a pure refactor — stop and confirm with the user, then run the spec/test/docs sync that change requires.

## Gates and Optional Steps

**Step contract:** `/start-workflow` owns how gate, core and optional steps run; this table summarizes this workflow's `intent`, `outcomeGates` and step roles from `.claude/workflows.json`, in its recommended default order.

| Step | Role | Runs when / earns its cost | Proves |
| --- | --- | --- | --- |
| `/investigate` | core | always in practice — scope, callers, 3+ local pattern examples | scope and target pattern |
| `/test` | gate | always — BEFORE any change, on the affected scope | baseline green |
| `/plan` | core | always in practice; XS/S keeps it to files, steps, rollback | refactor plan |
| `/plan --mode=validate` | optional | size L+, or an ambiguous target structure or scope | plan confirmed |
| `/integration-test` | optional | touched behavior has no test that would fail if it changed | characterization tests |
| `/plan --mode=execute` | core | always in practice — small verifiable increments | the change |
| `/spec [mode=tests]` | optional | TCs reference moved code/tests, or an invariant lacks a TC | TCs match |
| `/pbi --mode=review --type=spec-tests` | optional | TC content changed beyond evidence paths | TC quality |
| `/spec [mode=sync]` | optional | specs/TCs reference moved or renamed code/test paths | specs match |
| `/workflow-review-changes --tests=defer` | gate | always — INLINE in the main session | review converged |
| `/integration-test --mode=verify` | optional | integration tests written or changed in this run — after the review | integration tests green |
| `/test` | gate | always — after the change and review fixes, baseline scope; when `/integration-test --mode=verify` ran, pass `--proven=<its report path>` so only tiers it did not cover run | behavior preserved |
| `/workflow-end` | gate | always | run closed |
| `/watzup` | core | wrap-up summary | handoff |

Outcome gates: tests pass · review converged · run closed.

A recommended step the triage shows would do no real work is not run; record it through the Step Execution Protocol with its evidence.

**Ad hoc skills (not registry steps):** `/investigate` again before removing "unused" code — grep evidence, confidence ≥80%, cross-module/service check · `/performance-review` for a performance-driven refactor (below) · `/code-simplifier` for a clean-up pass, only before the review and final test so they cover its result.

> **[PERFORMANCE-SDD ROUTE]** A performance-driven refactor (query optimization, caching, fewer allocations, throughput) runs `/performance-review` for benchmark evidence — SLA, baseline, measurement command — while preserving observable behavior and functional no-regression checks. A pure behavior-preserving optimization adds no new TCs when the invariant-preservation evidence and the final `/test` gate cover it; a changed SLA, performance constraint, state timing boundary, public contract or docs/spec boundary still requires spec, test and docs sync.

## Orchestration Freedom

You choose inline vs sub-agent, parallel waves vs sequential, batching and order — optimize wall-clock and token cost at equal quality. Fixed constraints (data dependencies):

- The baseline and any characterization tests run green on the unrefactored code before `/plan --mode=execute` changes it.
- A change exists before it is reviewed or tested; a spec sync runs before the review that checks it; the review is static (`--tests=defer`) and the verify runs after it; a fix made by the verify step re-runs `/workflow-review-changes --tests=defer` (`SYNC:verify-last-order`); `/workflow-end` runs last.
- `/workflow-review-changes` runs INLINE in the main session — never as a sub-agent — and owns the test-quality review and the docs/domain-entity reference refresh; do not repeat them here.
- Gates awaiting user approval (plan validation, a behavior-change decision) are never parallelized.

Recommended: XS/S work inline without sub-agents; L/XL mechanical changes applied per module batch with a bounded report each, then one full-scope final test.

## Memory, Reporting and Fix Path

- **Tasks:** one task per selected step or batch so nothing is lost after compaction; child skills expand their phases under the parent row.
- **Report first:** create `tmp/reports/workflow-refactor-{YYMMDD}-{HHmm}-{slug}.md` before the first finding; append triage, baseline evidence, pattern examples, batch results and deviations per step; re-read it and `TaskList` after compaction. Sub-agent briefs make report-writing their first deliverable.
- **Fix path:** validate a finding (evidence-backed, reproducible) before fixing it; fix at the owning layer; re-run the reviewer or test that raised it, plus a holistic pass when fixes were non-trivial. A failing test after the change means the refactor changed behavior until proven otherwise — adjudicate it before editing either side.
- **Loop bounds:** round 1 exits on zero open validated findings (Round-1 LOW closure); from round 2 only CRITICAL/HIGH/MEDIUM block and LOW-only findings are deferred; cap 3 review rounds; failing tests are uncapped; no progress → escalate via `AskUserQuestion`.

## Activation

Activate the `workflow-refactor` workflow: run `/start-workflow workflow-refactor` with the user's prompt as context. Apply the shared SDD Artifact Contract from `shared/sdd-artifact-contract.md` in the active skills root; project conventions come from `docs/project-config.json` and the docs index.

Recommended default order (roles in the table above):

**IMPORTANT MANDATORY Steps:** /investigate -> /test -> /plan -> /plan --mode=validate -> /integration-test -> /plan --mode=execute -> /spec [mode=tests] -> /pbi --mode=review --type=spec-tests -> /spec [mode=sync] -> /workflow-review-changes --tests=defer -> /integration-test --mode=verify -> /test -> /workflow-end -> /watzup

<!-- PROTOCOL-GUIDES:START -->

> **Protocol guides** — A hook delivers each protocol's full text when this skill loads. If a protocol's text is not in your context, read its file below before you act on it.

- `incremental-persistence` — Persist results per file or section while the work proceeds; a sub-agent or heavy step processes more than three files → .claude/skills/shared/protocols/incremental-persistence.md
- `session-goal-ledger` — Keep the original goal and every user prompt of the session; running a long or multi-prompt session → .claude/skills/shared/protocols/session-goal-ledger.md
- `subagent-return-contract` — Sub-agents return a structured envelope and a report path, never an inline report; spawning a sub-agent → .claude/skills/shared/protocols/subagent-return-contract.md
- `verify-last-order` — Build all phases and write tests, review statically, then verify once with a mutation check; planning or running any code-changing task → .claude/skills/shared/protocols/verify-last-order.md
- `workflow-registry-binding` — Read the workflow registry entry and the workflow skill together, since they must agree; executing or editing a workflow → .claude/skills/shared/protocols/workflow-registry-binding.md

<!-- PROTOCOL-GUIDES:END -->


<!-- SYNC:session-goal-ledger:reminder -->

- **MANDATORY** Session goal ledger per the `Task Planning Rules`: pin `Original goal:`, keep `User prompts this session: P1…Pn`, and map the result to every prompt before claiming done; full text: `.claude/skills/shared/protocols/session-goal-ledger.md`.

<!-- /SYNC:session-goal-ledger:reminder -->

## Closing Reminders

**IMPORTANT MUST ATTENTION Goal:** restructure existing code without changing its observable behavior, proven by the same test scope green before and after plus a converged change review.

- **MUST ATTENTION** triage size, kind and risk FIRST; run only the recommended skills the triage shows do real work, and log every deviation with evidence.
- **MUST ATTENTION** baseline `/test` (gate) green BEFORE any change; characterization tests first for any touched behavior no test guards; the final `/test` (gate) green on the same scope AFTER the change.
- **MUST ATTENTION** search 3+ local examples and follow the project's `workflowPatterns`; removing "unused" code needs `/investigate` evidence.
- **NEVER** edit an assertion or expected value to make the refactor pass; a behavior change needs the user's approval and the spec/test/docs sync it implies. `/workflow-review-changes` runs INLINE in the main session; close with `/workflow-end`.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.