# Safe Refactor (safe-refactor)

> Restructures code while preserving behavior, bracketing structural edits with the same verification before and after.

- Category: [Refactoring](https://www.myskills.tools/en/categories/refactoring/)
- Source: Community · Julius Brussee
- Repository: https://github.com/JuliusBrussee/caveman/tree/main/skills/safe-refactor (commit 82864c8)
- SKILL.md: https://github.com/JuliusBrussee/caveman/blob/main/skills/safe-refactor/SKILL.md
- Install command: `npx skills add JuliusBrussee/caveman --skill safe-refactor`
- License: Apache-2.0
- Compatible with: Claude Code, Codex, Gemini CLI
- Permissions: read-repo ✓, write-files ✓, shell ✓, network ✗
- Status: Scan passed
- A rule scan cannot catch every risk. Read this skill's SKILL.md and check its permissions before installing.

## Core rule

Define the behavior-preservation boundary and establish verification before any structural edit.

## Execution Phases

1. **Set boundary and proof** — Define which behavior must be preserved and establish verification before editing; keep feature changes out of the refactor.
2. **Move one boundary at a time** — Move one ownership boundary at a time, keeping every intermediate state buildable and testable.
3. **Preserve interfaces** — Keep public interfaces, failure behavior, ordering and compatibility unless scoped, and avoid dependency or config growth without a correctness need.
4. **Re-run the same proof** — Run the same proof after the change and stop when behavior matches and the requested structure is reached.

## Permissions (summarised from SKILL.md)

| Capability | Needed | Details |
|---|---|---|
| File writes | Required | Edits code structure within the refactor scope. |
| Command execution | Limited | Runs the build and test commands used as proof that behavior is unchanged. |
| Network outbound | Not required | The skill does not call for network access. |

## SKILL.md frontmatter (YAML)

```yaml
---
name: safe-refactor
description: Restructure code while preserving behavior. Use for extraction, consolidation, ownership moves, or cleanup where verification must bracket structural edits.
---
```

Home: https://www.myskills.tools/en/ · URL: https://www.myskills.tools/en/skills/safe-refactor/
