AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified MIT Self-run

Refactor Loop

skill-ao92265-claude-code-playbook-refactor-loop · by ao92265

Characterization-test-first refactor loop. Generates Playwright/Vitest baseline tests capturing current behavior, commits them, then iterates refactor until tests stay green. Distinct from tdd-fix (bug-fix-first) — this is refactor-first. Triggers "/refactor-loop", "characterization tests", "safe refactor", "refactor with tests first".

— No reviews yet
0 installs
38 views
0.0% view→install

Install

$ agentstack add skill-ao92265-claude-code-playbook-refactor-loop

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • ✓ Prompt-injection patterns
  • ✓ Secret / credential exfiltration
  • ✓ Dangerous shell & filesystem operations
  • ✓ Untrusted network calls
  • ✓ Known-malicious package signatures

What it can access

  • ✓ Network access No
  • ✓ Filesystem access No
  • ✓ Shell / process execution No
  • ✓ Environment & secrets No
  • ✓ Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-ao92265-claude-code-playbook-refactor-loop)

Reliability & compatibility

✓ Security review passed
0 installs to date
— no reviews yet
● 3mo ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.

How agent discovery & health will work →
Are you the author of Refactor Loop? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

Refactor Loop — Test-Driven Safe Refactor

For refactors (no behavior change). Generates a behavioral safety net BEFORE touching code, then iterates the refactor until the net still holds.

When to invoke

  • Renaming/restructuring without semantic change
  • Splitting a god component, extracting hook/util, deduping logic
  • Migrating styles/theme without altering rendered output
  • Library/version upgrade in a contained module

When NOT to invoke

  • Bug fix → use tdd-fix
  • Feature add → use dev-story or normal flow
  • Mechanical rename across files where existing tests already cover it

Workflow

Step 1 — Identify target + capture surface

Ask user (if not stated) for:

  • Target file/dir
  • Public surface to preserve: rendered output, network calls, exposed API, side effects

Step 2 — Write characterization tests

Generate tests that PIN current behavior:

  • React component: Playwright snapshot of rendered DOM in 2–3 prop states + assertion on emitted network calls
  • Pure function: Vitest cases for every observed input → output pair from existing usage (grep callers)
  • Service/class: Spec covering each public method's happy path + error paths

Tests MUST run green against unchanged code. If they fail on unchanged code → tests are wrong, fix them before continuing.

Step 3 — Baseline commit

git checkout -b test/-baseline
git add 
git commit -m "test(baseline): characterization tests for  before refactor"

Step 4 — Iterate refactor

Loop, max 20 iterations:

  1. Make one small refactor increment
  2. Run full suite: tsc -b && npm test && npm run lint
  3. Green → commit refactor: and continue
  4. Red → diagnose ROOT CAUSE (not symptom):
  • Was behavior actually changed? → revert + rethink
  • Was baseline test brittle (timing, ordering)? → harden test in separate commit, then continue
  1. Cap at 20 iterations. If goal not reached, surface to user with diff summary.

Step 5 — Final diff report

Refactor: 
Baseline tests: 
Iterations: /20
Net diff: , +/-
Behavior delta: NONE (all baseline tests passing)

Hard Rules

  • NEVER skip the baseline test step. "I'll just be careful" is how regressions ship.
  • Baseline tests committed in their OWN branch/commit before any refactor commit. Reviewable separately.
  • Root-cause failures, never symptom-patch tests to make them pass.
  • tsc -b (NOT --noEmit) — CI parity.
  • If iteration cap hit: surface partial progress, do not silently push half-finished work.

Subagent routing

  • executor (sonnet) — write tests + refactor increments
  • verifier (sonnet) — run suites + parse failures
  • Escalate to opus only after 2 sonnet root-cause attempts on same failure.

Triggers

/refactor-loop, "characterization tests", "safe refactor", "refactor with tests first", "lock in behavior before refactor"

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.