[Bug] "Modified Files" panel does not clear after git commit #8370

Open
opened 2026-02-16 18:09:47 -05:00 by yindo · 2 comments
Owner

Originally created by @taetaetae on GitHub (Feb 2, 2026).

Originally assigned to: @rekram1-node on GitHub.

Description

After committing files with git commit, the "Modified Files" panel in the sidebar still shows those files as modified. Users expect committed files to be removed from this list.

Steps to Reproduce

  1. Start OpenCode in a git repository
  2. Make changes to files using OpenCode (AI edits)
  3. Observe "Modified Files" panel shows the changed files
  4. Run git add . && git commit -m "commit message" (either via OpenCode bash tool or external terminal)
  5. Observe "Modified Files" panel still shows the same files

Expected Behavior

Files that have been committed should be removed from the "Modified Files" list, since they are no longer "modified" from git's perspective.

Actual Behavior

Committed files remain in the "Modified Files" list until the session ends or OpenCode is restarted.

Root Cause Analysis

After investigating the codebase, I found that:

  1. session_diff is computed from OpenCode's internal snapshot system, not the user's git repository

    • Internal snapshots are stored in ~/.local/share/opencode/snapshot/{project-id}/
    • SessionSummary.summarize() computes diff between step-start and step-finish snapshot hashes
  2. No git commit event detection exists

    • FileWatcher only watches .git/HEAD for branch changes (packages/opencode/src/file/watcher.ts)
    • Vcs namespace only handles BranchUpdated events (packages/opencode/src/project/vcs.ts)
    • There is no handler that detects when a git commit happens
  3. session_diff is never refreshed after external git operations

    • Once computed, session_diff persists until session ends
    • User's git commit does not trigger any recalculation

Relevant Code

packages/opencode/src/session/summary.ts:

async function summarizeSession(input: { sessionID: string; messages: MessageV2.WithParts[] }) {
  const diffs = await computeDiff({ messages: input.messages })
  // ...
  await Storage.write(["session_diff", input.sessionID], diffs)
  Bus.publish(Session.Event.Diff, { sessionID: input.sessionID, diff: diffs })
}

packages/opencode/src/project/vcs.ts:

// Only watches for branch changes, not commits
const unsubscribe = Bus.subscribe(FileWatcher.Event.Updated, async (evt) => {
  if (evt.properties.file.endsWith("HEAD")) return
  // ... only handles branch changes
})

Proposed Solution

Option A: Detect git commit and filter session_diff

  1. Watch for .git/index or .git/refs/heads/* changes in FileWatcher
  2. On commit detection, filter session_diff to only include files that are still uncommitted
  3. Publish updated diff to UI

Option B: Periodically refresh session_diff

  1. After bash tool executions that might be git commands, refresh session_diff
  2. Compare against current git diff --name-only HEAD to filter committed files

Environment

  • OS: macOS
  • OpenCode version: latest from dev branch
  • Commit: 7b3c82d95c10e7ec364d8b970209dadfdb43e4dc

Related Issues

  • #11802 - Related issue about session_diff being worktree-global (different but related problem)
Originally created by @taetaetae on GitHub (Feb 2, 2026). Originally assigned to: @rekram1-node on GitHub. ## Description After committing files with `git commit`, the "Modified Files" panel in the sidebar still shows those files as modified. Users expect committed files to be removed from this list. ## Steps to Reproduce 1. Start OpenCode in a git repository 2. Make changes to files using OpenCode (AI edits) 3. Observe "Modified Files" panel shows the changed files 4. Run `git add . && git commit -m "commit message"` (either via OpenCode bash tool or external terminal) 5. Observe "Modified Files" panel **still shows the same files** ## Expected Behavior Files that have been committed should be removed from the "Modified Files" list, since they are no longer "modified" from git's perspective. ## Actual Behavior Committed files remain in the "Modified Files" list until the session ends or OpenCode is restarted. ## Root Cause Analysis After investigating the codebase, I found that: 1. **`session_diff` is computed from OpenCode's internal snapshot system**, not the user's git repository - Internal snapshots are stored in `~/.local/share/opencode/snapshot/{project-id}/` - `SessionSummary.summarize()` computes diff between `step-start` and `step-finish` snapshot hashes 2. **No git commit event detection exists** - `FileWatcher` only watches `.git/HEAD` for branch changes (`packages/opencode/src/file/watcher.ts`) - `Vcs` namespace only handles `BranchUpdated` events (`packages/opencode/src/project/vcs.ts`) - There is no handler that detects when a `git commit` happens 3. **`session_diff` is never refreshed after external git operations** - Once computed, `session_diff` persists until session ends - User's `git commit` does not trigger any recalculation ### Relevant Code **`packages/opencode/src/session/summary.ts`**: ```typescript async function summarizeSession(input: { sessionID: string; messages: MessageV2.WithParts[] }) { const diffs = await computeDiff({ messages: input.messages }) // ... await Storage.write(["session_diff", input.sessionID], diffs) Bus.publish(Session.Event.Diff, { sessionID: input.sessionID, diff: diffs }) } ``` **`packages/opencode/src/project/vcs.ts`**: ```typescript // Only watches for branch changes, not commits const unsubscribe = Bus.subscribe(FileWatcher.Event.Updated, async (evt) => { if (evt.properties.file.endsWith("HEAD")) return // ... only handles branch changes }) ``` ## Proposed Solution ### Option A: Detect git commit and filter session_diff 1. Watch for `.git/index` or `.git/refs/heads/*` changes in `FileWatcher` 2. On commit detection, filter `session_diff` to only include files that are still uncommitted 3. Publish updated diff to UI ### Option B: Periodically refresh session_diff 1. After bash tool executions that might be git commands, refresh `session_diff` 2. Compare against current `git diff --name-only HEAD` to filter committed files ## Environment - OS: macOS - OpenCode version: latest from `dev` branch - Commit: `7b3c82d95c10e7ec364d8b970209dadfdb43e4dc` ## Related Issues - #11802 - Related issue about session_diff being worktree-global (different but related problem)
Author
Owner

@github-actions[bot] commented on GitHub (Feb 2, 2026):

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

  • #10920: Desktop does not keep session changes current - same problem where changes tab isn't updated after commits
  • #11802: Session summary/diff is worktree-global (not session-scoped) - related underlying issue causing file attribution problems
  • #7555: Session Changes / Modified Files show changes from origin/main - related issue with modified files display not reflecting actual state
  • #10716: TUI session_diff tracking not working on Windows - session_diff tracking failures

Feel free to ignore if these don't address your specific case.

@github-actions[bot] commented on GitHub (Feb 2, 2026): This issue might be a duplicate of existing issues. Please check: - #10920: Desktop does not keep session changes current - same problem where changes tab isn't updated after commits - #11802: Session summary/diff is worktree-global (not session-scoped) - related underlying issue causing file attribution problems - #7555: Session Changes / Modified Files show changes from origin/main - related issue with modified files display not reflecting actual state - #10716: TUI session_diff tracking not working on Windows - session_diff tracking failures Feel free to ignore if these don't address your specific case.
Author
Owner

@taetaetae commented on GitHub (Feb 2, 2026):

Thanks for the duplicate check!

I reviewed #10920 and it describes the same symptom (changes tab not updating after commit), but from the Desktop/Web perspective.

This issue provides:

  • Root cause analysis with specific code references (session/summary.ts, project/vcs.ts, snapshot/index.ts)
  • Two proposed solutions (Option A: git commit detection, Option B: periodic refresh)
  • TUI-specific context (though the underlying issue affects both Desktop and TUI)

The root cause is the same: session_diff is computed from OpenCode's internal snapshot system and never refreshed after external git operations.

I'm happy to work on a PR if the maintainers agree with one of the proposed approaches. The fix would likely benefit both #10920 (Desktop) and this issue (TUI) since they share the same backend code.

cc @adamdotdevin @rekram1-node

@taetaetae commented on GitHub (Feb 2, 2026): Thanks for the duplicate check! I reviewed **#10920** and it describes the same symptom (changes tab not updating after commit), but from the Desktop/Web perspective. This issue provides: - **Root cause analysis** with specific code references (`session/summary.ts`, `project/vcs.ts`, `snapshot/index.ts`) - **Two proposed solutions** (Option A: git commit detection, Option B: periodic refresh) - **TUI-specific context** (though the underlying issue affects both Desktop and TUI) The root cause is the same: `session_diff` is computed from OpenCode's internal snapshot system and never refreshed after external git operations. I'm happy to work on a PR if the maintainers agree with one of the proposed approaches. The fix would likely benefit both #10920 (Desktop) and this issue (TUI) since they share the same backend code. cc @adamdotdevin @rekram1-node
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8370