anomalyco / anomalyco/opencode

apply_patch move to same path deletes the file

Open
#45,310 0 comments 0 reactions 1 assignee View on GitHub

@kitlangton is already working on this.

Since Aug 26, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
Avg merge
7h 2m
Merged PRs (30d)
384

Description

Description

When apply_patch processes a Move directive where the destination path is the same as the source file path, it writes the new content then immediately removes the file — deleting what was just written. The file ends up missing instead of updated.

Steps to reproduce
  1. Have a file same.txt with content old content
  2. Apply a patch that updates the file and moves it to the same path:
*** Begin Patch
*** Update File: same.txt
*** Move to: same.txt
@@
-old content
+new content
*** End Patch
  1. The file is deleted instead of containing new content
Root cause

In the case "move" branch, when movePath === filePath, the sequence is write(movePath, newContent) → remove(filePath), which removes the file just written. Since both paths resolve to the same absolute path, the remove undoes the write.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.