The Economic Benefit of Refactoring
martinfowler.com 2 months ago 12
A developer built a 150,000-line codebase entirely with AI agents, then systematically refactored a 17,155-line data access layer file to measure token cost savings. By splitting the file into 19 smaller files through planned refactoring steps, input tokens required for the same representative task dropped from 159,564 to 27,360—an 83% reduction. The experiment demonstrates that refactoring AI-generated codebases can substantially reduce token consumption for future changes, though the developer could not measure the upfront refactoring cost and notes AI agents require explicit human direction to apply refactorings effectively.