Skip to main content
Watch mode tells Ant to monitor your entry file and restart the process whenever that file is saved. You get a tight edit-save-run loop without manually stopping and restarting the process yourself. It is particularly useful when developing HTTP servers or running scripts that you iterate on frequently.

Starting watch mode

Add -w or --watch before your file:
ant -w server.js
Ant starts the process normally, then watches server.js for changes. Each time you save the file, Ant terminates the running process and starts a fresh one. TypeScript files work the same way:
ant -w server.ts

Keeping previous output

By default, Ant clears the terminal screen on each restart so you always see only the output from the current run. Pass --no-clear-screen to keep all previous output visible instead:
ant -w --no-clear-screen server.js
This is useful when you want to compare output across restarts or when your terminal does not handle screen clearing well.
--no-clear-screen must be used together with -w. Using it on its own is an error and Ant will exit with a message explaining the issue.

Development workflow

1

Start Ant in watch mode

ant -w server.js
Ant starts your script and prints its output to the terminal.
2

Edit and save your file

Open server.js in your editor. Make a change and save.
3

Ant restarts automatically

Ant detects the file change, terminates the old process, and starts a new one. You see the fresh output immediately — no manual restart needed.

HTTP server example

Watch mode pairs well with Ant’s built-in HTTP server. Start your server in watch mode and every save triggers a clean restart:
export default {
  port: 3000,
  fetch(req) {
    return new Response("Hello from Ant!");
  }
};
ant -w server.js
# started on port 3000
# [file change detected — restarting]
# started on port 3000

Restrictions

Watch mode has a few constraints that come directly from how the watcher is implemented:
Watch mode monitors only the entry file you pass on the command line. Changes to imported modules or other files in your project do not trigger a restart.
The following combinations are not supported and will cause Ant to exit with an error:
CombinationReason
ant -w -e "..."Watch mode requires a real file on disk to monitor.
echo "..." | ant -wStdin has no file path to watch.
ant -w installWatch mode cannot be used with package manager subcommands.
ant -w --no-clear-screen (without a file)Requires a file entry point.
If you need to watch multiple files or directories, consider wrapping Ant in a shell script that uses a file-watching utility, or structure your project so that a single entry point imports everything you want to watch.