---
description: Refactor a module toward a target pattern without changing behavior.
argument-hint: <module-path> <target-pattern>
---

# /refactor-module

## Purpose

Improve internal structure of a module while preserving its public contract and behavior.

## Required context

- `CLAUDE.md`, `knowledge/patterns/`, the module's tests

## Inputs

- `$1` — module path, `$2` — target pattern (e.g. "extract repository", "split god service")

## Execution steps

1. Ensure tests exist and pass FIRST (characterization tests if absent).
2. Refactor in small steps, running tests after each.
3. Keep the public API identical unless the user approved a contract change.

## Validation checklist

- [ ] All tests still pass
- [ ] Public API unchanged (or change documented)
- [ ] No new dependencies between layers
- [ ] `dependency-cruiser` clean

## Expected output

Same behavior, better structure.

## Failure handling

If tests are missing, write them before refactoring — never refactor blind.
