Claude Code's Edit Tool Wastes Your Most Expensive Tokens. Here's a Fix.
You’re deep into a Claude Code session. The agent is humming along, editing files, and making progress.
And quietly bleeding money on every single edit.
Here’s why. The built-in Edit tool uses string matching. To change five lines of code, the model has to echo back those exact five lines as old_string, then provide the replacement as new_string. That echoed text is pure overhead: it’s already in the file. The model is spending output tokens, the most expensive token class, just to point at code and say “I mean this part.”
For a typical 15-line edit, that’s ~200 wasted output tokens. Do a few dozen edits in a session (not unusual for any real feature work) and you’re burning serious money on text the model already knows is there.
It gets worse when something goes wrong. If the file changed since the agent last read it (maybe you saved in your editor, maybe another tool touched it) the string match fails. The model hallucinating a character or two has the same effect. Either way, the edit errors out, the agent re-reads the whole file to get back in sync, and you’ve just paid for all that content again. In longer sessions, these re-reads compound.
I got tired of watching this happen, so I built trueline-mcp to fix both problems.
The token tax on every edit
Let’s look at what’s actually happening. Here’s the built-in Edit under the hood. The model has to echo the old text just to locate the change:
{
"file_path": "src/server.ts",
"old_string": "export function handleRequest(req: Request) {\n const body = await req.json();\n validate(body);\n return process(body);\n}",
"new_string": "export function handleRequest(req: Request) {\n const body = await req.json();\n const parsed = schema.parse(body);\n return process(parsed);\n}"
}
See all that duplicated text? trueline replaces it with a compact line-range reference:
{
"file_path": "src/server.ts",
"edits": [{
"checksum": "1-50:a3b1c2d4",
"range": "12:kf..16:qz",
"content": "export function handleRequest(req: Request) {\n const body = await req.json();\n const parsed = schema.parse(body);\n return process(parsed);\n}"
}]
}
The model never echoes the old text. It says which lines to replace, proves it read them correctly, and provides the new content. ~200 fewer output tokens per edit, on the most expensive token class.
Oh, and there’s a fun gotcha with the built-in tool: if old_string appears more than once in the file, the edit fails. The model has to pad in extra context lines until the match is unique — yet more wasted tokens. trueline addresses lines directly. No ambiguity, no padding.
Every edit is verified against reality
The same mechanism that saves tokens is what makes edits reliable. When the agent reads a file through trueline, every line comes back tagged with a short hash:
1:bx|import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2:dd|
3:ew|const server = new Server({ name: "trueline-mcp", version: "0.1.0" });
checksum: 1-3:8a64a3f7
When the agent wants to edit, it echoes those hashes back. If the file changed since the read the hashes won’t match and the edit is rejected before it touches disk. No silent corruption, no guessing, no “why does this file look wrong?” twenty minutes later.
This is the part that kills the re-read cycle. Instead of the agent discovering a stale match, failing, re-reading the whole file, and trying again, trueline catches the mismatch immediately and tells the agent exactly what’s wrong. One targeted re-read of the changed range, and it’s back on track.
Multiple edits to the same file go through in a single call too, each independently verified. The built-in Edit handles one replacement per call, so trueline cuts tool-call overhead for multi-site changes.
Three tools, zero config
trueline_read— reads a file, tags each line with a hash, returns a range checksum.trueline_edit— verifies hashes, then applies the edit atomically. Supports multiple edits per call.trueline_diff— same verification, but outputs a unified diff without touching disk. Good for previewing changes before committing to them.
Once installed, a SessionStart hook nudges the agent toward the trueline tools, and a PreToolUse hook blocks the built-in Edit tool so it can’t fall back to string matching. You don’t have to think about it—the agent uses verified edits from the start, automatically.
Security-wise, trueline enforces the same deny patterns Claude Code uses (.env, *.key, etc.)
Try it
/plugin marketplace add rjkaes/trueline-mcp
/plugin install trueline-mcp@trueline-mcp
Two commands. Your next Claude Code session will use hash-verified edits automatically. No configuration, no changes to your workflow. Fewer wasted tokens and edits that don’t silently corrupt your code.
Prior art
Can Boluk described the underlying problem (AI agents working against stale state) and Seth Livingston built a hash-line edit tool for VS Code. trueline brings the same idea to Claude Code as an MCP plugin.
The code is on GitHub: rjkaes/trueline-mcp. Apache-2.0, TypeScript, built with Bun.


