home / skills / aidotnet / moyucode / file-watcher

file-watcher skill

/skills/tools/file-watcher

This skill watches files and directories for changes, with event callbacks, pattern filtering, and optional actions on update.

npx playbooks add skill aidotnet/moyucode --skill file-watcher

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
906 B
---
name: file-watcher
description: 监视文件和目录变化,支持事件回调和过滤。
metadata:
  short-description: 监视文件变化
source:
  repository: https://github.com/gorakhargosh/watchdog
  license: Apache-2.0
---

# File Watcher Tool

## Description
Watch files and directories for changes with event callbacks, pattern filtering, and action triggers.

## Trigger
- `/watch` command
- User needs to monitor files
- User wants change notifications

## Usage

```bash
# Watch directory
python scripts/file_watcher.py ./src/

# Watch with pattern filter
python scripts/file_watcher.py ./src/ --pattern "*.py"

# Watch and run command on change
python scripts/file_watcher.py ./src/ --exec "npm run build"

# Watch specific file
python scripts/file_watcher.py config.json
```

## Tags
`watch`, `files`, `monitor`, `events`, `automation`

## Compatibility
- Codex: ✅
- Claude Code: ✅

Overview

This skill watches files and directories for changes and delivers event callbacks, pattern filtering, and optional action triggers. It provides a lightweight, scriptable watcher that can notify on create/modify/delete events and run commands when changes occur. It is built in TypeScript and designed for integration into development workflows and automation pipelines.

How this skill works

The watcher scans specified files or directories and listens for filesystem events. You can supply glob-style patterns to filter which files trigger callbacks. When a matching event occurs, the skill invokes configured callbacks or executes a shell command. It supports single-file targets, whole directories, and recursive watching with debouncing to avoid duplicate triggers.

When to use it

  • Automatically rebuild or test when source files change
  • Monitor configuration files for runtime reloads
  • Run deployment or packaging steps on content updates
  • Trigger notifications or CI hooks from local file changes
  • Watch log files or data folders for ingestion pipelines

Best practices

  • Specify precise glob patterns to limit noise and reduce CPU usage
  • Use debouncing or cooldown intervals to group rapid changes into a single action
  • Run build or heavy commands asynchronously and check exit codes
  • Exclude large directories like node_modules or build outputs from watches
  • Log events with timestamps to aid debugging and audit trails

Example use cases

  • Watch a project src/ folder and run the build command on change (e.g., --exec "npm run build").
  • Monitor a single config.json file and reload application settings when it changes.
  • Filter for *.ts or *.py files to only trigger tests for relevant language files.
  • Trigger a deployment script when files in a release/ directory are added or modified.
  • Notify a team chat or webhook when critical files are deleted or replaced.

FAQ

Can I watch multiple paths at once?

Yes. Provide multiple file or directory paths and the watcher will monitor each target concurrently.

How do I avoid repeated triggers during large saves?

Use debounce or cooldown options to group rapid filesystem events into a single callback or command run.