The Problem
Deleting code with built-in tools is arguably the most wasteful operation in AI-assisted coding. To remove content, the agent must first read every line of the target block, then echo all of that content back as the search parameter of a string replacement call, and finally replace it with an empty string.
This is the content-echo problem: the agent spends tokens proportional to the size of the deletion, not to produce anything, but solely to identify what to remove. A 60-line function costs 60 lines of tokens to delete. A 600-line deprecated module costs 600 lines. The token cost scales linearly with the size of the content being removed, and the agent produces nothing useful in return.
What Goes Wrong Without Clean Deletion
Token waste. Every line being deleted must be read, copied into the tool call, and echoed back. For large deletions, this can consume a significant portion of the context window, sometimes enough to prevent the agent from completing other edits in the same turn.
Formatting artifacts. String replacement operations frequently mishandle whitespace and line endings when replacing content with an empty string. Blank lines may be left behind where the deleted content used to be. The line before and after the deletion may be joined incorrectly. These artifacts break the formatting of the surrounding code and require manual cleanup.
Match failures. If even one character in the echoed content doesn't match the actual file (a trailing space, a different line ending, an extra blank line), the entire replacement fails. The agent has spent tokens echoing 60 lines of content, only to have the operation silently fail or match the wrong location.
How Mouse Handles Deletion
Mouse's delete operation takes two numbers: a start line and an end line. That's it.
The agent doesn't read the content being deleted. It doesn't echo it back. It doesn't construct a string replacement call. It specifies the range, and Mouse removes it: cleanly, with no leftover artifacts, no whitespace ambiguity, and no risk of match failure.
The token cost is constant and trivial, whether the deletion is 6 lines or 600.
What This Looks Like in Practice
Removing a deprecated function:
"Delete the
calculateLegacyTaxfunction frombilling.js. Remove it cleanly with no leftover blank lines or formatting artifacts."
The agent identifies the function's line range and issues a delete operation. The diff shows only the removed lines. Nothing else was touched, and no content was echoed.
Cleaning up after a refactor:
"Remove the 3 commented-out blocks in
config.jsthat are marked with// DEPRECATED. Leave the surrounding configuration intact."
The agent uses batch editing to stage three separate delete operations, one per block. All deletions reference the original file's line numbers, so there is no line-drift between operations. The agent reviews the staged result, then commits all three deletions atomically.
Deleting a large test suite:
"Delete the entire
describe('Legacy Integration')block from the test file. It spans about 120 lines."
With built-in tools, this would require echoing 120 lines of test code just to identify them for deletion, a significant context window cost. With Mouse, the agent only needs to identify and specify two numbers: the start and end lines. Or, the agent can make an even more precise edit by identifying the coordinates of the edit, identifying the start and end column positions as well as the line range.
Prompting for Clean Deletion
The key is to communicate that you want a clean removal, not a rewrite:
"Remove the function cleanly. Don't echo or copy the content, just delete the line range."
"Delete these blocks without leaving blank-line artifacts or formatting damage."
With Mouse installed, your assistant will use line-range deletion for removal operations.
Next Steps
Deletion often happens in the context of broader refactoring work that spans multiple files. The next page covers Cross-File Refactors and Repeated Edits.