File watcher that runs commands when files change, with .gitignore support and cross-platform filesystem monitoring
watchexec is a file monitoring tool that executes commands when filesystem changes are detected. It monitors the current directory and subdirectories for modifications, then triggers specified commands automatically. The tool handles common development workflows like running unit tests, linters, or build processes when source files change.
The tool coalesces multiple filesystem events into single command executions, which prevents redundant runs when editors create temporary files during saves. It respects .gitignore and .ignore files for filtering watched paths, and uses process groups to manage forking programs. Changed file paths are provided to executed commands through environment variables or STDIN.
watchexec runs on macOS, Linux, and Windows without requiring language runtimes or ecosystem-specific dependencies. It supports file extension filtering, command restarting with the -r flag, and integrates with tools like checkexec for conditional execution and systemfd for development socket-passing. The tool serves developers working across different languages and build systems who need automated command execution based on file changes.
# via Cargo
cargo install --locked watchexec-cli
# via Binstall
cargo binstall watchexec-cli