Skip to content

Edit tools return line-number prefixes while read_file strips them #765

Closed

Description

@will-lamerton

Problem

The same file is returned to the model in two different representations depending on which tool produced it.

read_file deliberately strips line numbers (source/tools/read-file.tsx:175-176):

// Return content without line numbers for clean content-based editing
return linesToReturn.join('\n');

But string_replace (source/tools/file-ops/string-replace.tsx:86-88) and write_file (source/tools/file-ops/write-file.tsx:58-60) both return it with a %4d: prefix on every line.

Two costs:

  1. The prefix is about 6 characters per line for information the model rarely needs, given both our editors are content-based rather than line-based. On a 500-line file that is roughly 750 tokens of pure formatting.
  2. Seeing the same file in two representations within one session is a plausible independent trigger for re-reading to disambiguate, which is the exact behaviour flagged in the benchmark writeup.

Fix

Drop the prefixes wherever the content is not being cited by line number. Since read_file already establishes the no-line-numbers convention and that is the tool the model sees most, the edit tools should match it.

Related

Largely moot for write_file and string_replace if the echo-removal issues land, since there will be no echoed content left to prefix. Worth keeping open as a convention decision, and it still applies to any future tool that returns file content.

Activity

  1. will-lamerton commented on Aug 3, 2026

    @will-lamerton
    MemberAuthor

    Part of #772.

  2. siddhanttiwari19 commented on Aug 3, 2026

    @siddhanttiwari19

    Hey @will-lamerton , I'd like to pick this up. Makes sense to standardize on read_file's no-line-numbers convention ,I'll update string_replace and write_file to drop the %4d: prefix from their returned content so all three tools are consistent. Mind assigning it to me?

  3. will-lamerton commented on Aug 9, 2026

    @will-lamerton
    MemberAuthor

    Closing this as resolved, and recording the convention it was held open to decide.

    The cost argument here died with the bounding work. #776 removed the write_file echo entirely, #784 bounded string_replace to a 20-line window either side of the edit, and #798 has just done the same for diff_edit. No tool returns a whole file to the model any more, so the "roughly 750 tokens on a 500-line file" this issue opened with no longer exists to save. The most any edit tool now emits is about 40 lines of window.

    What's left is the convention question, and the answer is that the remaining line numbers stay. Both string_replace and diff_edit now return Updated file context (lines X-Y of N) with [... lines A-B omitted ...] gap markers. The header and the markers cite line numbers, so per-line numbers inside the window are doing orientation work in a partial view that they weren't doing in a full-file dump. Stripping them there would make the excerpt harder to place, not cheaper.

    The convention, for future tools returning file content:

    • read_file returns raw content with no line numbers, for clean content-based editing (source/tools/read-file.tsx:175-176).
    • Bounded excerpt contexts keep per-line numbers, because their headers and gap markers reference them.
    • Display formatters always number, and always have. That's the Ink layer, not the LLM payload.

    Thanks @Pixie-19 for #790, which correctly identified the inconsistency before the bounding work landed and made the case for dealing with it.

  4. added
    area:providers
    on Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area:providersclean upgood first issue

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions