Skip to main content
Glossary

What Is Code Churn?

Code churn is the percentage of newly written code that gets rewritten or deleted shortly after it is committed, typically within two to three weeks. Some churn is normal iteration; sustained high churn signals rework, unclear requirements, or low-quality code.

2-minute setup • No credit card required

What it means

Code churn measures how stable new code is. Formula: churn rate = (lines added in a window that are modified or deleted within that window ÷ total lines added in the window) × 100, with the window usually two to three weeks. If a team adds 10,000 lines in a two-week window and 1,800 of those lines are rewritten or removed before the window ends, churn is 18%. It is computed from git history, so it needs no extra instrumentation. Some rework is normal and healthy: code changes during review, after tests, and as developers learn the problem. Commonly cited guidance treats churn sustained above roughly 20–25% as a warning sign worth investigating, though the right level depends on the phase: prototypes and planned refactors churn more, stable products less. Churn is different from simply counting lines changed: it focuses on code that did not survive, which is wasted or redone work. AI-generated code adds a new angle. AI-assisted code tends to be accepted quickly and rewritten later, and GitClear's research reported code churn rising alongside the adoption of AI coding assistants. Many teams now compare the churn of commits authored by AI agents against human-written commits to see whether AI output is actually sticking.


Why Code Churn matters

Code churn is an early warning that a team is building, tearing down, and rebuilding the same thing. High churn on a feature means it is further from done than the ticket status suggests, and it often traces back to shifting requirements, rushed design, or review feedback arriving too late. Per-repository churn trends also help with onboarding (new contributors churn more as they learn the codebase) and with risk: files that are both high-churn and high-complexity are where bugs concentrate. With AI coding agents writing a growing share of commits, churn is one of the clearest ways to judge whether that output holds up: if agent-authored lines are rewritten far more often than human lines, the time saved writing them is being spent again on rework. Gitmore's AI agent ledger attributes commits to agents such as Claude Code, Cursor, and Copilot using Co-authored-by trailers and other git signals, which gives you the human-vs-agent split you need before comparing churn between the two.


How to measure

1) Choose a window, typically two to three weeks. 2) List every line added in that window from git history (git log --numstat or blame-based tooling). 3) Count how many of those lines were modified or deleted before the window closed. 4) Churn rate = churned lines ÷ lines added × 100. 5) Track it as a weekly trend per repository rather than a single number, and investigate spikes. 6) To compare AI and human code, split commits by author type first (for example, by Co-authored-by trailers that agents such as Claude Code or Copilot add) and compute churn for each group separately. A rough approximation without line tracking: if deletions are consistently more than half of additions over a period, churn is likely high. Avoid using churn to rank individual developers; it reflects the work and its requirements as much as the person.


Real-world example

A team building a new payments feature notices their churn rate jumped from 20% to 55% over two weeks. Investigation reveals the product spec changed twice during development, requiring significant rewrites of the API contract and database schema. The engineering manager works with the product manager to freeze the spec and document edge cases before the team resumes coding. Churn drops back to 18% in the following sprint, and the feature ships on the revised timeline.

FAQ

Common questions

How do you calculate code churn?

Code churn rate = (lines added in a time window that were then modified or deleted within that window ÷ total lines added in the window) × 100. The window is usually two to three weeks. For example, 1,500 churned lines out of 10,000 added is 15% churn.

What is a normal code churn rate?

There is no official benchmark, but common guidance is that some rework is normal and that churn sustained above roughly 20–25% is a warning sign. Expect higher churn during prototyping or planned refactors and lower churn on mature, stable code. Watch the trend for your own team rather than comparing to other companies.

Is high code churn always bad?

No. High churn is expected during prototyping, major refactors, or early exploration. It becomes a problem when it persists on features that should be stabilizing, or when it is caused by changing requirements forcing repeated rewrites. A 40% churn rate during a planned refactor can be fine; the same rate on a feature that was supposed to ship last week is a red flag.

Does AI-generated code have higher churn?

It can. AI-assisted code is easy to accept quickly and is often rewritten later, and GitClear's research reported rising code churn alongside AI assistant adoption. The reliable way to know for your team is to measure it: attribute commits to AI agents (for example, via Co-authored-by trailers) and compare churn for agent-authored versus human-authored code over the same window.

How can I tell which commits were written by an AI agent?

Many agents leave signals in git: Co-authored-by trailers (Claude Code, Copilot and others add them), bot accounts, and branch name prefixes. Gitmore's AI agent ledger reads these signals across GitHub, GitLab, and Bitbucket to attribute commits to agents like Claude Code, Cursor, and Copilot, without reading your source code.

How is code churn different from code complexity?

Churn measures how often recently written code changes; complexity measures how hard code is to understand and maintain. They are related but distinct. Files that are both high-churn and high-complexity are usually the riskiest areas of a codebase.

Can you measure code churn from Git?

Yes. Git records every addition and deletion, so you can use git log --numstat or blame history to see which recently added lines were later modified or removed, then compute the percentage. Dedicated git analytics tools automate the line tracking and show churn as a trend.

Track Code Churn Automatically

Gitmore turns your git activity into automated reports with real metrics — delivered to Slack and email.

Get Started Free

No credit card • No sales call • Reports in 2 minutes