opencode icon indicating copy to clipboard operation
opencode copied to clipboard

fix: filter git operations from session diffs

Open R44VC0RP opened this issue 1 day ago • 2 comments

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)

R44VC0RP avatar Jan 14 '26 20:01 R44VC0RP