file-watcher
Original:🇺🇸 English
Translated
Chokidar-based file watcher that triggers `claude -p` on changes. Useful for automated AI reactions to file changes — design sync, code validation, config regeneration, etc.
21installs
Added on
NPX Install
npx skill4agent add qdhenry/claude-command-suite file-watcherTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →File Watcher Skill
Overview
Sets up a file watcher using chokidar that monitors a path for changes and runs a Claude prompt against every changed file. The prompt supports a placeholder that gets replaced with the changed file path.
{{file}}Quick Start
bash
# Watch src/ and analyze any changed file
node scripts/watch-files.mjs ./src 'Analyze {{file}} for issues'
# Watch only .tsx files with 1s debounce
node scripts/watch-files.mjs ./src 'Review {{file}} for React best practices' --glob '*.tsx' --debounce 1000
# Via package.json script (pass args after --)
bun run watch:files -- ./src 'Check {{file}}'CLI Reference
node scripts/watch-files.mjs <path> <prompt> [--glob '<pattern>'] [--debounce <ms>]| Arg | Required | Description |
|---|---|---|
| Yes | File or directory to watch |
| Yes | Claude prompt. Use |
| No | Glob filter (e.g. |
| No | Debounce delay in milliseconds (default: 500) |
How It Works
- Chokidar watches the target path for and
addeventschange - Changes are debounced (default 500ms) to batch rapid saves
- For each changed file, the placeholder in the prompt is replaced with the actual file path
{{file}} - is executed via
claude -p '<prompt>' --printchild_process.execSync - Claude's output is logged to stdout
Example Prompts
| Use Case | Prompt |
|---|---|
| Code review | |
| Type checking | |
| Design sync | |
| Test generation | |
| Documentation | |
Configuration
Glob Patterns
Filter which files trigger the watcher:
bash
--glob '*.tsx' # Only TypeScript React files
--glob '*.css' # Only CSS files
--glob '*.{ts,tsx}' # TypeScript files (not supported by chokidar glob — use without braces)Debounce
Control how long to wait after the last change before triggering:
bash
--debounce 200 # Fast (200ms) — good for single-file saves
--debounce 1000 # Slow (1s) — good for batch operations
--debounce 5000 # Very slow (5s) — good for build output directoriesTroubleshooting
| Issue | Solution |
|---|---|
| Install Claude Code: |
| Watcher not detecting changes | Check the path exists and you have read permissions |
| Too many invocations | Increase |
| Prompt with special characters | Wrap prompt in single quotes; |
| Permission denied | Ensure the watched directory is readable |
Dependencies
- (devDependency) — file system watcher
chokidar - CLI — must be installed globally and authenticated
claude