Skip to content

Conversation

@R44VC0RP
Copy link
Collaborator

Summary

Adds automatic config file watching to FileWatcher that triggers Instance.dispose() when config files change. This enables hot-reloading of MCP servers and other config-driven features without restarting the server.

Use case: Running opencode serve on a remote server, then adding/modifying opencode.json with new MCP servers - the changes now take effect automatically.

Changes

  • Expanded FileWatcher to watch config files (opencode.json, opencode.jsonc, config.json)
  • Watches multiple locations:
    • Project root (Instance.directory)
    • Project .opencode/ subdirectory (if exists)
    • User home ~/.opencode/ (if exists)
    • Global config ~/.config/opencode/
  • Per-instance debounce (500ms) and in-flight guard to prevent dispose storms
  • Works for all projects (not just git repos)
  • Added OPENCODE_DISABLE_CONFIG_WATCHER flag to opt out
  • Added Event.ConfigChanged bus event for subscribers

Testing

  • Verified TypeScript compiles without errors
  • Verified bun dev --help runs successfully

Add automatic config file watching to FileWatcher that triggers
Instance.dispose() when opencode.json, opencode.jsonc, or config.json
changes. This enables hot-reloading of MCP servers and other config
without restarting the server.

Changes:
- Watch project root, .opencode/, ~/.opencode/, and ~/.config/opencode/
- Per-instance debounce (500ms) and in-flight guard to prevent storms
- Works for all projects (not just git repos)
- Add OPENCODE_DISABLE_CONFIG_WATCHER flag to opt out
@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found one potentially related PR:

Related PR:

The searches primarily returned PR #9849 (the current PR), suggesting there are no other open PRs directly addressing config file hot-reloading or MCP server dynamic reloading at this time.

@R44VC0RP R44VC0RP marked this pull request as draft January 21, 2026 16:13
Test cases for the config hot-reload feature:
- Detects opencode.json changes
- Watches .opencode directory
- Debounces rapid changes
- Watches config.json and opencode.jsonc
- Ignores non-config files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant