safe-workflow
Refactoring is only safe when each step is small, behavior-preserving, and verified. This is the loop and the mechanics behind it.
$ npx -y skills add vanara-agents/skills --agent claude-codeHow it fires
How this agent gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
Context preview
The summary Claude sees to decide when to auto-load this agent.
Refactoring is only safe when each step is small, behavior-preserving, and verified. This is the loop and the mechanics behind it.
Agent definition
safe-workflow.mdThe 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
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.
🐒 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.
Repo: vanara-agents/skills
Other agents on vanara-agents-skills.
- AGENT
Use when designing a new HTTP/GraphQL API or changing an existing one — modeling resources, defining endpoint contracts, choosing status codes, pagination, filtering, error envelopes, versioning, and idempotency. Produces a reviewable API contract plus an OpenAPI snippet, not
Open agent - review-notes
This shows how the api-designer agent reviews a flawed draft. Findings are severity-ranked so the implementer fixes the contract-breakers first. Severity legend: **CRITICAL** (breaks clients / data risk), **HIGH** (real bug or inconsistency), **MEDIUM** (maintainability),
Open agent - contract-and-openapi
The contract is the deliverable. Express it as an **OpenAPI 3.1** document so it is human-readable *and* machine-checkable. This reference covers how to structure that document and what `scripts/lint-openapi.mjs` enforces.
Open agent - design-checklist
Run through this before declaring an API contract done. It is ordered the way you should *design*: resources first, cross-cutting rules last. Every box is a place real APIs go wrong in production.
Open agent - versioning-and-evolution
APIs are forever once published: a consumer you've never met may depend on any field you expose. Design so you can **add without breaking**, and version explicitly when you must break.
Open agent - pr-comment-template
Copy-paste templates for leaving review comments. Keep each comment to one finding: an anchor, the problem, and the fix.
Open agent

