Skip to content
Development
Agent

safe-workflow

Refactoring is only safe when each step is small, behavior-preserving, and verified. This is the loop and the mechanics behind it.

From plugin
skills
954 skills54 agents

Claude Code

$ npx -y skills add vanara-agents/skills --agent claude-code

Agent definition

safe-workflow.md

The Safe Refactoring Workflow

Refactoring is only safe when each step is small, behavior-preserving, and verified. This is the loop and the mechanics behind it.

The core loop

confirm tests GREEN
  └─ pick ONE smell
       └─ apply ONE small transformation
            └─ run tests
                 ├─ GREEN → keep, optionally commit, loop
                 └─ RED   → revert last step, take a smaller step (or add a test)

The loop is non-negotiable. The two questions that gate every step:

1. **Were the tests green before I started?** If not, you are not refactoring — you are debugging. Get to green first. 2. **Are the tests still green after this step?** If not, you changed behavior. Revert.

Characterization tests (when coverage is missing)

If the code you must refactor has no tests, write tests that **describe what it does now**, not what it should do:

1. Call the code with representative inputs. 2. Observe the actual output (run it). 3. Assert that exact output — even if it looks wrong. The goal is to detect *change*, not to judge correctness. 4. Now refactor under that net. If a characterization test goes red, your refactor altered behavior.

Fixing genuinely-wrong behavior is a *separate* task done *after* the refactor, with its own test.

Transformation mechanics

Each refactoring has a known recipe. A few of the most common:

Extract Function

1. Copy the fragment into a new function with an intention-revealing name. 2. Pass in the variables it reads as parameters; return the values it writes. 3. Replace the original fragment with a call. 4. Run tests.

Rename

1. Use editor/tooling rename so every reference updates atomically. 2. Run tests. (With good tooling this is among the safest moves.)

Replace Nested Conditional with Guard Clauses

1. Identify the error/edge conditions. 2. Turn each into an early `return`/`throw` at the top. 3. De-indent the remaining happy path. 4. Run tests.

Introduce Parameter Object

1. Create a type/struct grouping the parameters that travel together. 2. Add it as a new parameter; populate from the old ones at the call site. 3. Move logic to read from the object; remove the old parameters. 4. Run tests after each sub-step.

Commit discipline

  • One behavior-preserving step per commit where practical. Message: `refactor: extract normalizeName`.
  • Never bundle a refactor commit with a feature or fix commit. A reviewer (or `git bisect`) must be

able to trust that a `refactor:` commit changed no behavior.

  • Keep steps revertible: each commit should leave the suite green.

Stop conditions

Stop refactoring when any of these is true:

  • The targeted smell is gone and the code reads clearly.
  • You can no longer make a change you're confident preserves behavior.
  • You've drifted out of the requested scope.
  • A behavior change is actually required — switch tasks and say so.
Read more
@vanara-agents
Ships withskills

🐒 Free agents, skills & packs for Claude Code One subscription. An army of Claude Code agents. 30 production-grade agents, skills, and packs for Claude Code — free, Apache-2.0, install with one command.

917 skills54 agents
Get the whole plugin

Stars on GitHub

Momentum

stars in total
9
Star history of vanara-agents/skills on GitHub, a chart by star-history.com

Other agents on skills.

AGENT

AGENT

Agent

Use when designing a new HTTP/GraphQL API or changing an existing one — modeling resources, defining endpoint contracts, choosing…

review-notes

review-notes

Agent

This shows how the api-designer agent reviews a flawed draft. Findings are severity-ranked so the implementer fixes the…

contract-and-openapi

contract-and-openapi

Agent

The contract is the deliverable. Express it as an **OpenAPI 3.1** document so it is human-readable *and* machine-checkable. This…

design-checklist

design-checklist

Agent

Run through this before declaring an API contract done. It is ordered the way you should *design*: resources first, cross-cutting…

pr-comment-template

pr-comment-template

Agent

Copy-paste templates for leaving review comments. Keep each comment to one finding: an anchor, the problem, and the fix.

More agents from other plugins.

a11y-architect
Auto-invoked

a11y-architect

Agent

Accessibility Architect specializing in WCAG 2.2 compliance for Web and Native platforms. Use PROACTIVELY when designing UI…

ecc2w293k
@affaan-m@affaan-mInstall Agent
analyze-pass-impact

analyze-pass-impact

Agent

Analyzes how a specific topic affects a group of compiler passes. Used by the /plan-update skill to parallelize research across…

react5d252k
@facebook@facebookInstall Agent
orchestrator

orchestrator

Agent

- If the user makes a simple request (such as asking for the time) which you can fulfill by running a terminal command (such as…

codex5d135k
@openai@openaiInstall Agent
cavecrew-builder

cavecrew-builder

Agent

Surgical 1-2 file edit. Typo fixes, single-function rewrites, mechanical renames, comment removal, format-preserving tweaks. Hard…

caveman6d119k
@juliusbrussee@juliusbrusseeInstall Agent

Questions about safe-workflow.

Which coding agents can use safe-workflow?
safe-workflow installs in Claude Code and Cursor: each loads subagents from .claude/agents, so copy the file there. Flowy's auto-invocation runs in Claude Code only.