opencode icon indicating copy to clipboard operation
opencode copied to clipboard

`file.watcher.updated` events never fire in git repositories with no commits

Open roman-16 opened this issue 1 month ago • 2 comments

Description

The file.watcher.updated event never fires in git repositories that have been initialized but have no commits yet. The FileWatcher silently fails to initialize because the project is incorrectly assigned projectID=global instead of being recognized as a git project. This affects:

  • Plugins listening for file.watcher.updated events
  • Any functionality dependent on file system watching Root cause analysis: When OpenCode detects a git repository:
  1. git rev-parse succeeds (.git directory exists)
  2. But for repos with no commits, the project is created with projectID=global instead of a proper git project hash
  3. In FileWatcher.init(), there's an early return check:
    if (Instance.project.vcs !== "git")
      return {};
    
  4. Since projectID=global projects don't have vcs: "git", the watcher never initializes
  5. No logs are emitted - the failure is completely silent

OpenCode version

1.0.119

Steps to reproduce

  1. Create a new git repository without any commits:
    mkdir test-repo && cd test-repo
    git init
    echo "test" > file.txt
    git add file.txt
    # Don't commit!
    
  2. Run opencode with logging:
    opencode run --print-logs --log-level INFO "add 1 to main.txt"
    
  3. Observe the logs:
    • You'll see projectID=global in session creation
    • No service=file.watcher logs appear at all
    • No file.watcher.updated events are published
  4. Compare with a repo that has commits - the watcher initializes properly with logs like:
    INFO  service=file.watcher init
    INFO  service=file.watcher platform=linux backend=inotify watcher backend
    

Screenshot and/or share link

No response

Operating System

NixOS (Linux)

Terminal

vscode

roman-16 avatar Dec 04 '25 23:12 roman-16

We do this intentionally because if you are running opencode in your root dir we dont wanna file watch everything that'd be crazy

rekram1-node avatar Dec 05 '25 04:12 rekram1-node

But we need to fix for this case:

But for repos with no commits, the project is created with projectID=global instead of a proper git project hash

rekram1-node avatar Dec 05 '25 04:12 rekram1-node

fixed in next release: https://github.com/sst/opencode/commit/767a81f9308c451dbe68451da1623baa255745e9

rekram1-node avatar Dec 05 '25 06:12 rekram1-node