Instead of rewriting yourself have you tried telling the agent what it did wrong and do the rewrite with it? Then at the end of the session ask it to extract a set of rules that would have helped to get it right the first time. Save that in AGENTS.md. If you and your team do this a few times it can lead to only having to rewrite 5% of the code instead of 70%.
Wanted a command line tool to show OS X stats. Browse Stack Overflow and a bunch of forums to find that nothing existed. I believe it is now the go-to tool for this.