Re-run Commands on File Change With watchexec

Watch files and automatically restart a command after edits.

macOSwatchautomationcliLow risk
Run watchexec -w src -e rs -- cargo test to rerun tests whenever a Rust file changes.

01Command

Command
$ watchexec -w src -e rs -- cargo test

02What it does

watchexec monitors files or directories and restarts the given command on change. Use -w to set watch paths, -e to filter extensions, --debounce to avoid rapid restarts and -c to clear the screen between runs.

03Risk

RiskLow risk
CompatibilitymacOS with Homebrew installed
!Warning: It watches the filesystem continuously and can spin CPU if the watched command itself writes many files.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • Homebrew formula: watchexec
    Homebrew · vendor-doc · 2026-09-20
    Evidence: Packages watchexec, which watches paths and restarts a command on change.

Last verified: 2026-09-22 · Category: Developer