# safe-refactor

Restructures code without changing its behavior, checking that it still works before and after each structural edit.

Skill by Julius Brussee. Category: Code quality.

## Install

Project (for this project only):

```sh
npx skills add juliusbrussee/caveman --skill safe-refactor
```

Works with: Claude Code, Codex CLI, Cursor, Antigravity, Copilot CLI, opencode.

Global (for every project on this machine):

```sh
npx skills add juliusbrussee/caveman --skill safe-refactor -g
```

Works with: Claude Code, Codex CLI, Cursor, Antigravity, Copilot CLI, opencode.

## Tags

- Runs on your computer: It runs as a program on your machine, with your access.

## Security audits

- Gen Agent Trust Hub: Pass
- Socket: Pass
- Snyk: Pass

Installs: 104918. Installs counted by skills.sh. [Open on skills.sh](https://www.skills.sh/juliusbrussee/caveman/safe-refactor)

## Source

[Open the source](https://github.com/juliusbrussee/caveman/tree/HEAD/skills/safe-refactor). Checked 2026-10-24. This summary may contain AI-generated text, so it can be wrong. Check the source before you rely on it.

## SKILL.md

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

# Safe refactor

Define behavior-preservation boundary and establish verification before structural edits.

- Keep feature changes outside refactor.
- Move one ownership boundary at a time.
- Preserve public interfaces, failure behavior, ordering, and compatibility unless explicitly scoped.
- Keep intermediate states buildable and testable.
- Avoid dependency or configuration growth without correctness need.

Run same proof after change. Stop when behavior matches and requested structure is achieved.
````

- Previous: [caveman-learn](https://syn4pse.dev/terminal/caveman-learn.md)
- Next: [caveman-optimize](https://syn4pse.dev/terminal/caveman-optimize.md)
- [Terminal](https://syn4pse.dev/terminal.md)
- [Suggest a change](mailto:terminal@syn4pse.dev?subject=Terminal%20suggestion)
