# Diff limits: stop a coding agent from rewriting the repository

> File, line, and duplication limits help keep implementation close to the requested scope.

- By: Djan Magno
- Published: 2026-09-27
- Updated: 2026-09-27
- URL: https://t25.io/en/blog/diff-limits-runaway-coding-agent/
- Engineering · diff, change limits, coding agents, policy, code review

> **TL;DR:** > - A diff limit is a pipeline rule that stops an implementation if it changes more files or lines than the configured ceiling.
> - T25 can also measure repeated lines in production files. Test files are excluded from that metric.
> - When a limit is exceeded, the task fails and gets a handoff summary; the system does not shrink the diff automatically.
> - These limits control size and one duplication signal. They do not prove the code is correct or secure.

## What a diff ceiling does

A **diff ceiling** is a configurable limit on implementation size. In T25, `max_files_changed` caps how many files a task may change, while `max_diff_lines` caps the changed lines in the diff. `max_duplicate_line_ratio` adds a check for excessive repetition in production files.

These rules do not understand what the code is meant to do. They flag changes that grow beyond what a project is willing to review in one task. Finding review and the human gate still matter; see [why the model's APPROVE is not the merge](https://t25.io/en/blog/the-models-approve-is-not-the-merge/).

## The default limits

The currently documented defaults are:

| Key | Default | What it counts |
|---|---:|---|
| `max_files_changed` | 40 | Files changed by the task |
| `max_diff_lines` | 2000 | Changed diff lines |
| `max_duplicate_line_ratio` | 0.5 | Highest duplicate-line ratio among production files |

The duplication ratio is measured per file, and the highest ratio is compared with the ceiling. Test files under `test/`, `tests/`, or named `.test.` and `.spec.` are left out of that calculation. In bootstrap mode, T25 skips only this metric; file and line limits still apply.

## Set limits for your repository

Use the `limits` block in `t25.yaml` to adjust these values:

```yaml
limits:
  max_files_changed: 40
  max_diff_lines: 2000
  max_duplicate_line_ratio: 0.5
```

These are the documented defaults, not a prescription for every repository. If your team reviews smaller tasks, lower the ceilings. If legitimate work needs more room, consider splitting it into reviewable deliveries before making an exception. A higher ceiling accepts larger diffs; one set too low can reject valid work.

## What happens when a limit is exceeded

After implementation, T25 collects workspace statistics and compares each configured metric with its limit. If any rule fails, it writes a `handoff.md` artifact with the reason and observed numbers, then marks the task as failed. The agent does not quietly proceed to QA as if the diff passed policy.

The handoff explains the block so the team can decide what to do next. You might reduce the scope, split the task, or review the project limit. The factory does not trim files from the diff or change the limits on its own.

T25 records the failure and handoff so the team can decide what to do next. Check the task state and artifacts available in your environment before resuming work.

## What this guardrail does not check

A small diff can still contain a serious bug, regression, or security issue. A large change can also be necessary for a migration or bootstrap task. That is why diff ceilings complement the spec, tests, QA, review, and risk controls; they do not replace them.

For task-specific branches and worktrees, see [one task, one worktree](https://t25.io/en/blog/one-task-one-worktree-isolating-ai-coding-agents/). The [configuration reference](https://t25.io/en/docs/) lists the option names and descriptions.

## FAQ

### Does T25 delete or revert the diff when it exceeds a ceiling?

No. The task fails and gets a handoff summary. The team decides whether to reduce scope, split the work, or adjust policy.

### Do test-file lines count?

They count toward `max_diff_lines`. They are excluded only from the `max_duplicate_line_ratio` calculation.

### Does bootstrap mode ignore every limit?

No. It skips the duplication check; file and line ceilings still apply.

### Is a diff ready to merge if it stays under the ceiling?

No. The ceiling measures size and, optionally, repetition. QA, review, and the human gate still need to do their jobs.

### Should I raise the ceiling for a large task?

Consider splitting the task first. If the larger scope is justified, adjust the project policy deliberately and keep human review of the result.
