An energy fix that changes behaviour is a bug. Legacy code often has no tests, so an optimisation cannot be checked and nobody dares merge it.
The fix you can use today
Pin current behaviour with characterisation tests before changing anything.
Run the full suite before and after every optimisation.
Keep public interfaces unchanged unless you mean to change them.
GreenCode researchers put one rule first: never break the code to save energy.
Tools that help
GreenCode Constitution skill (GreenCode researchers): open-source energy principles and a catalogue of 37 energy anti-patterns that an AI coding agent can follow to find and fix waste like this
SonarQube: static analysis for code smells, bugs and security issues, with quality gates in CI
How GreenCode helps
GreenCode helps tackle this by generating the missing unit tests before it changes any code. Every optimisation is then gated on quality issues, security flaws and error rate, which must not rise. More on this.