Skip to content
Back to skills

Coding

ASecurity

Use to change the structure of existing code that has no reliable safety net, in small reversible steps (strangler, branch by abstraction, parallel run). Use refactor.skill instead when a green test suite already covers the code.

  • 24 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added November 22, 2026
ai-agentsgotestingrefactoringsecurity

Security analysis

A100/100

Pro scans all 21 files and shows the line behind each finding

Scanned November 22, 2026

npx -y skills add andreibesleaga/GABBE --skill coding --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Coding?

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

Security grade badge for Coding
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/andreibesleaga-coding-3bfa6b1b/badge)](https://www.skillsdirectory.com/skills/andreibesleaga-coding-3bfa6b1b)

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: safe-refactoring
description: Use to change the structure of existing code that has no reliable safety net, in small reversible steps (strangler, branch by abstraction, parallel run). Use refactor.skill instead when a green test suite already covers the code.
triggers: [safe refactoring, refactor legacy, strangler fig, branch by abstraction, parallel run, improve in small steps, refactor without tests, reversible step]
tags: [coding, refactoring, brownfield]
core: true
context_cost: medium
---
# Safe Refactoring Skill

## Goal
Improve structure without changing behaviour when the code was not written for testing. This is stage B3 of `guides/processes/brownfield-lifecycle.md`. It adds the net first (`characterization-tests.skill`), then applies the mechanics of `refactor.skill` one reversible step at a time.

## Steps
1. **Check entry.** The human approved the plan (`ASSESSMENT.md`, proposal section). Characterisation tests exist for the target (`project/CHARACTERIZATION.md`) and are green. If not, stop and run `characterization-tests.skill`.
2. **Write the step list.** In `project/TASKS.md` write each step as one reversible change with its own check: "T-nnn: <what>, check: <command>, undo: <how>". A step that cannot be undone alone is split.
3. **Pick the technique per step.**
   - Replace a module over time (strangler): put a facade in front of the old code, route one case to the new code, keep the rest on the old.
   - Replace an implementation used by many callers (branch by abstraction): add an interface, make callers use it, add the new implementation behind it, switch with a flag or one line, remove the old one last.
   - Check the new against the old (parallel run): run both, compare results, log differences, return the old result until differences are zero for a period the human agreed.
   - Local cleanup (extract, rename, early return): apply `refactor.skill`.
4. **Do one step.** Make the change. Run the step's check and the full test suite. Green: record it (step 6). Red: undo the step, do not patch the tests, find the cause.
5. **Keep behaviour identical.** After a step the characterisation tests pass unchanged. If one must change, stop; that is a behaviour change (see Constraints).
6. **Record each step.** One line in `project/TASKS.md` (`DONE`, check output summary) and, when the project uses small commits, a note for the human with the proposed commit message. Do not commit.
7. **Check boundaries.** After structural steps run `agentic-linter.skill` and the complexity tool; no new cycles, complexity not above 10 in touched code.
8. **Remove the old path last.** Delete old code only when the new path has served for the agreed period, its tests pass, and the human said yes to the deletion.
9. **Finish.** Run the full suite and compare to the baseline in `project/CHARACTERIZATION.md`: pass count not lower, coverage not lower. Report the steps done and the steps left.

## Constraints
- One reversible step at a time; never a step that mixes refactoring with a feature or a dependency upgrade.
- No big-bang rewrite. A rewrite of a whole system needs an ADR and the human's approval at S02.
- Moving code must keep its security context: authorisation checks, input validation, audit logging and error contracts stay with the logic that they protect. List them before the move and confirm after.
- Do not edit tests to make a step pass.

## Output Format
Steps done in `project/TASKS.md`, tests green, a short report: "<n> steps done, <m> left, suite <pass count> passing (baseline <pass count>), coverage <x>% (baseline <y>%)".

## Limits and safety
- Data migrations and schema changes are not refactoring steps here; they go through `db-migration.skill` and need the human's yes (data loss risk).
- A step that touches a production switch (a route, a flag in production) is deployed only through the S10 gate: the human says "deploy now" in that request.
- When the old code looks like it has undocumented checks (a strange condition, a magic number), keep it and ask the human; do not "tidy" it.

Files in this skill

  • agent-trajectory-eval.skill.md4.6 KB
  • artisan-commands.skill.md2.3 KB
  • assurance-ladder.skill.md5 KB
  • browser-tdd.skill.md5.4 KB
  • chaos-fault-injection.skill.md7 KB
  • characterization-tests.skill.md4.3 KB
  • ci-autofix.skill.md2.8 KB
  • clean-coder.skill.md2.8 KB
  • code-review.skill.md4.2 KB
  • debug.skill.md4.6 KB
  • design-by-contract.skill.md3.5 KB
  • documentation.skill.md5.2 KB
  • eval-driven-development.skill.md5.5 KB
  • evals/code-review.eval.yaml1 KB
  • excalidraw.skill.md3.7 KB
  • file-processing.skill.md2.5 KB
  • formal-spec-lightweight.skill.md3.9 KB
  • fuzz-differential-testing.skill.md3.9 KB
  • git-workflow.skill.md5.4 KB
  • incremental-feature.skill.md3.6 KB

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.

View all in ai-agents →

Comments

Loading comments…

Newsletter

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