github jdx/hk v1.37.0
v1.37.0: Smarter Config, Hook-Level Env, and Better Fix/Check Semantics

11 hours ago

This release overhauls global configuration handling, adds hook-level environment variables, and fixes several correctness issues in check/fix workflows.

Highlights

Overhauled global config (hkrc) -- The global user configuration has been significantly reworked. hk now supports the full Config.pkl format in hkrc files (not just UserConfig.pkl), fixing a panic when using the documented example with hooks and steps. The recommended config location is now ~/.config/hk/config.pkl, with clear "project wins" merge semantics. The legacy .hkrc.pkl paths and --hkrc flag are deprecated and will be removed in v2. Thanks @ivy! #710

Hook-level env support -- Hooks can now define environment variables that are automatically passed to all their steps, reducing duplication when multiple steps need the same variables. Step-level env takes precedence over hook-level env. #709

check_diff correctness in check mode -- Previously, steps with check_diff defined would always run the diff command first, even in check mode. This could hide non-auto-fixable errors when the diff command exited 0. The diff-first shortcut is now gated to fix mode only. Thanks @nkakouros! #717

Added

  • Hook-level env: Define environment variables once per hook instead of repeating them on every step. Step-level env takes precedence when both define the same variable. (@jdx) #709

    hooks {
        ["pre-push"] {
            env {
                ["HK_PROFILES"] = "types"
            }
            steps = linters
        }
    }
  • Go-style diff parsing: hk now correctly handles unified diffs where the --- line has a .orig suffix (common with Go tools like gofmt -d). (@jdx, co-authored by @thejcannon) #704

  • XDG config directory support: Global configuration can now be placed at ~/.config/hk/config.pkl (or a custom path via HK_CONFIG_DIR). (@ivy) #710

  • Config precedence documentation: A clear precedence table and hkrc merge semantics are now documented, covering built-in defaults through CLI flags. (@ivy) #701 #710

Fixed

  • end-of-file-fixer now enforces that files end with exactly one trailing newline, matching pre-commit-hooks behavior. Previously it would add a missing newline but leave multiple trailing newlines untouched. (@jdx) #708

  • pre-commit with stash no longer passes untracked files to linters as input. Untracked files were incorrectly included in the unstaged files set, causing them to be processed during hk run pre-commit. Thanks @nkakouros! #716

  • check_diff in check mode no longer silently swallows errors. When a step defines check_diff, hk previously ran the diff command first in all modes. If the diff command exited 0 (no auto-fixable issues), non-auto-fixable violations detected by the regular check command were hidden. The diff-first shortcut is now only used in fix mode. Thanks @nkakouros! #717

  • hkrc format support: Global config files can now use the full Config.pkl format with hooks containing steps that have check, fix, and glob fields. Previously this caused a panic because hk always deserialized hkrc as UserConfig. (@ivy) #710

  • hkrc discovery path: Default hkrc discovery now correctly checks ~/.hkrc.pkl and ~/.config/hk/config.pkl, instead of only looking for .hkrc.pkl relative to the current directory. (@ivy) #710

  • --all flag documentation now correctly describes what the flag does. Thanks @nkakouros! #715

Deprecated

  • .hkrc.pkl and --hkrc flag are deprecated and will be removed in hk v2. Use ~/.config/hk/config.pkl for global configuration or hk.local.pkl in the project root for per-project overrides. Deprecation warnings are shown when legacy paths are used. #710

New Contributors

Full Changelog: v1.36.0...v1.37.0

Don't miss a new hk release

NewReleases is sending notifications on new releases.