Skip to content

Conversation

@R44VC0RP
Copy link
Collaborator

@R44VC0RP R44VC0RP commented Jan 21, 2026

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_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

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
@R44VC0RP R44VC0RP force-pushed the feat/config-hot-reload branch from 3d18c36 to 9e93c83 Compare January 21, 2026 21:37
@R44VC0RP
Copy link
Collaborator Author

310 of the LOC is a test file.

- Watch config files (opencode.json, opencode.jsonc, config.json) in:
  - Project directory
  - .opencode subdirectory
  - ~/.opencode (user home)
  - ~/.config/opencode (global config)
- Debounce config changes (500ms) to prevent reload storms
- Reset Config.global cache before Instance.dispose()
- Emit global.disposed event to notify TUI/web clients to refresh
- Add OPENCODE_EXPERIMENTAL_CONFIG_WATCHER flag to opt-in
- Use createRequire for browser conditions compatibility
@R44VC0RP R44VC0RP force-pushed the feat/config-hot-reload branch from 9e93c83 to fc5e799 Compare January 21, 2026 21:40
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