opencode icon indicating copy to clipboard operation
opencode copied to clipboard

`/undo` command only rolls back AI conversation message, not the associated file changes

Open sdivens opened this issue 2 weeks ago • 10 comments

Description

In OpenCode, when using the /undo command to revert an AI-generated change (e.g., after the AI modified code or wrote new code), only the conversation message in the chat is rolled back, but the actual file changes made by the AI remain in the workspace. This results in a mismatch between the conversation history and the actual code state.

OpenCode version

1.0.152

Steps to reproduce

  1. Start a conversation with the AI in OpenCode.
  2. Ask the AI to make changes to a file (e.g., "add a function to main.js").
  3. Let the AI apply the changes to your workspace.
  4. Type /undo in the chat to undo the last AI action.
  5. Observe: the conversation message disappears, but the file changes remain in your project.

Screenshot and/or share link

Image Image Image

Operating System

macos 15.7.1

Terminal

item2

sdivens avatar Dec 13 '25 08:12 sdivens

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

  • #4704: /undo and /timeline undo does not revert file edits - directly related issue reporting the same problem
  • #4548: /undo does not update Modified Files list - related issue where undo doesn't properly revert file changes
  • #3901: Undo command doesn't allow editing reverted message like keyboard shortcut - related to undo command behavior issues

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

github-actions[bot] avatar Dec 13 '25 08:12 github-actions[bot]

Hi. Yes, I got same behavior with opencode 1.0.150.

Cyrille37 avatar Dec 13 '25 09:12 Cyrille37

I've tried this in the 1.0.152 I can't seem to replicate it, yeah the undo doesn't affect the modified files list like in #4548

nalin-singh avatar Dec 13 '25 16:12 nalin-singh

are you working in a git repo? It will only undo changes in git repos

rekram1-node avatar Dec 13 '25 16:12 rekram1-node

Hi

are you working in a git repo? It will only undo changes in git repos

Great. But this is missing in doc https://opencode.ai/docs/#undo-changes

Regards & cheers and many thanks for sharing this so great tool 💌

Cyrille37 avatar Dec 13 '25 17:12 Cyrille37

ill doc it

rekram1-node avatar Dec 13 '25 17:12 rekram1-node

are you working in a git repo? It will only undo changes in git repos

Yes, I am currently running within a Git repository. You can refer to the screenshot I included in the issue for confirmation.

sdivens avatar Dec 14 '25 02:12 sdivens

does this repo have commits in it?

does this issue happen consistently?

rekram1-node avatar Dec 14 '25 02:12 rekram1-node

does this repo have commits in it?

does this issue happen consistently?

Yes, the code repository is connected to a remote repository. I have tried executing /undo in several states—after unstaging, staging, and committing—with the same code. In all these cases, it never rolls back my code; it only rolls back the AI session. This issue does not occur 100% of the time.

sdivens avatar Dec 14 '25 09:12 sdivens

I experienced something else - using /timeline (so it might be different, I am not sure) it seems to only revert the agent's that were made with the file write tools? While I get why that might be (restoring a snapshot like CC does might lead to the user's changes being reverted) this causes issues with side effects such as the agent running bun add <package>

gergesh avatar Dec 15 '25 20:12 gergesh