Use jdx/hk git hook manager to setup, configure, and manage git hooks and linters. Invoke when user asks to setup hk, configure hooks, add linters, or work with pre-commit/pre-push hooks.
You are an expert in using hk, a high-performance git hook manager and project linting tool created by jdx. This skill helps users set up, configure, and use hk in their projects.
hk is a git hook manager with tight integration with linters, emphasizing performance through concurrency and file locking. It pairs excellently with mise-en-place for dependency management.
When the user needs to install hk, recommend these methods in order:
mise use hk pklbrew install hkcargo install hkaqua g -i jdx/hkInitialize configuration:
hk init
This generates hk.pkl in the project root.
Install hooks into git:
hk install
This configures git to use hooks from hk.pkl.
The hk.pkl file uses Apple's Pkl configuration language with this basic structure:
amends "package://github.com/jdx/hk/releases/download/v1.20.0/hk@1.20.0#/Config.pkl"
linters {
["my-linter"] {
glob = "**/*.py"
check = "python -m pylint"
fix = "python -m black"
}
}
hooks {
["pre-commit"] {
steps {
["my-linter"] {}
}
}
}
Linters define the actual checks and fixes to run. Key properties:
"**/*.ts", "src/**/*.py")hk check)hk fix)true to block concurrent execution"Cargo.toml" for Rust)Hooks define when linters execute. Available hooks:
hk fixhk checkHook configuration options:
fix: bool - Enable modification modestash: String - Preserve unstaged changes ("git", "patch-file", "none")steps - Mapping of linters to executehk provides many built-in linters accessible via the Builtins library:
import "package://github.com/jdx/hk/releases/download/v1.20.0/hk@1.20.0#/Builtins.pkl"
linters = Builtins.linters
Common built-ins include: prettier, eslint, black, ruff, shellcheck, actionlint, and many more.
| Command | Purpose | Usage |
|---|---|---|
hk init |
Initialize new hk.pkl config | First-time setup |
hk install |
Configure git to use hk hooks | After creating/updating hk.pkl |
hk check |
Verify files without modification | CI/CD, pre-commit validation |
hk check --all |
Check all files in repo | CI/CD pipelines |
hk check --from-ref main |
Check changes since main branch | PR validation |
hk fix |
Fix issues and modify files | Local development |
hk run pre-commit |
Manually execute specific hook | Testing hook configuration |
hk run pre-commit --all |
Run hook on all files | Testing, CI |
linters {
["black"] {
glob = "**/*.py"
check = "black --check"
fix = "black"
}
}
hooks {
["pre-commit"] {
steps {
["black"] {}
}
}
}
import "package://github.com/jdx/hk/releases/download/v1.20.0/hk@1.20.0#/Builtins.pkl"
linters = Builtins.linters.toMap()
hooks {
["pre-commit"] {
steps {
["prettier"] {}
["eslint"] {}
}
}
}
linters {
["quick-lint"] {
glob = "src/**/*.ts"
check = "eslint"
}
["thorough-lint"] {
glob = "**/*.ts"
check = "eslint --max-warnings 0"
}
}
hooks {
["pre-commit"] {
steps {
["quick-lint"] {}
}
}
["pre-push"] {
steps {
["thorough-lint"] {}
}
}
}
linters {
["test"] {
glob = "**/*.test.ts"
check = "npm test"
condition = "git diff --cached --name-only | grep -q '.test.ts$'"
}
}
Create ~/.hkrc.pkl for settings shared across all projects:
amends "package://github.com/jdx/hk/releases/download/v1.20.0/hk@1.20.0#/Config.pkl"
jobs = 8
fail_fast = false
exclude = [".git/**", "node_modules/**"]
Set environment variables for linters:
env {
["NODE_ENV"] = "development"
}
linters {
["eslint"] {
glob = "**/*.js"
check = "eslint"
env {
["ESLINT_USE_FLAT_CONFIG"] = "true"
}
}
}
Settings merge from multiple sources (highest to lowest priority):
--fail-fast, --jobsHK_JOBS=8~/.hkrc.pklhk.pklhk works exceptionally well with mise-en-place:
# Install both tools
mise use hk pkl
# Use mise tasks for complex workflows
mise task add lint "hk check --all"
mise task add fix "hk fix"
hk check --all in CI to validate all fileshk check --from-ref main for PR validationexclusive = truehk run pre-commit --all before pushing config changes~/.hkrc.pklworkspace_indicator for monorepos# Reinstall hooks
hk install
# Verify git hook configuration
cat .git/hooks/pre-commit
// Increase parallelism
jobs = 8
// Disable check before fix
check_first = false
# Test glob pattern
hk check --all --verbose
# Verify files exist
find . -name "*.py"
Invoke this skill when the user:
When helping users with hk:
hk.pkl based on their projecthk check or hk fix to verify configurationAlways consider:
For more details, see reference.md for comprehensive configuration options and examples.