Skip to content

[BUG]: Edit tool applies formatter to entire file, causing unintended changes outside the edited range #14450

@DRBragg

Description

@DRBragg

Bug Description

The Edit tool's post-edit formatting step reformats the entire file, not just the edited range. This causes cosmetic changes (removed blank lines, indentation adjustments) on lines the user never intended to modify, producing noisy diffs that require manual cleanup.

Steps to Reproduce

  1. Open a project with a formatter configured (e.g., Prettier detected automatically, or ruby-lsp in LSP config)
  2. Use the Edit tool to make a single-line change in an ERB, HTML, or JS file
  3. Run git diff on the file

Expected: Only the targeted line changes.
Actual: Additional blank lines are removed, indentation is adjusted, and other cosmetic changes appear on unrelated lines.

Concrete Example

Editing a single turbo_stream_from line in an ERB file:

oldString: '  <%= turbo_stream_from "chat_list_#{Current.user.id}" %>'
newString: '  <%= turbo_stream_from "chat_list_#{Current.user.model_name.param_key}_#{Current.user.id}" %>'

Resulting diff shows 5 unrelated changes in addition to the intended one:

 <%# locals(conversations:, pagy:) %>
-
 <%= content_for(:title_tag, ": Chat") %>
-
 <%= render(Podia::UI::CardComponent.new(
...
   <% end %>
-
-  <%= turbo_stream_from "chat_list_#{Current.user.id}" %>
+  <%= turbo_stream_from "chat_list_#{Current.user.model_name.param_key}_#{Current.user.id}" %>
...
-            <%= render CMS::Chat::ItemComponent.with_collection(conversations) %>
+          <%= render CMS::Chat::ItemComponent.with_collection(conversations) %>

Three blank lines were removed and one line's indentation was changed — none of which were part of the oldString or newString.

The same edit performed with sed produces a clean single-line diff.

Impact

This is a significant workflow disruption in codebases with style conventions. Every Edit tool change to a template or JS file requires:

  1. Running git diff to check for damage
  2. git checkout to restore the file
  3. Re-doing the edit with sed or manual editing

This happens consistently — not occasionally — on every Edit tool invocation on files where a formatter is detected.

Workaround

Using sed for surgical replacements instead of the Edit tool, or setting "formatter": false in opencode.json (which disables all formatting, including on genuinely new code).

Relation to #4603

Issue #4603 proposed range-based formatting as a feature. This bug report is the flip side: the current whole-file formatting behavior is a bug that produces incorrect diffs. PR #4604 would resolve this by restricting formatting to the edited range only.

Environment

  • OpenCode version: 1.2.6
  • File types affected: .erb, .html, .js (likely any file with a detected formatter)
  • OS: macOS Tahoe 26.3

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions