Skip to content

Edit tool strips all leading whitespace from matched lines (space-indented Python files) #24549

Closed

Description

@saintd

Description

The Edit tool strips ALL leading whitespace from lines in the oldString/newString match, flattening them to column 0. The diff output shows correct indentation, but the actual file on disk has zero indentation on the edited lines. This makes the tool unusable for any edit inside indented blocks (functions, classes, if/try/for blocks, etc.).

Reproduction

  1. Have a Python file with space-indented code inside a try block:
        assert cs.temp_storage_path is not None
        # Updates storage_path to point to the new file
  1. Use Edit tool with oldString/newString that includes the 8-space indentation:
oldString: "        assert cs.temp_storage_path is not None\n        # Updates storage_path to point to the new file"
newString: "        assert cs.temp_storage_path is not None\n        assert cs.content_hash is not None\n        # Updates storage_path to point to the new file"
  1. Tool reports "Edit applied successfully"
  2. File on disk has zero indentation:
assert cs.temp_storage_path is not None
assert cs.content_hash is not None
# Updates storage_path to point to the new file
  1. This breaks Python syntax (try block without except)

Verification

  • cat -An confirms the edited lines have 0 leading spaces instead of 8
  • git diff shows the lines lost their indentation
  • python3 -c "import ast; ast.parse(open('file').read())" confirms syntax error
  • Reverting with git checkout -- restores valid file
  • The same bug occurs across multiple edit attempts and across OpenCode restarts
  • A worker sub-agent (different model) had the exact same issue, confirming it's the tool, not the model

Affected versions

  • 1.14.25
  • 1.14.26

OS

Linux

Related issues

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 27, 2026
  2. saintd commented on Apr 27, 2026

    @saintd
    Author

    Filed in error. The Edit tool preserves indentation correctly — the issue was user error (miscounting leading spaces in the oldString match). Closing.

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

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions