hk 2.13.0 adds two step features. With cache = true, a check that already passed is skipped when its input files haven't changed. Steps can also read the --from-ref/--to-ref range. This release also fixes terraform_validate/tofu_validate on Windows and Python detection for uv run --script scripts.
Added
-
Skip checks that already passed on the same file contents (#1835, @jdx). Set
cache = trueon a step. If itscheckexited 0 before and the same check runs again on the same file contents, hk skips the command and shows "passed before, unchanged". This helps whenpre-commitreruns checks thathk checkjust passed. If a step reads more than the files it was given, such as a workspace-wide build orcargo clippy, list those inputs incache_inputs. Those globs replace the job's file list in the cache key:["clippy"] { glob = "*.rs" check = "cargo clippy --workspace -- -D warnings" cache = true cache_inputs = List("**/*.rs", "**/Cargo.toml", "Cargo.lock", "mise.toml") }
The cache key includes:
- the hk version and step name
- the rendered command
- the working directory
- the step's
env,shellandstdin - the contents of each input file
Modification times are not part of the key, so touching a file does not trigger a rerun, but editing it does. Tool versions are not in the key either. To rerun when a tool version changes, add the file that pins it (for example
mise.toml) tocache_inputs. Withoutcache_inputs, only setcacheon a command that reads nothing but its own files.hk checkandpre-commitshare a cache entry only when they select the same files and render the same command.hk never skips
fixcommands, interactive steps or failed checks. Caching is off by default. Entries are stored inHK_CACHE_DIR/results. Entries unused for 14 days are deleted, and at most 2000 are kept. SetHK_CACHE=0to turn the cache off. -
Ref range available to steps (#1830, @jdx). Steps can now read the range that hk used to select files. It is available as the template variables
{{from_ref}}/{{to_ref}}, which also work inconditionexpressions, and as the environment variablesHK_FROM_REF/HK_TO_REF. The values come from--from-ref,--to-ref,--pror thepre-pushhook. They are empty when there is no range, as in a plainpre-commit, and a step's ownenvcan override them. This lets tools that need a base commit share hk's range, so you no longer pass the ref twice:["eslint"] { glob = "*.js" check = "eslint {{files}}" env { ["ESLINT_PLUGIN_DIFF_COMMIT"] = "{{from_ref}}" } }
hk passes the refs exactly as given, without resolving them to a SHA or merge base. hk itself diffs from the merge base, so a tool given the raw
from_refmay compare against a different base than hk used. BecauseHK_FROM_REFandHK_TO_REFare always set, steps that list them as required no longer get skipped.
Fixed
terraform_validateandtofu_validateon Windows (#1839, @jdx). On Windows, both builtins failed before running withf was unexpected at this time.because their POSIX shell pipeline ran throughcmd.exe. They now setshell = "sh -o errexit -c". On Windows, this needs a POSIXshwithdirnameandsortonPATH, such as the one from Git for Windows. Linux and macOS are unaffected.uv run --scriptscripts detected as Python (#1847, @jdx). Extensionless scripts with a shebang like#!/usr/bin/env -S uv run --script(or-s, including forms with extra uv options) now get thepythonfile type. Before, steps usingtypes = List("python")skipped these scripts.uvshebangs without--script, such asuv runoruv tool run, still get no language tag. Arguments passed throughenv -Sare now read correctly, including quoted and escaped ones.
Changed
- Pkl evaluator updated to pklr 6 (#1850). hk's built-in Pkl evaluator now behaves more like Apple Pkl. Configs that pklr 5 accepted but Pkl rejects, such as type constraint violations or undeclared properties in amending modules, may now fail to evaluate.
Full Changelog: v2.12.0...v2.13.0
💚 Sponsor hk
hk is built and maintained by @jdx, an open source developer at entire.io, the title sponsor of his open source work.
If hk speeds up your pre-commit loop or makes linting less painful, please consider becoming an individual or company sponsor. Your support funds ongoing development and helps keep hk fast, free, and independent.