davila7/claude-code-templates · info

Warning: Error closing watcher:

Error message

Warning: Error closing watcher:

What it means

FileWatcher.stop() warns when closing an individual fs.FSWatcher throws. Watchers are iterated and each close() is wrapped in try/catch so one failing close doesn't abort shutdown of the rest.

Source

Thrown at cli-tool/src/analytics/core/FileWatcher.js:334

        this.claudeDir, 
        this.dataRefreshCallback, 
        this.processRefreshCallback
      );
    }
  }

  /**
   * Stop and cleanup all watchers and intervals
   */
  stop() {
    console.log(chalk.red('🛑 Stopping file watchers...'));

    // Close all watchers
    this.watchers.forEach(watcher => {
      try {
        watcher.close();
      } catch (error) {
        console.warn(chalk.yellow('Warning: Error closing watcher:'), error.message);
      }
    });

    // Clear all intervals
    this.intervals.forEach(intervalId => {
      clearInterval(intervalId);
    });

    // Reset arrays
    this.watchers = [];
    this.intervals = [];
    this.isActive = false;
  }

  /**
   * Get watcher status
   * @returns {Object} Status information
   */

View on GitHub (pinned to a0851ed10c)

Solutions

  1. Ignore — the watcher is being torn down anyway; the warning is cosmetic
  2. Avoid double-stop: guard stop() with a running flag
  3. Ensure watched directories still exist before stop, or detach deletions first
  4. Upgrade the CLI if double-close was fixed in a newer version

Example fix

// before
stop() {
  this.watchers.forEach(w => w.close());
}
// after — idempotent stop
stop() {
  this.watchers.forEach(w => { try { w.close(); } catch {} });
  this.watchers.clear();
  this.running = false;
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Make close idempotent so double-stop never throws
if (!this.running) return;

Try / catch

this.watchers.forEach(w => { try { w.close(); } catch (e) { /* swallow: teardown */ } });
this.watchers.clear();

Prevention

When it happens

Trigger: watcher.close() throwing on an already-closed or invalidated watcher (EBADF), or on some platforms when the watched directory was removed before close.

Common situations: Watched project directories deleted or renamed before stop(); rapid start/stop cycles (resume calls stop) closing watchers twice; platform quirks on Windows/network mounts.

Related errors


AI-assisted analysis of davila7/claude-code-templates@a0851ed10c (2026-08-28). Data as JSON: /api/errors/32be48d64f1cce48. Report an issue: GitHub.