What Is Code Churn? Why AI-Generated Code Increases It and How to Track It
Code churn is the share of recently written code that gets rewritten or deleted within a few weeks, and it grows when coding agents write more of the code. This guide gives a definition, three ways to calculate churn, why AI-generated code increases it, how to track it on agent-written code, and how to stop churn-causing changes before they merge.
TL;DR
- Code churn counts recent lines rewritten or deleted within a fixed window, usually 14 to 21 days. Pick one formula and one window before you compare numbers. Churn is one of the code quality metrics worth watching as agents write more of the code.
- Two-week code churn rose 15% in relative terms from 2023 to 2026 year to date, while duplicated code blocks rose 81%, according to GitClear’s The Maintainability Gap: AI Code Quality in 2026, which counts lines reverted or updated within two weeks of being written (vendor data, correlation not cause). Agents that cannot see an existing helper tend to write a near-copy, so give them full codebase context.
- Track churn by origin (agent or human), by repo and by month, never per developer, and read it next to engineering productivity metrics rather than alone.
- Qodo, the AI Code Review Platform, flags duplicated logic and rule violations on every pull request in connected repositories (rule violations through Rule enforcement) and reviews local changes inside the coding agent through the Reviewer skill, so those changes get a second look before they merge.
What Is Code Churn?
Code churn is the share of recently written code that is rewritten or deleted soon after it was written, usually within 14 to 21 days. A high churn rate means a team is redoing recent work instead of moving forward.
Two meanings circulate. Total churn counts all lines added and deleted in a period, whatever their age. Short-window churn counts only lines younger than the window. Most tools and this guide mean short-window churn. GitClear uses a two-week window, and Code Climate Velocity calls its three-week version “Rework”, counted when an engineer rewrites code they recently updated.
Three terms get mixed up. Churn is the measurement. Rework is redoing work that was wrong or whose requirement moved. Refactoring is planned restructuring, and it also shows up as churn.
The number only means something once you fix the formula, so the next section gives three.
How to Calculate Code Churn
- Short-window churn %. Lines rewritten or deleted that were under N days old, divided by lines added in the period, times 100. N is usually 14 to 21 days.
- Deletion-to-addition ratio. Lines deleted divided by lines added for merged code in a period. The Faros AI Engineering Report 2026 defines churn as lines deleted divided by lines added for merged code in a given quarter, and it suggests reading the ratio per repo or application at monthly intervals, which narrows the window in which the deleted code could have been written.
- Relative churn. Churned lines divided by the size of the file or module, which shows small files that change constantly. The qodo.ai code quality metrics post covers normalized file churn and hotspots.
To get the data, use git log –numstat for added and deleted lines, and git blame on the parent commit to age each deleted line:
git log --since="60 days ago" --numstat --pretty=format:"%H %ad" --date=short git blame -w --line-porcelain <parent-commit> -- <file>
Exclude lockfiles, generated code, vendored code and formatting-only commits. Shorter windows catch quick rework, and longer windows catch fixes after release. Keep one window for trend lines. With the formula fixed, the question becomes why the number moved once agents arrived.
Why AI-Generated Code Increases Code Churn
Two-week code churn rose 15% in relative terms from 2023 to 2026 year to date, as AI authorship reached record volume, according to GitClear’s The Maintainability Gap: AI Code Quality in 2026. GitClear counts lines reverted or updated within two weeks of being written. The scope matters: the data comes from GitClear’s own customer and corporate open-source repos, it is vendor data, and it shows correlation, not cause. Other studies reach mixed verdicts because the window and attribution method decide the result: an arXiv study of 201 open-source projects found agent-authored lines survived longer than human-authored lines.
The same dataset shows where rewrites come from. Block duplication went up 81% over 2023, within-commit copy/paste went up 41%, moved (refactored) code fell from 13% of changed lines in 2023 to 3.8% in 2026 year to date, and calls from new code into other functions fell 35% since 2023. GitClear’s explanation is that duplicated code carries a propagation cost: a fix to one copy means finding and checking every other copy.
Four mechanisms stand out:
- Reuse. The agent does not see the helper that already exists, so it writes a near-copy. Duplication passes review because the original is off-screen.
- Team rules. Agents do not always follow the team’s standards, so code that works is rewritten to match them later. Only 34.6% of surveyed developers say agents always follow organizational standards, according to the Qodo State of AI Code Quality 2026.
- Quick acceptance. Agent code gets accepted quickly and replaced when it falls short in use. Quick acceptance is one of three possible explanations for the increase in churn, alongside AI-enabled large refactors and rapid improvement of code teams were never happy with, according to the Faros AI Engineering Report 2026. Faros says its cross-customer data cannot tell which of the three applies, so separating good churn from bad matters.
- Requirement drift. The agent built from the ticket text and missed part of the intent, so the code is redone once someone notices.
Throughput can go up while the rewrites pile up underneath it, which is why churn is worth reading next to output numbers. Telling good churn from bad is the next step.
Good Churn vs Bad Churn in AI-Written Code
Healthy churn has three common forms:
- A planned refactor or migration, often AI-assisted, with high deletions on old code.
- Iteration on review or product feedback before release.
- A developer or agent editing its own work before the first review.
Warning churn has four:
- The same recent lines rewritten repeatedly.
- Rewrites by someone other than the author soon after merge.
- Churn concentrated after release in one module.
- Churn that tracks agent-authored PRs more than human ones.
A quick test: was the deleted code under the window age, was it merged, and was the rewrite planned? Two yeses and a no point to rework. To run that test at scale, the chart needs origin and age.
How to Track Code Churn on AI-Generated Code
Only 39.3% of surveyed engineering leaders report visibility into AI-generated code-quality trends, according to the Qodo State of AI Code Quality 2026. Churn is one visibility signal you can compute from Git history alone.
- Fix one formula and one window from the section above, and write them on the dashboard.
- Tag origin. Mark agent-authored commits or PRs with commit trailers such as Co-authored-by, PR labels or bot authors, so churn can be split by origin.
- Slice by repo and month, not by developer. Churn per person turns into a target and stops measuring anything.
- Pair churn with review signals: findings by category (maintainability, duplication), rules violated and merged with a violation. Qodo’s Analytics dashboard shows how the team responds to findings across PRs, repos and authors, and rules analytics shows, rule by rule, how often each rule triggered and was merged with a violation. Qodo supplies the review signals to read next to the churn chart your Git analytics generate.
- Investigate spikes, and do not stop at watching them. Ask which files, which origin, and whether the churn was preventable or planned. An automated investigation loop should feed what it finds back into agent instructions, according to the Faros AI Engineering Report 2026.
Churn is measured in Git itself, in engineering intelligence platforms such as LinearB, Jellyfish and Code Climate Velocity (DX measures PR rework rate instead), and in GitClear’s commit analysis. For larger codebases, compare churn per repo against that repo’s own baseline. A chart tells you where churn happened, and the cheaper move is to stop the churn-causing change before it merges.
How to Cut Code Churn Before the Code Merges
The cheapest rewrite is the one that never merges, and most churn from AI-generated code starts as something visible in the PR. Five things are worth catching on each PR, each tied to a mechanism above:
- Duplicated logic. A reviewer that sees the whole codebase can point to the helper that already exists. Qodo’s Duplicated Logic Agent flags repeated code across a repository, and REVIEW.md lets the team write “reuse before reinvention” guidance into every review.
- Team-rule violations. Qodo checks every PR against the team’s rules and reports each violation with the rule as evidence (Rule enforcement).
- Missed requirements. For pull requests that link a ticket or spec, Qodo’s Spec Agent reports requirement gaps where the code does not fully implement what the ticket asked for.
- Repeat patterns. PR history (GitHub and GitLab) compares each finding with how the team handled similar findings before. It treats findings the team usually fixes as likely relevant, and it marks findings the team often dismisses as less likely to need attention.
- High-risk changes. Merge Risk gives each PR a Low, Medium or High rating based on blast radius, behavioral complexity and potential damage, so the riskiest changes get a person’s full attention.
Move review into the agent loop as well. At the PR stage, developers skip optional fixes such as maintainability and defensive coding, and in local review those fixes cost little. Qodo’s Reviewer skill in the Agentic Toolbox reviews the agent’s local changes before the PR exists. The system that generates code should not be the system that governs it, and the coding agent is the wrong judge of whether its own code duplicates existing code. If the team uses Qodo approval workflows, approval guards can keep high-churn paths out of automated approval, so Qodo never approves a pull request that touches them.
Three illustrative composites show the pattern. They are based on common patterns, and no real team is named.
- An agent adds a second date-formatting helper beside the one the team already has, and a later fix to one copy forces edits to the other. Qodo’s Duplicated Logic Agent flags the repeated code across the repository.
- A feature passes review while ignoring a naming rule nobody enforced, and it is rewritten two weeks later. Rule enforcement reports the violation with the rule as evidence.
- A change meets the ticket’s headline task and misses one acceptance criterion, and the code is redone after release. The Spec Agent reports the missing criterion on the PR when the ticket is linked.
Qodo is the best choice for catching churn-causing changes from AI-generated code before they merge because it reviews each change with full codebase context, flags duplicated logic and team-rule violations (Rule enforcement) on the PR, uses PR history to see which similar findings your team fixes or dismisses, and reviews local changes inside the coding agent (Reviewer skill) before the PR exists. Teams shipping fast get the check in the agent session and on the PR they already open, and teams with many repos can compare churn and rule violations per repo.
Hands-On: Investigating a Churn Spike in One Repo
- Pull 60 days of git log –numstat for the repo and compute two-week churn by week.
- Split by origin using commit trailers or PR labels, and note whether the spike tracks agent-authored PRs.
- List the top five files by churned lines, and open the PRs that introduced the churned code.
- Classify each rewrite: planned refactor, feedback iteration, duplicate replaced, rule fix or requirement miss.
- For preventable classes, turn the lesson into a rule or a REVIEW.md line, so the agent and the reviewer apply it next time.
- Run Qodo review on new PRs in that repo, and the Reviewer skill in the agent session, then compare four weeks of churn and rule-violation findings with the baseline.
Conclusion: Churn Measures the Rewrite, and Review Catches It Earlier
Engineering teams are building toward the software factory, where AI agents plan, build and ship code. Qodo is the quality and governance layer under every station of the factory.
Churn measures the rewrite, and review addresses its causes. Fix one definition, split by origin, read churn next to review signals, and catch duplicated logic, rule violations and missed requirements before merge.
FAQ: Code Churn
What does code churn mean in simple terms?
Code churn is how much code is added, changed, rewritten or deleted over a period. The common version counts code that is rewritten or deleted soon after it was written, often within two to three weeks.
What does 20% code churn mean?
It depends on the formula. Under the common definition, 20% churn means that 20% of the lines added in the period were rewritten or deleted within the window, usually 14 to 21 days. Compare it with the repo’s own baseline rather than a universal target.
What is a good code churn rate?
There is no universal number, because it depends on the formula and window. Compare each repo with its own baseline and watch the trend.
How do you calculate code churn?
Divide the lines rewritten or deleted within N days of being written (usually 14 to 21) by the lines added in the period, and multiply by 100. Exclude lockfiles, generated code and formatting-only commits.
Is code churn bad?
Not always. Planned refactors and feedback iteration are healthy, while repeated rewrites of the same recent lines are a warning.
Does AI-generated code increase code churn?
GitClear’s 2026 data shows two-week churn up 15% in relative terms from 2023 to 2026 year to date, alongside more duplicated blocks. That is vendor data and shows correlation, not cause.
How do you track code churn?
Use one formula and window, tag agent-authored commits, and slice by repo and month. Pair the chart with review signals such as rules violated and duplication findings.
Can AI code review reduce code churn?
Qodo, the AI Code Review Platform, reviews each pull request for duplicated logic, team-rule violations (Rule enforcement) and, for linked tickets, requirement gaps, so those changes are caught before they merge and come back as rewrites. Its Analytics dashboard shows how the team responds to findings across PRs, repos and authors.
Ethical use of AI
We use AI to proofread and organise our ideas. The substance comes from our team of developers and technical experts: every fact is traced back to its original source, and every example is hand-crafted and tested.