hx’s watch mode automatically runs commands when source files change, enabling rapid development iteration.
Overview
Watch mode monitors your source files and triggers rebuilds, tests, or other commands automatically when you save changes.
hx watch buildBasic Usage
Watch and Build
hx watch buildRebuilds automatically when any .hs file changes.
Watch and Test
hx watch testRe-runs tests on every save.
Watch and Run
hx watch runRebuilds and restarts the application.
Watch and Check
hx watch checkType-checks without full compilation (faster feedback).
Watched Files
By default, hx watches:
| Pattern | Description |
|---|---|
*.hs | Haskell source files |
*.cabal | Cabal configuration |
hx.toml | hx configuration |
*.yaml, *.json | Common config files |
In directories:
src/app/lib/test/bench/
Options
Clear Terminal
Clear the screen before each run:
hx watch build --clearDebounce
Control how long to wait after changes settle:
# Wait 500ms after last change
hx watch build --debounce 500Default is 300ms.
Custom Patterns
Watch additional files:
hx watch build --include "config/**/*.yaml"Exclude files:
hx watch build --exclude "generated/**"Polling Mode
Use polling instead of filesystem events (useful for network drives):
hx watch build --pollConfiguration
Configure watch behavior in hx.toml:
[watch]
# Clear terminal on each run
clear = true
# Debounce delay (ms)
debounce = 300
# Additional patterns to watch
include = ["config/**"]
# Patterns to exclude
exclude = [
"dist-newstyle/**",
".git/**",
"*.tmp"
]Workflows
Test-Driven Development
hx watch test- Write a failing test
- Save → tests run automatically
- Write implementation
- Save → tests run again
- See green tests
- Repeat
REPL-Like Development
hx watch run- Make changes to your application
- Save → app rebuilds and restarts
- See results immediately
Type-First Development
hx watch checkFaster feedback than full builds:
- Write function signatures
- Save → type errors shown
- Fill in implementations
- Save → type check again
Combined Workflows
Run checks, then tests if they pass:
# Using shell
watch -n 1 'hx check && hx test --match "fast"'Keyboard Controls
While in watch mode:
| Key | Action |
|---|---|
r | Force re-run |
Enter | Force re-run |
q | Quit watch mode |
Ctrl+C | Quit watch mode |
Performance Tips
Use Check for Fast Feedback
hx watch check is faster than hx watch build:
# Faster - type check only
hx watch check
# Slower - full compilation
hx watch buildExclude Generated Files
[watch]
exclude = ["generated/**", "dist-newstyle/**"]Adjust Debounce
Lower debounce for faster response:
[watch]
debounce = 100Higher debounce to batch rapid changes:
[watch]
debounce = 500Focus on Changed Areas
Run specific tests:
hx watch test -- --match "Parser"Integration with Editors
VS Code
HLS provides real-time feedback. Use watch mode for tests:
- Open integrated terminal
- Run
hx watch test - Keep terminal visible while editing
Vim/Neovim
Split terminal workflow:
:split | terminal hx watch testOr with tmux:
tmux split-window -h "hx watch test"Emacs
(defun hx-watch-test ()
(interactive)
(async-shell-command "hx watch test"))Troubleshooting
Changes Not Detected
Try polling mode:
hx watch build --pollCheck watched directories:
hx watch build --verboseToo Many Rebuilds
Increase debounce:
hx watch build --debounce 500Exclude noisy directories:
[watch]
exclude = ["logs/**", "tmp/**"]High CPU Usage
On some systems, filesystem watching can be intensive. Solutions:
Use polling with longer intervals:
hx watch build --pollReduce watched directories
Platform Notes
Linux
Uses inotify. May need to increase watch limit:
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf
sudo sysctl -pmacOS
Uses FSEvents. Generally works well.
Windows
Uses ReadDirectoryChangesW. May have issues with network drives—use --poll if needed.