Skip to content

On file edit it is also formattedΒ #8387

Closed as not planned
Closed as not planned

Description

@Adar-Dagan

Description

When editing a cpp file then the file is also completely formatted making the edit very dirty if the source file isn't already formatted correctly.

Plugins

Non

OpenCode version

Latest

Steps to reproduce

  1. Get an unformated cpp file, I use files in the llvm project
  2. make the llm do a small edit in that file
  3. see there is a large diff for that file

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Activity

  1. github-actions commented on Jan 14, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Feel free to ignore if none of these address your specific case.

  2. cravenceiling commented on Jan 16, 2026

    @cravenceiling
    Contributor

    It's probable because of the built-in clang-format formatter (opencode.ai/docs/formatters), do you have a .clang-format config file? Or try disabling it:

    {
      "$schema": "https://opencode.ai/config.json",
      "formatter": {
        "clang-format": {
          "disabled": true
        }
      },
    }
  3. Adar-Dagan commented on Jan 19, 2026

    @Adar-Dagan
    Author

    I do have a .clang-format but it is almost empty, I work on the llvm project.
    I would prefer not to completely disable the formatter, I do want it but I want it to change only the lines that where edited. I see the bot linked to commit that should do this, is there a bug?

  4. jasonfharris commented on Jan 20, 2026

    @jasonfharris

    The same "feature" It totally bit me and it took me quite a long time after trying all sorts of prompts like:

    Make a minimal, surgical change. Do not reformat. Do not adjust spacing, alignment, or line wrapping anywhere else.
    Only change the exact lines required for the functional change. If your edit would touch any other line, don't do it.

    But then I figured out that it was always actually running clang format on the file.

  5. mikaelj commented on Feb 3, 2026

    @mikaelj

    horribly annoying - it's clearly a bug.

  6. prilosac commented on Feb 19, 2026

    @prilosac

    I agree that this behavior feels like a bug. But, I understand the desire to make the out of the box experience as good as possible.

    Perhaps there's a middle ground where opencode looks for uv/ruff/other formatter definitions in pyproject.toml (in the case of python, other appropriate places for other languages), only running the appropriate formatter if it's already configured for the project?

  7. nyh commented on Mar 11, 2026

    @nyh

    I agree that this behavior feels like a bug. But, I understand the desire to make the out of the box experience as good as possible.

    The thing is, I can't think of any project where this behavior is desirable. Sure, if opencode is writing new code, it should format it according to the formatting rules and/or the code it sees around in the same file. But I can't think of any case where I want opencode, after adding a few lines in the middle of the source file, to also move around whitespace in 20 other lines in the same file. Nobody ever wants that...

  8. prilosac commented on Mar 18, 2026

    @prilosac

    I agree that, generally, it would obviously be a sane default to only format the code OpenCode writes. But, I can easily imagine a workflow where I want OpenCode apply the same formatting-on-write as my editor.

    To me, a large part of this issue is that the UI for this is super misleading, because it'll show you a simple few line change, and it's not until you accept the change that it formats the file and the diff you actually get is very different from the one you accepted.

  9. removed
    bugSomething isn't working
    on May 3, 2026
  10. github-actions commented on Jul 6, 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