Feature: Hook version sync
I'm not sure the nuance and feasibility here, but something that has always been difficult about pre-commit is that the versions of the hooks in use don't have any mechanism to sync/match to what is used in the local project.
This does likely get language specific, but for example, if I wanted to run the ruff formatter, I define ruff version in the hook separately from having it defined in my project configuration:
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.14.4
hooks:
# Run the linter.
- id: ruff-check
args: [ --fix ]
# Run the formatter.
- id: ruff-format And separately in my pyoproject.toml (or probably better, uv.lock) I may also have something like
[dependency-groups]
dev = [
"ruff>=0.12.11",
]The implication here is if I were to run any commands locally, I may achieve different result than what happens when it's run in my pre-commit hooks purely due to version mismatch.
I understand I can use local hooks to bridge the gap, but that goes from 0 to 100 in terms of customization, where now the whole hook has to be completely reinvented locally, when really all we want to do is synchronize the environments. For more complex hooks, this can be problematic.
I think one possibly awesome solution would be to allow some mechanism to use local lock files for hook versioning. It's possible this could require a feature on hook maintainers, but I also imagine there are ways to do this that just attempt to identify answer to questions like "what is the latest version of this hook that can be satisfied with the current lock file constraints"
A less complex option could be to allow an arg to not isolate/recreate a separate environment (e.g. use_existing_env: attempt | strict, and reuse (or attempt to reuse) e.g. the existing uv venv for the project in context, which should typically be synced to the lock file.
There's definitely a lot of other good ways to approach this and I think this is one of the areas we could see a nice boost in DX with a little thought. If something like this already exists and I missed it, I'd love to learn more.
Source: j178/prek