Skip to content

Edit tool messes with indentation (but this is not shown in the diff) #14612

Closed as not planned

Description

@joeldrapper

Description

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

  1. Have a file that uses single-tab indentation
  2. Ask agent to edit the file — any edit will do
  3. The diff will show the correct edit but the file will actually have had all \t replaced with \t\t.

I was editing a Ruby file with ruby-lap enabled.

Screenshot and/or share link

No response

Operating System

macOS

Terminal

Zed

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Feb 21, 2026
  2. ariane-emory commented on Feb 23, 2026

    @ariane-emory
    Contributor

    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.

  3. 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
  4. joeldrapper commented on Feb 23, 2026

    @joeldrapper
    Author

    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.

  5. tellnes commented on Mar 9, 2026

    @tellnes

    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.

    Environment: opencode 1.2.20, macOS, shell script files

  6. MartinEmrich commented on Apr 1, 2026

    @MartinEmrich

    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.

  7. joeldrapper commented on Apr 1, 2026

    @joeldrapper
    Author

    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.

  8. MartinEmrich commented on Apr 1, 2026

    @MartinEmrich

    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.

  9. joeldrapper commented on Apr 7, 2026

    @joeldrapper
    Author

    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.

  10. Nowaker commented on Apr 9, 2026

    @Nowaker

    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.

    Image
  11. MartinEmrich commented on Apr 9, 2026

    @MartinEmrich

    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.

  12. assigned and unassigned on Apr 26, 2026
  13. removed
    bugSomething isn't working
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  14. majick commented on May 23, 2026

    @majick

    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)

  15. mbudisic commented on Jun 24, 2026

    @mbudisic

    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.
  16. github-actions commented on Aug 24, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions