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
- Open a project with a formatter configured (e.g., Prettier detected automatically, or
ruby-lsp in LSP config)
- Use the Edit tool to make a single-line change in an ERB, HTML, or JS file
- 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:
- Running
git diff to check for damage
git checkout to restore the file
- 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
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
ruby-lspin LSP config)git diffon the fileExpected: 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_fromline in an ERB file:Resulting diff shows 5 unrelated changes in addition to the intended one:
Three blank lines were removed and one line's indentation was changed — none of which were part of the
oldStringornewString.The same edit performed with
sedproduces 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:
git diffto check for damagegit checkoutto restore the filesedor manual editingThis happens consistently — not occasionally — on every Edit tool invocation on files where a formatter is detected.
Workaround
Using
sedfor surgical replacements instead of the Edit tool, or setting"formatter": falseinopencode.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
.erb,.html,.js(likely any file with a detected formatter)