Watch Mode
Watch mode re-runs a recipe whenever relevant files change. It’s useful for development loops — running tests, rebuilding on save, or restarting a dev server.
jake -w buildJake polls for file changes every 500ms, with a 100ms debounce after the last detected change before triggering a re-run. This means the recipe fires roughly 100ms after files stop changing, not on every individual write.
What Gets Watched
Section titled “What Gets Watched”Without an explicit pattern, Jake automatically watches:
- The Jakefile and any imported files
- File dependencies declared in
filerecipes - Patterns in
@watchdirectives in the target recipe
jake -w build # watches Jakefile + @watch patterns + file depsWith an explicit pattern, Jake watches only what you specify:
jake -w "src/**/*.ts" buildWhen watch mode starts, Jake shows what it’s monitoring:
[watch] Watching 5 file(s) for changes...[watch] Patterns: src/**/*.ts, Jakefile[watch] Press Ctrl+C to stop@watch Directive
Section titled “@watch Directive”Declare additional watch patterns inside a recipe:
task build: @watch src/**/*.ts npm run buildMultiple patterns on one line:
task dev: @watch src/**/*.ts tests/**/*.ts config/*.json npm run devJakefile Reloads
Section titled “Jakefile Reloads”If the Jakefile itself (or an imported file) changes while watch mode is running, Jake reloads it before the next run. The entire executor reinitializes with the updated recipe definitions — so changes to recipe commands, dependencies, or new recipes take effect immediately without restarting.
When using an explicit pattern (jake -w "src/**" build), Jakefile reloading still happens if the Jakefile matches the pattern or is being auto-tracked.
Deleted and Recreated Files
Section titled “Deleted and Recreated Files”Deleted files trigger a re-run. If you delete a watched file and then recreate it, both events trigger the recipe. This is useful for workflows that regenerate files from scratch.
Conditional Watch Behavior
Section titled “Conditional Watch Behavior”Use is_watching() to adjust what a recipe does in watch mode vs a one-off run:
task build: @if is_watching() echo "Incremental build (skipping lint)..." @else npm run lint @end npm run buildLong-Running Recipes
Section titled “Long-Running Recipes”If a recipe is still running when the next file change is detected, Jake waits for the current run to finish before starting the next one. Changes that arrive during execution are not queued — only the latest change matters, and it triggers one re-run once the current execution completes.
Combining Flags
Section titled “Combining Flags”# Verbose output shows which file triggered the rebuildjake -w -v build
# Parallel execution in watch modejake -w -j4 test
# Explicit pattern + verbosejake -w "src/**/*.go" -v testCommon Patterns
Section titled “Common Patterns”Frontend dev loop — watch TypeScript source, rebuild on change:
task dev: @watch src/**/*.ts src/**/*.css public/**/* npm run build:devTest on save — run only affected tests:
task test: @watch src/**/*.ts tests/**/*.test.ts npm testGo rebuild — recompile and restart on source changes:
task run: @watch **/*.go go run ./cmd/server