Skip to content

Edit tool corrupts files with Windows-1252 (non-UTF-8) encoding #28521

Closed as not planned

Description

@viniciusgati

Description

The Edit tool reads and writes files assuming UTF-8 text. For codebases encoded in Windows-1252 (common in TOTVS/Protheus ADVPL ecosystem in Brazil), bytes like 0xE7 (ç), 0xE3 (ã), 0xE9 (é) — valid Windows-1252 but invalid UTF-8 sequences — get corrupted on read. On write, the entire file is converted to garbled UTF-8, destroying Portuguese accents and special characters.

Plugins

No response

OpenCode version

1.15.5

Steps to reproduce

  1. Create a file with Windows-1252 encoding containing ç ã é (bytes E7, E3, E9)
  2. Use the Edit tool to change any line
  3. File is rewritten as malformed UTF-8

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Activity

  1. github-actions commented on May 20, 2026

    @github-actions
    Contributor

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

    If your issue is specifically about the Edit tool corrupting Windows-1252 files (rather than a general feature request for multi-encoding support), it may still be worth keeping open as a distinct bug report with a concrete reproduction case.

  2. majick commented on May 22, 2026

    @majick

    Cheap hack to make edit less dangerous: scold the model for calling it until it stops destroying ~70% of the files it touches.

    approx line 70 of opencode-dev/packages/opencode/src/tool/edit.ts. See for detail: #24742 (comment)

  3. aburghacc commented on Jun 24, 2026

    @aburghacc

    same problem here.

    Thought how such encoding issues are handled elsewhere. From java tools we know a runtime setting which determines, which encoding the tool should use when processing text files. Assuming that for most codebases the encoding of text files is determined equally by convention, a setting of which encoding opencode should use could help. In Java the runtime setting is file.encoding="UTF-8"

  4. 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