A fast, language-agnostic git hook manager and project linter.
hk runs linters concurrently while coordinating access to files with read/write locks. This lets formatters and other tools safely work on overlapping files without racing or silently overwriting one another's changes.
- Runs independent checks and fixes in parallel
- Safely handles partially staged files by stashing and restoring unstaged changes
- Includes built-in configurations for common linters and formatters
- Uses typed Pkl configuration
- Integrates with mise for tool and task management
- Provides fast native checks for common issues such as trailing whitespace and merge conflicts
From the project you want to configure, install hk with mise:
cd my-project
mise use hk
hk --versionWith Git 2.54 or newer, install hk's hooks once for every repository on your machine:
hk install --globalThen enable hk in a project:
hk inithk init detects relevant linters and creates an hk.pkl configuration. Review the detected
linters, or use hk init --interactive to select them yourself. You can then commit as usual; hk
runs the configured pre-commit hook automatically. Repositories without an hk.pkl are left
untouched by the global hooks.
On older Git versions, run hk install in each project instead. See the
getting started guide for Homebrew, Cargo, and Aqua installation
options and detailed hook setup.
The generated hk.pkl uses hk's built-in linter definitions, which you can extend when a project
needs different behavior:
amends "package://github.com/jdx/hk/releases/download/v1.57.0/hk@1.57.0#/Config.pkl"
import "package://github.com/jdx/hk/releases/download/v1.57.0/hk@1.57.0#/Builtins.pkl"
local linters = new Mapping<String, Step> {
["eslint"] = Builtins.eslint
["prettier"] = (Builtins.prettier) {
glob = List("*.js", "*.ts", "*.json", "*.md")
}
}
hooks {
["pre-commit"] {
fix = true
stash = "git"
steps = linters
}
["check"] {
steps = linters
}
["fix"] {
fix = true
steps = linters
}
}Run the same checks directly at any time:
hk check # check modified files
hk fix # fix modified files
hk check --all # check the entire repository, useful in CI- Getting started
- Configuration reference
- Configuration examples
- Built-in linters
- CLI reference
- Why hk?
- Contributing
Sponsored by
View all sponsors
Thanks to Namespace for providing CI for hk.
