watchexec
$ watchexec Community Med Riskwatchexec monitors workspace paths for changes and optionally re-runs commands or emits structured filesystem events via --only-emit-events --emit-events-to=json-stdio. Because watchers run indefinitely by design, agents must run them in bounded background tasks.
brew install watchexec OS-native file watching (kqueue/inotify) runs directly in watchexec without polling or MCP overhead.
Agent-Readiness Checklist
Static evaluation (not yet probed on this host). Run npm run data:probe locally to capture live verification.
FCRS-1.0 6-Dimension Breakdown
Supports --emit-events-to=json-stdio and --only-emit-events, though it is a long-running daemon by nature.
- NDJSON event stream via
--emit-events-to=json-stdio
--only-emit-events is read-only; running commands on file edits can loop or mutate state if poorly scoped.
- Supports read-only event emission vs command execution
Single Rust binary via brew, cargo install watchexec-cli, and GitHub releases.
- Cross-platform OS watcher (
kqueue,inotify,ReadDirectoryChangesW)
Debounced, .gitignore-aware watching avoids brittle polling loops.
- Built-in ignore filtering and debouncing
Maintained by the watchexec org and powers tools like cargo-watch.
- Active Apache-2.0 repository
Detailed man page documenting event JSON schema and ignore rules.
- Upstream man page and
--help
Security, Auth & Guardrails
None required; watches local filesystem events only.
100% free, offline, and open-source (Apache-2.0).
# watchexec Agent Rules - NEVER run `watchexec` synchronously without a timeout or background task—it loops until killed. - Scope watches with `-w <dir>` and `-e <ext>` so build outputs do not trigger infinite loops.
Agent-Ready Command Recipes
Safe Read-Only Queries
watchexec --only-emit-events --emit-events-to=json-stdio -w src/
Emits JSON event objects on file modifications without executing any subcommand (run with a timeout/background limit).
Controlled Writes & Previews
watchexec -r -w src/ -e ts -- npm test
Watches .ts files under src/ and restarts npm test on change.
Strengths for Agents
- + Emits structured NDJSON filesystem events with
--only-emit-events --emit-events-to=json-stdio. - + Respects
.gitignoreout of the box and debounces rapid editor saves.
Caveats & Pitfalls
- ! Blocks indefinitely unless launched as a bounded background task or stopped explicitly.