Undo/Redo history broken — changes create new file instead of preserving history #1515

Closed
opened 2026-02-16 17:31:20 -05:00 by yindo · 8 comments
Owner

Originally created by @rauf322 on GitHub (Aug 27, 2025).

Originally assigned to: @thdxr on GitHub.

I’ve run into a problem with undo/redo functionality when OpenCode makes edits to a file.

After OpenCode applies changes, the undo/redo history does not work.
Instead of updating the existing file, it seems to create a new file state each time.

In Neovim, undotree is empty after OpenCode makes modifications, so I cannot step back through previous edits.
This makes it impossible to use normal undo/redo workflows, since there’s no history to revert.

You are free to have a look at my .config file maybe a have some nvim/.zshrc set up which prevents opencode modify files properly

Originally created by @rauf322 on GitHub (Aug 27, 2025). Originally assigned to: @thdxr on GitHub. I’ve run into a problem with undo/redo functionality when OpenCode makes edits to a file. After OpenCode applies changes, the undo/redo history does not work. Instead of updating the existing file, it seems to create a new file state each time. In Neovim, undotree is empty after OpenCode makes modifications, so I cannot step back through previous edits. This makes it impossible to use normal undo/redo workflows, since there’s no history to revert. You are free to have a look at my .config file maybe a have some nvim/.zshrc set up which prevents opencode modify files properly
yindo closed this issue 2026-02-16 17:31:20 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Aug 27, 2025):

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

  • #1048: Similar request for undo functionality when OpenCode makes file changes that can't be easily reverted

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

@github-actions[bot] commented on GitHub (Aug 27, 2025): This issue might be a duplicate of existing issues. Please check: - #1048: Similar request for undo functionality when OpenCode makes file changes that can't be easily reverted Feel free to ignore if none of these address your specific case.
Author
Owner

@rekram1-node commented on GitHub (Aug 27, 2025):

Instead of updating the existing file, it seems to create a new file state each time.

can you elaborate? so if it edits README.md, what happens?

@rekram1-node commented on GitHub (Aug 27, 2025): > Instead of updating the existing file, it seems to create a new file state each time. can you elaborate? so if it edits README.md, what happens?
Author
Owner

@thdxr commented on GitHub (Aug 27, 2025):

if you delete ~/.local/share/opencode/projects//snapshots does it work better?

@thdxr commented on GitHub (Aug 27, 2025): if you delete \~/.local/share/opencode/projects/<project>/snapshots does it work better?
Author
Owner

@rauf322 commented on GitHub (Aug 27, 2025):

I just tried deleting share/opencode and started from scratch, but got the same result.

Here’s how it edits the file: let’s say I have this file,

Myfile.txt

Image

That’s my Neovim tab with the undo tree history. Then I ask OpenCode to add one more line at the end, let’s say "foo foo".
I close Neovim to avoid any buffer conflict.

Image

It did that, and my file was supposed to be edited.

Image

But now the whole undo tree history in Neovim is gone — though that’s not the main point. The main point is: if I ask it to undo the changes,

Image

it seems like it reverts them,

Image

but the content stays the same

@rauf322 commented on GitHub (Aug 27, 2025): I just tried deleting share/opencode and started from scratch, but got the same result. Here’s how it edits the file: let’s say I have this file, Myfile.txt <img width="2170" height="1118" alt="Image" src="https://github.com/user-attachments/assets/16913e1d-773a-4112-b9f5-98f27d61df63" /> That’s my Neovim tab with the undo tree history. Then I ask OpenCode to add one more line at the end, let’s say "foo foo". I close Neovim to avoid any buffer conflict. <img width="2111" height="554" alt="Image" src="https://github.com/user-attachments/assets/0bd94341-8b3a-47d8-b6be-9d75e9bb7266" /> It did that, and my file was supposed to be edited. <img width="2167" height="1113" alt="Image" src="https://github.com/user-attachments/assets/756b6b27-76b0-4f17-b4bb-26d7bf868369" /> But now the whole undo tree history in Neovim is gone — though that’s not the main point. The main point is: if I ask it to undo the changes, <img width="2163" height="944" alt="Image" src="https://github.com/user-attachments/assets/a4578471-f74d-41d9-8d47-d4f567fc5ee4" /> it seems like it reverts them, <img width="2176" height="1120" alt="Image" src="https://github.com/user-attachments/assets/d0e966e1-37a3-41ba-bd0d-859dc6eed3fb" /> but the content stays the same
Author
Owner

@rauf322 commented on GitHub (Aug 27, 2025):

Firstly i assumed that maybe it just delete my previous file and add a new one with new content but by having a look at file creation time it didn't delete it for sure

@rauf322 commented on GitHub (Aug 27, 2025): Firstly i assumed that maybe it just delete my previous file and add a new one with new content but by having a look at file creation time it didn't delete it for sure
Author
Owner

@rauf322 commented on GitHub (Aug 27, 2025):

I just tried to call it with /init in the beginning but no result:

Image Image Image

no changes happened

@rauf322 commented on GitHub (Aug 27, 2025): I just tried to call it with /init in the beginning but no result: <img width="2154" height="1111" alt="Image" src="https://github.com/user-attachments/assets/8636e97a-d040-4dbb-9164-560ecb0b1865" /> <img width="2158" height="1114" alt="Image" src="https://github.com/user-attachments/assets/236e7dd7-ca6c-4e28-be05-669337a5c4ec" /> <img width="2173" height="1116" alt="Image" src="https://github.com/user-attachments/assets/b9c7397b-48df-4aef-9203-61757a9df2be" /> no changes happened
Author
Owner

@rekram1-node commented on GitHub (Aug 27, 2025):

are you in a git project

@rekram1-node commented on GitHub (Aug 27, 2025): are you in a git project
Author
Owner

@rauf322 commented on GitHub (Aug 27, 2025):

In a project with Git it works, though it still clears the whole Neovim undo tree — but that’s not a big deal. I didn’t know having Git in the project folder was such a big deal for undo and redo. Thank you!

@rauf322 commented on GitHub (Aug 27, 2025): In a project with Git it works, though it still clears the whole Neovim undo tree — but that’s not a big deal. I didn’t know having Git in the project folder was such a big deal for undo and redo. Thank you!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#1515