Skip to content

perf(tools): stop echoing written files back to the model - #422

Merged
mrnasil merged 1 commit into
mainfrom
perf/write-result-summary
Nov 7, 2026
Merged

mrnasil merged 1 commit into
mainfrom
perf/write-result-summary

Conversation

@mrnasil

@mrnasil mrnasil commented Nov 7, 2026

Copy link
Copy Markdown
Member

Part of the token-efficiency series (#418–#421).

Problem

write returned a preview of the first 40 numbered lines of the file it had just written. The model sent that content itself, so the echo gives it no new information. Pruning only cuts results past 2 KiB, so each write kept roughly 500 tokens in context until compaction.

Change

  • Model. The model now gets Wrote <path> · N lines plus the [+N -M] trailer. This comes from format_write_summary, which is the preview's own header line; format_write_preview now starts with it.
  • TUI. tool_block rebuilds the coloured preview from the call's content argument, which it holds both live and on resume. What it paints is byte-identical to before. A stored result that still carries a preview (an older transcript) is painted as is.
  • Unchanged. The approval prompt (preview_write) is unchanged, and so is edit_stats (it reads the trailer).
  • edit keeps its diff on purpose. For a tag-addressed edit (from/to/insert_after), the replaced block comes from the file, and seeing it is how the model catches a wrong range.

Measured (o200k)

File written Before After
crates/agent/src/notify.rs 539 tok 22 tok
crates/session/src/title.rs 543 tok 20 tok
README.md 915 tok 17 tok

Checks

  • New test write_block_paints_the_same_preview_from_its_content_argument: the TUI paints identical lines from the compact result and from the old full preview. It also covers the legacy, empty-file, error and non-write cases.
  • tools 538, agent 764 and tui 1495 lib tests pass, plus the format tests.
  • fmt, clippy (format, tools, tui) and ratchets are ok. Local llvm-cov: every changed line in format and tools is covered.

🤖 Generated with Claude Code

`write` returned a preview of the first 40 numbered lines of the file it
just wrote. The model sent that content itself, so the echo told it
nothing, and pruning only cuts results past 2 KiB, so each write kept
~500 tokens in context until compaction.

The model now gets `Wrote <path>  ·  N lines` and the `[+N -M]` trailer
(`format_write_summary`, the preview's own header line). The TUI rebuilds
the coloured preview from the call's `content` argument, which it already
holds live and on resume, so what it paints is unchanged; a stored result
that still carries a preview is painted as before.

`edit` keeps its diff: for a tag-addressed edit the replaced block comes
from the file, and showing it is how the model catches a wrong range.

Measured (o200k): a 40+ line Rust file 539 -> 22 tokens, README.md 915 -> 17.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mrnasil
mrnasil force-pushed the perf/write-result-summary branch from 3ffb70e to da6946f Compare November 7, 2026 13:37
@mrnasil
mrnasil merged commit 7f2ea77 into main Nov 7, 2026
7 checks passed
@mrnasil
mrnasil deleted the perf/write-result-summary branch November 7, 2026 13:48
@mrnasil mrnasil mentioned this pull request Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant