watchexec
OfficialAgent-readyAbout watchexec
watchexec automatically runs commands when files in the watched directory change. It filters monitored files by extension, path pattern, or custom rules, and debounces rapid successive changes to avoid redundant executions. Useful for integrating into development workflows that need to react to source code updates.
Key features
- 01Run commands automatically when files change
- 02Filter which files trigger execution by extension or path pattern
- 03Debounce rapid changes to prevent duplicate runs
Use cases
- 01Re-run tests or rebuild automatically as code is edited
- 02Enable real-time file-change response for coding agents in development environments
- 03Reduce repetitive manual commands in active development workflows
Install
Pick your OS or package manager and run the command in a terminal.
Once installed, runwatchexec --versionto confirm it works.
Example commands
Common commands in the order you’d use them.
Details
From the project READMEWatchexec
Software development often involves running the same commands over and over. Boring!
watchexec is a simple, standalone tool that watches a path and runs a command whenever it detects modifications.
Example use cases:
- Automatically run unit tests
- Run linters/syntax checkers
- Rebuild artifacts
Features
- Simple invocation and use, does not require a cryptic command line involving
xargs - Runs on OS X, Linux, and Windows
- Monitors current directory and all subdirectories for changes
- Coalesces multiple filesystem events into one, for editors that use swap/backup files during saving
- Loads
.gitignoreand.ignorefiles - Uses process groups to keep hold of forking programs
- Provides the paths that changed in environment variables or STDIN
- Does not require a language runtime, not tied to any particular language or ecosystem
- And more!
Quick start
Watch all JavaScript, CSS and HTML files in the current directory and all subdirectories for changes, running npm run build when a change is detected:
$ watchexec -e js,css,html npm run build
Call/restart python server.py when any Python file in the current directory (and all subdirectories) changes:
$ watchexec -r -e py -- python server.py
More usage examples: in the CLI README!
Install
- With your package manager for Arch, Debian, Homebrew, Nix, Scoop, Chocolatey…
- From binary with Binstall:
cargo binstall watchexec-cli - As pre-built binary package from Github
- From source with Cargo:
cargo install --locked watchexec-cli
All options in detail: in the CLI README,
in the online help (watchexec -h, watchexec --help, or watchexec --manual),
and in the manual page.
Augment
Watchexec pairs well with:
- checkexec: to run only when source files are newer than a target file
- just: a modern alternative to
make - systemfd: socket-passing in development
Extend
- watchexec library: to create more specialised watchexec-powered tools.
- watchexec-events: event types for watchexec.
- watchexec-signals: signal types for watchexec.
- watchexec-supervisor: process lifecycle manager (the exec part of watchexec).
- clearscreen: to clear the (terminal) screen on every platform.
- process wrap: to run commands in process groups.
- ignore files: to find, parse, and interpret ignore files.
- project origins: to find the origin(s) directory of a project.
- notify: to respond to file modifications (third-party).
Downstreams
Selected downstreams of watchexec and associated crates:
cargo watch: a specialised watcher for Rust/Cargo projects.- cargo lambda: a dev tool for Rust-powered AWS Lambda functions.
- create-rust-app: a template for Rust+React web apps.
- devenv.sh: a developer environment with nix-based declarative configs.
- dotter: a dotfile manager.
- ghciwatch: a specialised watcher for Haskell projects.
- tectonic: a TeX/LaTeX typesetting system.