Repository navigation
Conversation
Closes NomicFoundation#891 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: c9f915a The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This was referenced Oct 17, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #891.
This adds a watch mode to
hardhat build,hardhat test, andhardhat test solidity. Each command gets a--watch(-w) flag. With it, Hardhat runs the command, then runs it again each time a source, a test, or the config file changes. #891 asks for this and has 12 👍. It is also one of the first things people coming fromforge test --watchlook for.The feature wasn't discussed with the team first, so I'm happy to change the approach, the flag names, or where the code lives.
How it works
It is a new built-in plugin,
builtin:watch, that overrides the three tasks to add these arguments:--watch,-w--watch-delay--no-restart--run-allWithout
--watch, each override callsrunSuperand nothing changes.With
--watch, the parent process doesn't run the task. It watches the files with chokidar, which is already a dependency ofhardhat. For each run, it starts a newhardhatprocess with the same command line, minus the watch arguments. A new process per run means every run loads the current config, plugins, and sources, the same as typing the command again. Nothing is left cached between runs. Foundry does the same thing.buildandtest solidity), and the config file. Paths that don't exist are skipped. The artifacts and cache directories,node_modules, and.gitare ignored.--run-allturns this off. Test files or--grepgiven on the command line are kept on every run.--no-restartis set.areruns everything.q, Ctrl-C, or Ctrl-D quits. Input is passed to the child while a run is in progress.[Command was successful, lasted 3.57s](or the exit code), thenWatching N paths (sources, tests, and config) for changes. Press "a" to rerun everything, "q" to quit..watch: truethrows the new error HHE603 (WATCH_MODE_REQUIRES_CLI), because watch mode needs the command line it was started with.Tests
packages/hardhat/test/internal/builtin-plugins/watch/for argument handling, test file selection, the session state machine, the file watcher, and the task overrides (40 tests). I checked that they fail when the selection or restart logic is broken.pnpm build,pnpm lint, andpnpm testpass inpackages/hardhat(2922 passing) andpackages/hardhat-errors(38 passing).node scripts/check-dependencies.tspasses.forge test --watch1.8.1 on an equivalent Foundry project: narrowing to the changed test, a contract edit, several files at once, a compile error and its fix, a restart during a slow run,--no-restart,a,q, Ctrl-C (exit 0 and no processes left behind), a TypeScript test, a config change, a deleted file,--run-all,--grep,build --watch, andtest solidity --watch. Watch mode adds about 0.1 to 0.2 seconds per run.Differences from Foundry
--watch-delayis in milliseconds. Foundry's is in seconds.--watchtakes no list of paths. The paths come from the config.--rerun-failed.Docs: NomicFoundation/hardhat-website#314
🤖 Generated with Claude Code