You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Edit tool messes with indentation (but this is not shown in the diff) #14612
It looks like whenever the agent uses the edit tool, it replaces all tab indentation with two tabs. I was able to reproduce this with a simple one-line edit. The diff showed the correct edit but all tabs in the file had been replaced with two tabs.
Plugins
no
OpenCode version
1.2.10
Steps to reproduce
Have a file that uses single-tab indentation
Ask agent to edit the file — any edit will do
The diff will show the correct edit but the file will actually have had all \t replaced with \t\t.
This is likely due to a formatter, as those take effect after tools like the edit tool.
Personally, I prefer to turn off all formatters by adding this line to my configuration file:
"formatter": false,
I believe that there is also a way to turn off specific formatters for specific languages as well, I'm sure that you can find it in the documentation if you take a look.
changed the title [-]Edit tool messes with indentation (but this is now shown in the diff)[/-][+]Edit tool messes with indentation (but this is not shown in the diff)[/+]on Feb 23, 2026
I don't think it could be the formatter. The only formatter OpenCode could reasonably by using for Ruby is Rubocop and that's what I use to correct the mess.
This also affects space-indented files, not just tab-indented ones.
Reproduction: a bash script using 4-space indentation. Asking for a single-word change on one line causes the edit tool to reformat the entire file (case patterns, continuation lines, etc.).
Adding an .editorconfig with the correct indent_style and indent_size reduces the damage (prevents changing indent size) but the tool still reformats unrelated lines throughout the file.
Confirmed... I blamed poor Qwen3.5 27B multiple times, until it by itself found out that the "edit" tool messed up the formatting, and switched to sed toolcalls. Thanks for the hint to disable the formatters!
I am sure devs meant well with calling language specific formatters after edit, but this seems to conflict with code style instructions in AGENTS.md. A session with any code-style hints in AGENTS.md should prefer these over default values of whatever formatter found and used.
I think what is happening is OpenCode is generating code with space based indentation and that triggers a bug in Rubocop when it tries to convert it to tabs.
For me it was a shell script, and shfmt by default converted my 2-space-indentation to tabs. After disabling formatting, the model-generated code matched the surrounding style.
I am not able to reproduce this now, edits seem to work fine with tabs and formatting. Not sure if it’s a new version of OpenCode or Ruocop or something else.
OpenCode has been consistently messing up my shell script indentation from 2 spaces to 3 spaces. Citing OpenCode itself:
The Write tool is converting my spaces to tabs.
So it ends up using sed to apply the changes without messing the indentation.
I don't use any formatters, have no .editorconfig file, or whatnot. It's just pure OpenCode wanting my scripts formatted that way. Not even the AI. Write tool messes it up.
Yup, today it (Sonnet 4.6, so no slouch) randomly decided to reformat a few lines of a Python script from 4 to 5 spaces, and, confronted, claims the edit tool has done this (but was able to correct it). So just disabling the formatter via configuration is not ideal either.
This was a consistent problem for me, requiring multiple edit passes before the file was partially fixed. I worked around it with a cheap hack: disabling the edit tool and scolding the model for trying it. Details as to how are in #24742 (comment)
This issue persists into OpenCode 1.17.9, working with nemotron-3-super:120b on Python code. Agent would be stuck for minutes trying and trying to fix indentation problems. In many cases, I had to manually fix the offending blocks.
Following the suggestion above, I was not willing to intervene into edit.ts so ended up disabling the tool in local opencode.json
"permission": {
"edit": "deny",
},
and adding the following directive to AGENTS.md to try to shortcut its attempts at using edit. The agent is more successful at working through code changes (although it still occasionally attempts to use edit - it realizes the tool is disabled and redirects, but this burns time and tokens).
- NEVER use `edit` tool because it breaks indentation. It is disabled. Instead use PowerShell Get-Content and Set-Content.
Activity
ariane-emory commentedon Feb 23, 2026
This is likely due to a formatter, as those take effect after tools like the
edittool.Personally, I prefer to turn off all formatters by adding this line to my configuration file:
I believe that there is also a way to turn off specific formatters for specific languages as well, I'm sure that you can find it in the documentation if you take a look.
[-]Edit tool messes with indentation (but this is now shown in the diff)[/-][+]Edit tool messes with indentation (but this is not shown in the diff)[/+]joeldrapper commentedon Feb 23, 2026
I don't think it could be the formatter. The only formatter OpenCode could reasonably by using for Ruby is Rubocop and that's what I use to correct the mess.
Will try to figure out if it's only Ruby today.
tellnes commentedon Mar 9, 2026
This also affects space-indented files, not just tab-indented ones.
Reproduction: a bash script using 4-space indentation. Asking for a single-word change on one line causes the edit tool to reformat the entire file (case patterns, continuation lines, etc.).
Adding an
.editorconfigwith the correctindent_styleandindent_sizereduces the damage (prevents changing indent size) but the tool still reformats unrelated lines throughout the file.Environment: opencode 1.2.20, macOS, shell script files
MartinEmrich commentedon Apr 1, 2026
Confirmed... I blamed poor Qwen3.5 27B multiple times, until it by itself found out that the "edit" tool messed up the formatting, and switched to sed toolcalls. Thanks for the hint to disable the formatters!
I am sure devs meant well with calling language specific formatters after edit, but this seems to conflict with code style instructions in AGENTS.md. A session with any code-style hints in AGENTS.md should prefer these over default values of whatever formatter found and used.
joeldrapper commentedon Apr 1, 2026
I think what is happening is OpenCode is generating code with space based indentation and that triggers a bug in Rubocop when it tries to convert it to tabs.
MartinEmrich commentedon Apr 1, 2026
For me it was a shell script, and shfmt by default converted my 2-space-indentation to tabs. After disabling formatting, the model-generated code matched the surrounding style.
joeldrapper commentedon Apr 7, 2026
I am not able to reproduce this now, edits seem to work fine with tabs and formatting. Not sure if it’s a new version of OpenCode or Ruocop or something else.
Nowaker commentedon Apr 9, 2026
OpenCode has been consistently messing up my shell script indentation from 2 spaces to 3 spaces. Citing OpenCode itself:
So it ends up using
sedto apply the changes without messing the indentation.I don't use any formatters, have no
.editorconfigfile, or whatnot. It's just pure OpenCode wanting my scripts formatted that way. Not even the AI. Write tool messes it up.MartinEmrich commentedon Apr 9, 2026
Yup, today it (Sonnet 4.6, so no slouch) randomly decided to reformat a few lines of a Python script from 4 to 5 spaces, and, confronted, claims the edit tool has done this (but was able to correct it). So just disabling the formatter via configuration is not ideal either.
majick commentedon May 23, 2026
This was a consistent problem for me, requiring multiple edit passes before the file was partially fixed. I worked around it with a cheap hack: disabling the
edittool and scolding the model for trying it. Details as to how are in #24742 (comment)mbudisic commentedon Jun 24, 2026
This issue persists into OpenCode 1.17.9, working with nemotron-3-super:120b on Python code. Agent would be stuck for minutes trying and trying to fix indentation problems. In many cases, I had to manually fix the offending blocks.
Following the suggestion above, I was not willing to intervene into
edit.tsso ended up disabling the tool in localopencode.jsonand adding the following directive to
AGENTS.mdto try to shortcut its attempts at usingedit. The agent is more successful at working through code changes (although it still occasionally attempts to useedit- it realizes the tool is disabled and redirects, but this burns time and tokens).github-actions commentedon Aug 24, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.