rewatch
A smarter cargo-watch alternative, designed for AI coding agents.
The problem with cargo-watch
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.
Install
Quick start
# CLI arguments
# Or with a config file (just run `rewatch` with no arguments)
Config file
Create rewatch.toml in your project root:
= "cargo run"
= ["src", "Cargo.toml"]
= ["rs", "toml"]
[]
= "debug"
CLI arguments override config file values.
Using with AI coding agents
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
Setup with Claude Code
rewatch.toml:
= "cargo run"
= ["src"]
= ["rs", "toml"]
= ".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.
How it works
- 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
- 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
CLI options
| Option | Description |
|---|---|
-w, --watch <paths> |
Paths to watch, comma-separated or multiple flags |
-e, --ext <extensions> |
Filter by extensions (.rs and rs both work) |
-t, --trigger <path> |
Trigger file for auto-restart |
-- <command...> |
Command to run |
Config file reference
= "cargo run --release" # command to execute (shell-style quoting supported)
= ["src", "Cargo.toml"] # files/directories to watch
= ["rs", "toml"] # filter by extension (optional)
= ".rewatch-trigger" # trigger file (optional)
[] # environment variables for the child process
= "debug"
= "true"
Platform support
- 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).
rewatch vs cargo-watch
| 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 |
License
MIT