Python hooks for Claude Code
Project description
python-claude
Python hooks for Claude Code for projects using:
- poetry
- ruff
- mypy
- pytest
The hooks ensure that the quality tools are automatically used:
Each time a file is edited:
- Reformat with
ruff format - Type-check with
mypy - Record the file
When claude is ready to stop:
- Repair lints of edited files with
ruff check --fix. (We do not do this while editing files, becaue it Claude tends to addimportstatements in a dedicated edit, ahead of adding the code that uses it. In this case,ruff check --fixwould erase the "unused" import.) - Run the tests with
pytest.
Installation
poetry add python-claude
Usage
This package provides hooks that can be used with Claude Code's hook system.
Available Commands
edited- Tracks edited Python files for deferred processinggit status- Shows git statusmypy- Runs mypy type checking on edited filespytest- Runs pytestruff check- Runs ruff check on collected files with auto-fixruff format- Runs ruff format on edited filessession start- Prints introductory message about automatic hooks
Claude Code Settings
Add hooks to your Claude Code settings.json:
{
"hooks": {
"SessionStart": [
{
"hooks": [
{
"type": "command",
"command": "poetry run python-claude session start"
},
{
"type": "command",
"command": "poetry run python-claude git status"
}
]
}
],
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "poetry run python-claude ruff check"
},
{
"type": "command",
"command": "poetry run python-claude pytest"
}
]
}
],
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "poetry run python-claude ruff format"
},
{
"type": "command",
"command": "poetry run python-claude edited"
},
{
"type": "command",
"command": "poetry run python-claude mypy"
}
]
}
]
}
}
Development
poetry install
poetry run pytest
poetry run ruff check
poetry run mypy src
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_claude-0.1.0.tar.gz.
File metadata
- Download URL: python_claude-0.1.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.13.3 Darwin/25.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c84bb87fc016ca528570fdd6f7dbd0d43e0417ea5723bfe76dc9bb1376db8f7e
|
|
| MD5 |
270bb761dca4fb00ad5817898e7d1748
|
|
| BLAKE2b-256 |
cfaab2403cf9a4a52ba6fbcd7e65e6373fa76521f635f77cd13da9d866c4aceb
|
File details
Details for the file python_claude-0.1.0-py3-none-any.whl.
File metadata
- Download URL: python_claude-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.13.3 Darwin/25.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
944080c5060b6805764ed107eb905447faca25b0d07415f0f8250d335ebfb362
|
|
| MD5 |
a2b30717db3a7309d1d2c95d11426001
|
|
| BLAKE2b-256 |
4192db7405393901398ebf17a63bf6b998119b21a1e8c86af84128de2a23dfa7
|