Break a monolithic function into single-responsibility pieces
A 300-line function that works is still a 300-line function someone has to understand all at once to change safely.
- Use it for
- Anyone with a large, working function that's become hard to read or modify safely.
A large function that works is genuinely risky to change — understanding what it does requires holding the whole thing in your head at once, and a small edit can have effects in a part of the function you weren't focused on. This prompt breaks it into small, named, single-responsibility pieces, each doing one identifiable thing, while preserving exact behavior.
When not to use this
If the function is long but each line genuinely belongs to one cohesive operation with no natural seams, forcing a split can make it worse — this is for a function that's actually doing several distinct things stitched together.
Did this work?
Each resulting piece does one identifiable thing you could name in a function name, and the original behavior is fully preserved.
Tested on claude-opus-5. Evidence status is draft; it moves to battle-tested only on recorded runs, never by hand.