Rebuilding 100,000 Lines of Code in Six Months: The Limits and Costs of AI Coding

    This article examines a six-month effort to redesign and refactor roughly 100,000 lines of legacy code with AI coding tools, and why the timeline collapsed. It breaks down where AI actually improves output, where it falls short, a practical five-step approach to large-scale refactoring, and the health and sustainability costs of an unsustainable pace. The takeaway: AI lowers the cost of writing code, not the cost of making correct decisions.

    1. Background: A Legacy Rewrite Compressed by an Aggressive Deadline

    An engineer with seven years of production web development experience decided to bring AI coding tools into his daily workflow at a time when most of his team was still waiting to see how things played out. He did not treat the tools as replacements but as capability amplifiers: producing feature prototypes and demo solutions faster, and wiring large language model capabilities into his own products. Performance and architecture work that had been shelved because of tight schedules was suddenly back on the table.

    The trouble started with the goal itself. An internal web application at his company had originally been written by an intern, and it was itself forked from an even earlier intern project, so technical debt had piled up layer on layer. To win management’s support, he committed to independently redesigning and refactoring roughly 100,000 lines of code within a few months. Six months later, the conclusion was clear: the schedule promise had been too aggressive, the tools had been pushed to their limits, and he himself was close to burnout.

    The value of this case is not “which tools were used.” It is that it exposes a common pattern: AI coding raises output per unit of time, not the quality of decisions. When the plan itself is unreasonable, the tools only make mistakes happen sooner and faster.

    2. Where the Efficiency Gains Actually Come From, and Where They Stop

    The benefits of AI coding tools concentrate in four kinds of tasks:

    • Generating boilerplate and glue code, such as CRUD endpoints, form validation, and data transformation;
    • Understanding legacy code, where local explanations and call-chain mapping lower the cost of reading it;
    • Repetitive changes, such as standardizing error handling or bulk-replacing outdated patterns;
    • Filling in tests and documentation, pulling work that was “never going to get done” back into the plan.

    The boundaries are equally clear. The tools are good at local optimization, not global trade-offs; good at syntax and patterns, not at judging business semantics and historical baggage. Output quality drops noticeably when the context window is stuffed with irrelevant information, and when requirements are vague, the tools will paper over real ambiguity with an implementation that “looks reasonable.”

    Schematically, one reusable way to constrain a task is to cut it small and declare the boundaries explicitly:

    1. Goal: refactor only the query layer of the order module
    2. Constraints: do not change public interface signatures; preserve existing transaction boundaries
    3. Output: list of changed files + impact notes + corresponding unit tests
    4. Prohibited: introducing new runtime dependencies

    3. A Practical Method for a 100,000-Line Refactor

    1. Map dependencies before touching the first line

    Use static analysis to lay out module dependencies, circular references, and hot files, then decide the order of changes. The principle is “periphery before core, leaves before trunk,” so you avoid starting work in multiple places within the dependency center at the same time.

    2. Build a regression safety net

    Refactoring a legacy system with no tests is an uncontrolled risk. Start by locking down external behavior with contract tests and snapshot tests, then replace the internal implementation layer by layer. Even if coverage only reaches the critical paths, that beats zero.

    3. Commit in small steps, prioritize rollback

    Break the large refactor into hundreds of independently verifiable small changes, each of which can be rolled back on its own. This lowers the cost of any single failure and makes reviewing AI-generated content feasible.

    4. Supply context in layers

    Feed information in three layers — architecture conventions, module responsibilities, current task — and strip out unrelated files. The cleaner the context, the more stable the generated results.

    5. Automate quality gates

    Wire formatting, static checks, type checks, tests, and builds into continuous integration as hard conditions for merging. Keep human review focused on design trade-offs, and leave mechanical issues to the pipeline.

    4. Cost, Health, and Sustainability

    A tool subscription running into the thousands of yuan per month, more than ten hours of high-intensity coding a day, and six months of uninterrupted delivery add up to an unsustainable curve. What actually needs to be designed is the rhythm, not the peak:

    • Set “incompressible time” to protect sleep and recovery;
    • Measure output on a weekly rather than daily basis, so a single day’s sprint does not mask accumulated fatigue;
    • Hand low-creativity work like review, testing, and documentation to the tools, and keep architecture decisions for yourself;
    • Give range estimates on commitments, and align with management using the “scope–time–quality” triangle instead of a single-point decision.

    5. Conclusion

    AI-assisted development has lowered the cost of writing code, but it has not lowered the cost of being right. The lesson from the 100,000-line refactor comes down to three sentences: leave slack in the plan, keep context lean, and enforce quality with automated gates. If an organization wants similar capabilities under compliant, controlled conditions, it can look at general-purpose offerings from Baidu AI Cloud in engineering efficiency and cloud-native infrastructure — such as container platforms, log services, monitoring and alerting, and object storage — replacing heroics-driven sprints with a standardized engineering foundation.