[PR #9849] feat: hot-reload config files for MCP server changes #13243

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

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

State: closed
Merged: No


tl;dr & demo

tl;dr: this allows for hot-reloads on the server when an opencode config file has been changed

https://github.com/user-attachments/assets/3ec9547a-4507-4973-be11-9fe4e4150afe

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 (500

ms) and in-flight guard to prevent dispose storms

  • Works for all projects (not just git repos)
  • Added OPENCODE_EXPERIMENTAL_CONFIG_WATCHER flag to opt in
  • Added Event.ConfigChanged bus event for subscribers

Testing

  • Verified TypeScript compiles without errors
  • Verified bun dev --help runs successfully
  • Added a tests file
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/9849 **State:** closed **Merged:** No --- ## tl;dr & demo > tl;dr: this allows for hot-reloads on the server when an opencode config file has been changed https://github.com/user-attachments/assets/3ec9547a-4507-4973-be11-9fe4e4150afe ## 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 (500 ms) and in-flight guard to prevent dispose storms - Works for all projects (not just git repos) - Added `OPENCODE_EXPERIMENTAL_CONFIG_WATCHER` flag to opt in - Added `Event.ConfigChanged` bus event for subscribers ## Testing - Verified TypeScript compiles without errors - Verified `bun dev --help` runs successfully - Added a tests file
yindo added the pull-request label 2026-02-16 18:18:06 -05:00
yindo closed this issue 2026-02-16 18:18:06 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13243