The edit tool, implemented in packages/coding-agent/src/core/tools/edit.ts, edits a single file using exact text replacement, routing all file mutations through withFileMutationQueue (from file-mutation-queue.js) to serialize concurrent writes to the same file.[1] The EditOperations interface allows pluggable file I/O — with readFile, writeFile, and access methods — making it possible to delegate editing to remote systems such as SSH.[1] The edit tool renders with renderShell: 'self', meaning it manages its own shell rendering instead of delegating to a container.[1]
prepareEditArguments normalizes tool input before validation: models that send edits as a JSON string instead of an array — specifically noted for Opus 4.6 and GLM-5.1 — have their input parsed and converted to an array.[1] prepareEditArguments also handles a legacy single-edit form where oldText and newText appear as top-level keys, converting them into an edits array entry for backward compatibility.[1] Similarly, the path field accepts file_path as a legacy alias in render helpers, supporting older model outputs that used the old field name.[1]
validateEditInput throws if edits is not a non-empty array, enforcing at least one replacement per call.[1] Each edit's oldText must be unique in the file and non-overlapping with other edits in the same call; edits that affect the same block or nearby lines must be merged into one, and large unchanged regions must not be included merely to connect distant changes.[1]
EditToolDetails carries a unified diff string (diff) and an optional firstChangedLine — the line number of the first change in the new file — for editor navigation.[1] The Ctrl+J keybinding — registered in keybindings.ts, wired through runner.ts, and handled in interactive-mode.ts — toggles the inline diff view for edits independently of the tool-output collapse state. The edit tool's interactive TUI rendering is split across edit-summary.ts, tool-execution.ts, and conversation-components.ts; edit-summary.ts provides an always-visible edit-summary component, replacing the previous behavior of burying diffs inside collapsible tool output.
Sources