opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Session Changes / Modified Files show changes from origin/main

Open nathanchapman opened this issue 10 months ago • 10 comments

Description

"Session Changes" (in OpenCode Desktop) / "Modified Files" (in the TUI) is showing a bunch of irrelevant changes that neither I nor OpenCode made. I believe it's diffing against origin/main and treating the diff as if there are changes, rather than looking at the base branch

I'm using graphite, so that may be contributing here. These additional changes show up regardless of which branch I checkout in the stack. I can't provide screenshots yet, as this is happening on a private repo, but I'll work on getting a repro with screenshots that I can share

Plugins

No response

OpenCode version

1.1.11

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

macOS 15.7.3

Terminal

TUI + desktop app

nathanchapman avatar Jan 10 '26 02:01 nathanchapman

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

  • #6903: opencode report internal files as modified files in the session
  • #5049: auto update shows the updated file in "Modified Files" section on the right sidebar

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

github-actions[bot] avatar Jan 10 '26 02:01 github-actions[bot]

Follow-up Root Cause Analysis from OpenCode:

After digging through the codebase, I believe I've identified the root cause. This is related to rebasing/restacking rather than just branch switching.

How the Snapshot System Works

OpenCode maintains a separate git repository for snapshots at ~/.local/share/opencode/snapshot/<project-id>/. The project-id is derived from the root commit hash, so all branches in a repo share the same snapshot directory.

When a session starts, [`Snapshot.track()`](https://github.com/anomalyco/opencode/blob/dev/packages/opencode/src/snapshot/index.ts#L12-L35) runs git add . and git write-tree to create a tree object representing the current worktree state. Session diffs are computed by comparing the step-start snapshot to the step-finish snapshot.

The Bug

The problem occurs when you rebase (or gt restack with Graphite):

You start a session before rebasing → OpenCode creates snapshot S1
You rebase your stack, pulling in upstream changes from main
You continue the session (or start a new one) → OpenCode creates snapshot S2
The diff S1 → S2 now includes all changes from main that came in via rebase
The snapshot system has no awareness that a rebase occurred - it just sees "file content changed" and reports those as session changes. This explains why the changes appear to be from other people's commits on main.

Potential Fixes

Detect HEAD changes: Track the HEAD commit when creating snapshots. If HEAD changes unexpectedly (rebase, checkout, etc.), invalidate stale snapshots
Fresh snapshots per-session: Don't rely on persistent snapshot state across sessions
Branch+commit aware snapshots: Include branch name and/or commit hash in the snapshot path

nathanchapman avatar Jan 10 '26 03:01 nathanchapman

I'm experiencing a related issue with .NET projects. When the agent compiles the project (e.g., runs dotnet build), all files in bin/ and obj/ folders appear as "modified" in the Session Changes / Review panel, even though they are properly listed in .gitignore:

This pollutes the changes view with dozens of DLLs, PDBs, and other build artifacts that are completely irrelevant to the actual code changes made by the agent.

Expected behavior: Files matching .gitignore patterns should not appear in the session diff / modified files list.

alexandrereyes avatar Jan 28 '26 12:01 alexandrereyes

I could take a shot at fixing this @adamdotdevin.

judepereira avatar Feb 23 '26 14:02 judepereira

My "Modified Files" panel also gets cluttered with build-artifacts and files that are irrelevant for the context.

I tried adding an ignore-pattern to the watcher config, but it does not seem to have any effect:

~/.config/opencode/opencode.json and projectdir/opencode.json contain this:

{
  "$schema": "https://opencode.ai/config.json",
  "watcher": {
    "ignore": [
      ".pio/**",
      ".beads/**",
      ".git/**"
    ]
  }
}

Opencode 1.2.15 on Linux in a Proxmox container.

There is also a .gitignore with similar ignores and the repo itself is not affected, so "Modified Files" also does not reflect git status.

speters avatar Mar 04 '26 19:03 speters

I personally don't want any file change tracking beyond source control. Just seeing the unstaged files and having the interface for basic git operations is how I want to see diffs and commit changes.

archonic avatar Apr 02 '26 22:04 archonic

I also encountered this issue with a simple git pull to pull latest changes (same branch) while on an active session.

albertilagan avatar Apr 04 '26 12:04 albertilagan

I am experiencing the exact same issue on Opencode Desktop (1.14.50). When I manually edit files in my codebase during an Opencode session, the agent lists them as modified files at the bottom of the conversation. The agent is currently in "plan mode" and hasn't touched these files at all, they are changes I made myself that are completely unrelated to the current session. This behavior makes the session history very confusing.

bastienlimbour avatar May 14 '26 22:05 bastienlimbour

To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

github-actions[bot] avatar Jul 14 '26 03:07 github-actions[bot]

Err... Okay then. 👋

nathanchapman avatar Jul 14 '26 03:07 nathanchapman