[PR #8539] fix: filter git operations from session diffs #12784

Closed
opened 2026-02-16 18:17:40 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/8539

State: closed
Merged: No


Summary

When git operations like pull, merge, or checkout are run (either through OpenCode or in a separate terminal), the changed files would inflate the session diff counts in the sidebar, showing thousands of lines changed that weren't actually edited by the agent.

image

Changes

  • New FileTracking module (session/file-tracking.ts): Tracks files modified by git operations during a session
  • Bash tool updates: Detects git worktree-modifying commands (pull, merge, checkout, rebase, etc.) and tracks affected files
  • Step boundary tracking: Records the project's git HEAD at step-start and step-finish to detect external git operations
  • Diff filtering: Excludes git-modified files from session diffs unless they were also explicitly edited by tools

How It Works

  1. At step-start: Records the project's git HEAD
  2. During execution: If bash runs a git op, tracks changed files immediately
  3. At step-finish: Records the new git HEAD
  4. When computing diffs:
    • Compares HEAD at step boundaries to find all git-modified files (catches external git ops)
    • Filters the final diff to exclude git-modified files
    • Still includes files if they were explicitly edited by edit/write/patch tools

Handles

  • Git ops run through OpenCode's bash tool
  • Git ops run in a separate terminal by the user
  • User external edits (preserved - they show in snapshot diff but NOT in git-modified list)
  • Files that are both pulled AND subsequently edited by tools (included)
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/8539 **State:** closed **Merged:** No --- ## Summary When git operations like `pull`, `merge`, or `checkout` are run (either through OpenCode or in a separate terminal), the changed files would inflate the session diff counts in the sidebar, showing thousands of lines changed that weren't actually edited by the agent. ![image](https://github.com/user-attachments/assets/placeholder) ## Changes - **New `FileTracking` module** (`session/file-tracking.ts`): Tracks files modified by git operations during a session - **Bash tool updates**: Detects git worktree-modifying commands (`pull`, `merge`, `checkout`, `rebase`, etc.) and tracks affected files - **Step boundary tracking**: Records the project's git HEAD at `step-start` and `step-finish` to detect external git operations - **Diff filtering**: Excludes git-modified files from session diffs unless they were also explicitly edited by tools ## How It Works 1. At `step-start`: Records the project's git HEAD 2. During execution: If bash runs a git op, tracks changed files immediately 3. At `step-finish`: Records the new git HEAD 4. When computing diffs: - Compares HEAD at step boundaries to find all git-modified files (catches external git ops) - Filters the final diff to exclude git-modified files - Still includes files if they were explicitly edited by edit/write/patch tools ## Handles - Git ops run through OpenCode's bash tool - Git ops run in a separate terminal by the user - User external edits (preserved - they show in snapshot diff but NOT in git-modified list) - Files that are both pulled AND subsequently edited by tools (included)
yindo added the pull-request label 2026-02-16 18:17:40 -05:00
yindo closed this issue 2026-02-16 18:17:40 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12784