Correct command to install pre-commit globally is,
Copy$ uv tool install pre-commit
$ which pre-commit
/home/username/.local/share/../bin/pre-commit
See official uv docs; The uv tool interface.
I Built a tool that auto-syncs pre-commit hook versions with `uv.lock`
How to install pre-commit globally with uv - Stack Overflow
How to use pre-commit in uv-based project?
What are your favourite pre-commit hooks and why?
Videos
» pip install pre-commit-uv
TL;DR: Auto-sync your pre-commit hook versions with uv.lock
# Add this to .pre-commit-config.yaml
- repo: https://github.com/tsvikas/sync-with-uv
rev: v0.3.0
hooks:
- id: sync-with-uvBenefits:
-
Consistent tool versions everywhere (local/pre-commit/CI)
-
Zero maintenance
-
Keeps pre-commit's isolation and caching benefits
-
Works with pre-commit.ci
The Problem
PEP 735 recommends putting dev tools in pyproject.toml under [dependency-groups]. But if you also use these tools as pre-commit hooks, you get version drift:
-
uv updatebumpsblackto25.1.0in your lockfile -
Pre-commit still runs
black==24.2.0 -
Result: inconsistent results between local tool and pre-commit.
What My Project Does
This tool reads your uv.lock and automatically updates .pre-commit-config.yaml to match.
Works as a pre-commit (see above) or as a one-time run: uvx sync-with-uv
Target Audience
developers using uv and pre-commit
Comparison
❌ Using manual updates?
-
Cumbersome
-
Easy to forget
❌ Using local hooks?
- repo: local
hooks:
- id: black
entry: uv run black-
Breaks pre-commit.ci
-
Loses pre-commit's environment isolation and tool caching
❌ Removing the tools from pyproject.toml?
-
Annoying to repeatedly type
pre-commit run black -
Can't pass different CLI flags (
ruff --select E501 --fix) -
Some IDE integration breaks (when it requires the tool in your environment)
-
Some CI integrations break (like the black action auto-detect of the installed version)
Similar tools:
-
sync_with_poetry- Poetry version -
sync-pre-commit-lock- PDM/Poetry plugin
Try it out: https://github.com/tsvikas/sync-with-uv
⭐ Star if it helps! Issues and PRs welcome. ⭐
Correct command to install pre-commit globally is,
Copy$ uv tool install pre-commit
$ which pre-commit
/home/username/.local/share/../bin/pre-commit
See official uv docs; The uv tool interface.
It's solvable by having a global python virtual env or installing pre-commit in whatever system python you happen to have.
I choose to have a dev virtual environment. I created it and then added pre-commit to that, so it's mostly there when I need it.
❯ . ~/.venv/dev/bin/activate
❯ uv pip install pre-commit
Using Python 3.10.12 environment at: /home/mike/.venv/dev
Resolved 9 packages in 197ms
Prepared 2 packages in 146ms
Installed 8 packages in 53ms
+ cfgv==3.4.0
+ distlib==0.3.9
+ filelock==3.17.0
+ identify==2.6.9
+ nodeenv==1.9.1
+ platformdirs==4.3.6
+ pre-commit==4.1.0
+ virtualenv==20.29.3