# watchexec

> File watcher that runs commands when files change, with .gitignore support and cross-platform filesystem monitoring

Stars: 7.3k · Language: Rust · License: Apache-2.0 · Categories: Dev Tools

- Repository: https://github.com/watchexec/watchexec
- Website: https://watchexec.github.io
- Page: https://www.trmn.sh/tools/watchexec

## Install

- Cargo: `cargo install --locked watchexec-cli`
- Binstall: `cargo binstall watchexec-cli`

## Overview

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.

### Installation

```bash
# via Cargo
cargo install --locked watchexec-cli
```

```bash
# via Binstall
cargo binstall watchexec-cli
```

## Alternatives

- [sd](https://www.trmn.sh/tools/sd.md): Find and replace CLI tool with regex support, string-literal mode, and faster performance than sed (Rust, 7.4k stars)
- [zizmor](https://www.trmn.sh/tools/zizmor.md): Static analysis tool that finds and fixes security issues in CI/CD configurations, including GitHub Actions workflows, Dependabot, and pre-commit. (Rust, 6.9k stars)
- [tealdeer](https://www.trmn.sh/tools/tealdeer.md): Fast Rust implementation of tldr providing simplified, example-based manual pages for command-line tools (Rust, 6.6k stars)
- [tailspin](https://www.trmn.sh/tools/tailspin.md): Log file highlighter (binary: tspin) that colors dates, numbers, IPs, UUIDs, URLs and more in any log format, with no config, and pages output through less. (Rust, 8.0k stars)
- [pastel](https://www.trmn.sh/tools/pastel.md): Command-line tool to generate, analyze, convert and manipulate colors across multiple formats and color spaces (Rust, 6.5k stars)

## Guides

- [Rerun a test when files change with Watchexec](https://www.trmn.sh/guides/watchexec-rerun-tests): Watch a small project with Watchexec, trigger passing and failing runs, and ignore generated files.
- [watchexec vs entr](https://www.trmn.sh/compare/watchexec-vs-entr): Compare watchexec, entr: workflows, strengths and tradeoffs.

---

Canonical: https://www.trmn.sh/tools/watchexec
