anomalyco / anomalyco/opencode
apply_patch move to same path deletes the file
Open
@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
- Have a file
same.txtwith contentold content - 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
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.