Same behaviour. Cleaner code.
Refactoring means reorganising code without changing what it does. It keeps a growing project understandable, for you and for the agent.
Time to refactor when
One file is growing past a few hundred lines.
The same code is copied in three places.
You can't find where things happen.
The agent keeps breaking unrelated parts.
01
Tests first
Cover what it does now.
02
Commit
A clean save point.
03
One change
Split, rename or merge.
04
Run tests
Still green? Commit.
Tests first. Tidy second. Features third.