anomalyco / anomalyco/opencode

Bug: `/undo` reports success but does not revert files in non-Git projects

Open
#38,672 1 comment 0 reactions 1 assignee View on GitHub

@jlongster is already working on this.

Since Jul 24, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description
Bug Description

When using OpenCode in a non-Git project directory, running /undo or clicking the undo button shows "1 message reverted" but the actual file changes are NOT reverted at all.

Steps to Reproduce
  1. Start OpenCode in a non-Git directory (no git init was run)
  2. Ask OpenCode to modify a file (e.g., edit or write content)
  3. Run /undo or click the undo button
  4. Observe that it shows a success message, but the file content remains unchanged
Root Cause

OpenCode's undo mechanism relies on Git snapshots for file change tracking. In snapshot/index.ts, when state.vcs !== "git", the snapshot system is silently disabled — track() returns undefined and revert()/restore() become no-ops. However, the higher-level undo flow does not check this state and still reports "success" to the user.

Environment
  • OpenCode version: 1.18.4
  • OS: Windows 11 (Build 26200)
  • PowerShell: 5.1.26100.8115
Expected Behavior

When the project is not a Git repository, the undo action should clearly inform the user, for example: "Cannot undo file changes: the current project is not a Git repository. Please use this feature in a Git project."

Additional Suggestion (Feature Request)

Projects without Git actually have a greater need for undo functionality — users in Git projects can always manually recover via git checkout or git restore, but non-Git projects have no way to restore once files are modified. Consider implementing a file-copy or content-hash-based snapshot mechanism for non-Git environments in the future.

Plugins

No response

OpenCode version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

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.