A smarter cargo-watch alternative, designed for AI coding agents.
Tools like cargo-watch rebuild on every file save. When an AI agent (Claude Code, Cursor, Copilot) edits multiple files in rapid succession, this triggers dozens of redundant builds — wasting CPU and producing noise.
rewatch takes a different approach:
- Detects file changes and kills the running process
- Waits for Enter (or a trigger file) before restarting — so the agent can finish all its edits first
- Restarts once, when you're actually ready
This means one clean build instead of twenty failed ones.
cargo install rewatch# CLI arguments
rewatch -w src,Cargo.toml -e rs,toml -- cargo run
# Or with a config file (just run `rewatch` with no arguments)
rewatchCreate rewatch.toml in your project root:
command = "cargo run"
watch = ["src", "Cargo.toml"]
ext = ["rs", "toml"]
[env]
RUST_LOG = "debug"CLI arguments override config file values.
The trigger file feature enables a fully automated edit-build-test loop:
- Run
rewatchin one terminal - The AI agent edits your code — rewatch detects changes and kills the running process
- When the agent is done, it touches the trigger file — rewatch restarts immediately (no Enter needed)
- The agent sees build output and iterates
rewatch.toml:
command = "cargo run"
watch = ["src"]
ext = ["rs", "toml"]
trigger = ".rewatch-trigger"CLAUDE.md:
After making code changes that require a rebuild, run: touch .rewatch-trigger
.gitignore:
.rewatch-trigger
Run rewatch in one terminal and Claude Code in another — they work together automatically.
- Starts your command
- Watches files for changes (event-driven, not polling)
- On change — kills the process (entire tree) and shows diff-style indicators:
+created,~modified,-removed- Duplicate file names are suppressed — each file shown only once
- Waits for Enter before restarting (so you or the agent can finish edits)
- On process crash — shows exit code, waits for Enter
- On trigger file — restarts immediately without Enter (stale trigger files are cleaned up on startup)
- Hot-reloads its own config: editing
rewatch.toml(or the file passed via--config) re-reads the config and respawns the child with the new command/env/watch paths. No-op saves (touch,:wwithout edits) are skipped via content-hash dedup. - Ctrl+C — first press kills the child process and waits, second press exits rewatch
Note: By default, the trigger file only works when rewatch is waiting for Enter (after file changes or process exit). Use trigger_always = true or -T to allow trigger to restart even without file changes.
| Option | Description |
|---|---|
-w, --watch <paths> |
Paths to watch, comma-separated or multiple flags |
-e, --ext <extensions> |
Filter by extensions (.rs and rs both work). Only applies to files inside watched directories — files listed explicitly in -w always trigger. |
-t, --trigger <path> |
Trigger file for auto-restart |
-T, --trigger-always |
Trigger restarts even without file changes |
-E, --env <KEY=VALUE> |
Set environment variables (overrides TOML [env]) |
-c, --config <path> |
Use a custom config file instead of rewatch.toml. The file is required when this flag is given. |
-- <command...> |
Command to run |
Example with env override:
rewatch -E SQLX_MIGRATE_IGNORE_MISSING=truecommand = "cargo run --release" # command to execute (shell-style quoting supported)
watch = ["src", "Cargo.toml", ".env"] # files/directories to watch
ext = ["rs", "toml"] # filter by extension (optional, applies to dirs only)
trigger = ".rewatch-trigger" # trigger file (optional)
trigger_always = false # trigger restarts even without file changes (default: false)
[env] # environment variables for the child process
RUST_LOG = "debug"
SQLX_MIGRATE_IGNORE_MISSING = "true"- Windows: kills process tree via Win32 Job Objects
- Linux: kills process group via
kill(-pgid, SIGTERM) - macOS: same as Linux
Powered by notify (OS-native file system events) and process-wrap (from the watchexec project).
| cargo-watch | rewatch | |
|---|---|---|
| Rebuilds on every save | Yes | No — waits for Enter or trigger |
| AI agent friendly | No — floods with builds | Yes — trigger file for automation |
| Kills process tree | Partial | Full (Job Objects / process groups) |
| Config file | No | rewatch.toml |
| Language-agnostic | Cargo only | Any command |
MIT