File system watcher that executes commands when files change, with cross-platform support and git ignore integration
watchexec is a file system monitoring tool that automatically runs commands when files change in watched directories. It monitors the current directory and subdirectories by default, detecting modifications and triggering user-specified commands. The tool coalesces multiple filesystem events into single executions, handling editors that create swap or backup files during saves.
The tool integrates with version control workflows by automatically loading .gitignore and .ignore files to exclude irrelevant changes. It provides changed file paths through environment variables or STDIN, and uses process groups to manage forking programs. Commands can be filtered by file extensions, and the tool supports restarting long-running processes with the -r flag.
watchexec runs natively on macOS, Linux, and Windows without requiring language runtimes or ecosystem-specific dependencies. It serves common development workflows like running unit tests on code changes, triggering linters and syntax checkers, or rebuilding artifacts. The tool pairs well with build systems like just and specialized tools like checkexec for conditional execution based on file timestamps.
# via Cargo
cargo install --locked watchexec-cli
# via Binstall
cargo binstall watchexec-cli