[BUG] /diff turn view counts one extra added line for every created file

Status Open
Reported on v2.1.269
Maintainer reply None cached
Activity 0 comments · opened Sep 11, 2026

Preflight

  • [x] I searched the open bug issues and did not find this one.
  • [x] This is a single bug report.
  • [x] I am on the latest version (2.1.269).

What's Wrong?

When Claude creates a file, the turn tab of /diff shows one more added line than the file has, and the extra row is an empty + at the bottom.

A file written as "one\ntwo\nthree\n" shows +4 in the turn view while the git view of the same pane shows +3 for the same file. An empty file shows +1 with a blank row. A created file of exactly 400 lines (MAX_LINES_PER_FILE) is counted as 401, so the pane adds "… diff truncated (exceeded 400 line limit)" although nothing was cut.

The cause is the same in both places that build a created file's hunk: content.split('\n'). Nearly every file ends with a newline, and splitting on it yields a trailing empty string, which becomes an extra + row and an extra counted line.

  • In this repo: mods/diff/hooks/turns/turn-of/file-edit-of/file-edit-of.ts, in fileEditOf.
  • In the shipped binary 2.1.269, the built-in turn view does the same content.split("\n").

What Should Happen?

A created file's final newline should end its last line rather than open an empty one, the way git counts lines, so the turn view and the git view agree. An empty created file should have no hunk, and a 400-line created file should not be reported as truncated.

Error Messages/Logs

turn view:  path/to/new.ts  +4
git view:   path/to/new.ts  +3
git diff --numstat: 3  0  path/to/new.ts

Steps to Reproduce

  1. Ask Claude to create a file with three lines, for example one, two, three, written with a trailing newline (the usual case).
  2. Open /diff and look at the turn tab: the file shows +4, with an empty + row at the end.
  3. Switch to the git view in the same pane: the same file shows +3, which matches git diff --numstat.
  4. For the truncation case, ask Claude to create a file of exactly 400 lines and reopen the turn tab: the pane shows "… diff truncated (exceeded 400 line limit)" although the whole file is there.

Environment

  • Claude Code 2.1.269
  • Windows 11, Node 25
  • mods/diff at current main

Fix

I checked fileEditOf against git diff --numstat on real files, loading fileEditOf and turnOf straight from source under Node. On current main, 7 checks fail: "one\ntwo\nthree\n" gives 4 instead of 3, "" gives 1 instead of 0, "\n" gives 2 instead of 1, "x\n\n" gives 3 instead of 2, the empty file gets a hunk, and the 400-line file counts 401 and comes out isTruncated: true. Dropping the final newline before splitting, and giving an empty file no hunk, makes all of them pass. Content without a trailing newline and results that carry a structuredPatch are unchanged.

I have that change on a branch, but pull requests here are limited to collaborators, so here is the comparison instead:

https://github.com/anthropics/claude-code/compare/main...Dev-next-gen:claude-code:fix/turn-view-created-file-trailing-newline

If it is useful and someone opens the door for a PR, or wants to take the patch as is, it is ready.

One caveat: since the built-in turn view splits the content the same way, the mod would count created files differently from the built-in until the built-in gets the same fix. The git-consistent count looks like the right one to keep, since the pane shows both side by side.

AI tools used

View original on GitHub ↗