behavior-preserving-module-extractionlisted
Install: claude install-skill oliver-chase/OliverCode
# Behavior-Preserving Module Extraction
## When to Use
A single file has grown past 500+ lines. It contains distinct clusters of functionality that don't share much state.
## 4-Step Process
### Step 1 — Identify Extractions
Scan the large file for:
- Functions that share a common prefix or import set
- Functions that all use the same data source (DB, API, file)
- Functions that can be tested independently
Group them into a proposed module.
### Step 2 — Create the Module
```python
# lib/new_module.py — extracted from big_script.py
def function_a(input):
...
def function_b(input):
...
def function_c(input):
...
```
Import it in the original file:
```python
from lib.new_module import function_a, function_b, function_c
```
### Step 3 — Wrapper Delegation
Replace the original function bodies with calls to the new module. Same signature, same behavior:
```python
# OLD
def function_a(input):
# 50 lines of logic
# NEW
from lib.new_module import function_a as _function_a
def function_a(input):
return _function_a(input)
```
This preserves all call sites — no caller needs to change.
### Step 4 — Remove Wrappers (Optional)
Once the new module is stable, update all call sites to import directly from the module. Then remove the wrapper functions from the original file.
## Fast Feedback
- Run tests after every extraction, not after all 6
- If the test suite is slow, run only the tests that touch the extracted functions
- Run the app and exercise th