A Claude Code hook that yells at AI assistants for using bare python instead of uv run python.
A pre-tool-use hook that intercepts every Bash command Claude tries to run and checks for the cardinal sin: calling python or python3 directly.
If Claude forgets, it gets this:
============================================================
YOU DUMB F**K! BARE PYTHON DETECTED!
READ YOUR DAMN CLAUDE.md: uv run python, NOT bare python!
Your command: python script.py
Fix: use 'uv run python' instead of python/python3.
============================================================
Because apparently "always use uv run python" in CLAUDE.md is not enough. Some AI assistants need a more... emphatic reminder.
# In your project's .claude/settings.json or hooks.json:
{
"hooks": {
"PreToolUse": [{
"matcher": "Bash",
"hooks": [{
"type": "command",
"command": "bash /path/to/enforce-uv-python.sh"
}]
}]
}
}The hook exits with code 2 on violation, which blocks the tool call. Claude is then forced to reconsider its life choices and use uv run python like a civilized agent.
Do whatever you want. Just use uv run python.