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

Closed
opened 2026-02-16 17:39:37 -05:00 by yindo · 3 comments
Owner

Originally created by @roman-16 on GitHub (Dec 4, 2025).

Originally assigned to: @rekram1-node on GitHub.

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

Originally created by @roman-16 on GitHub (Dec 4, 2025). Originally assigned to: @rekram1-node on GitHub. ### 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: ```javascript 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: ```bash mkdir test-repo && cd test-repo git init echo "test" > file.txt git add file.txt # Don't commit! ``` 2. Run opencode with logging: ```bash 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
yindo added the bug label 2026-02-16 17:39:37 -05:00
yindo closed this issue 2026-02-16 17:39:37 -05:00
Author
Owner

@rekram1-node commented on GitHub (Dec 4, 2025):

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 commented on GitHub (Dec 4, 2025): We do this intentionally because if you are running opencode in your root dir we dont wanna file watch everything that'd be crazy
Author
Owner

@rekram1-node commented on GitHub (Dec 4, 2025):

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 commented on GitHub (Dec 4, 2025): 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
Author
Owner

@rekram1-node commented on GitHub (Dec 5, 2025):

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

@rekram1-node commented on GitHub (Dec 5, 2025): fixed in next release: https://github.com/sst/opencode/commit/767a81f9308c451dbe68451da1623baa255745e9
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3315