Repository navigation
Description
Problem
source/tools/file-ops/write-file.tsx:48-64 reads the file back after writing and returns every line of it, line-number prefixed, as the tool result:
// Generate full file contents to show the model the current file state
let fileContext = '\n\nFile contents after write:\n';
for (let i = 0; i < lines.length; i++) {
const lineNumStr = String(i + 1).padStart(4, ' ');
const line = lines[i] || '';
fileContext += `${lineNumStr}: ${line}\n`;
}This is pure duplication. The model just sent that exact content as the tool call arguments. We pay for the same bytes twice in the same conversation, and the second copy is about 6 characters per line more expensive than the first because of the line-number prefix.
There is no cap, so the cost scales linearly with file size.
Impact
Measured on files in this repo, the echo alone costs roughly:
source/app/App.tsx(791 lines): ~8,500 tokenssource/hooks/useAppState.tsx(447 lines): ~4,500 tokenssource/tools/tool-manager.ts(414 lines): ~3,650 tokens
And because tool results stay in the conversation, that cost is re-sent on every subsequent step of the agent loop.
Fix
Replace the echo with a confirmation line:
return `File ${action} successfully (${lineCount} lines).`;This is losslessly removing 100% of the echo. The model cannot learn anything from the echo that it did not already know, since it authored the content.
Worth keeping the read-back itself (it verifies the write succeeded) and just not returning the content.
Notes for a first-time contributor
Small, isolated change in one function. Existing tests are in source/tools/file-ops/write-file.spec.tsx and will need their expected-result assertions updated. Run with pnpm run test:ava source/tools/file-ops/write-file.spec.tsx.
Activity
will-lamerton commentedon Aug 3, 2026
Part of #772.
yashkhatri012 commentedon Aug 8, 2026
I'd like to work on this. Can you assign it to me?
fix: stop echoing full file contents back after write_file