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:
- Record the file for later processing
When Claude is ready to stop:
- Reformat edited files with
ruff format - Repair lints of edited files with
ruff check --fix - Type-check edited files with
mypy - Run the tests with
pytest
Note: We defer ruff format and ruff check until Claude stops to avoid changing files while Claude is working. Changing files during editing would spoil Claude's edits and force it to reread files.
Installation
Option 1: Plugin Installation (Recommended)
Install as a Claude Code plugin for automatic hook configuration:
-
First, add this package to your project:
poetry add python-claude
-
Install as a Claude Code plugin:
claude plugin install /path/to/python-claude
-
Restart Claude Code to activate the hooks
The plugin automatically configures all necessary hooks - no manual settings.json configuration needed!
Option 2: Manual Installation
If you prefer manual configuration:
-
Add to your project:
poetry add python-claude
-
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 format" }, { "type": "command", "command": "poetry run python-claude ruff check" }, { "type": "command", "command": "poetry run python-claude mypy" }, { "type": "command", "command": "poetry run python-claude pytest" } ] } ], "PostToolUse": [ { "matcher": "Write|Edit", "hooks": [ { "type": "command", "command": "poetry run python-claude edited" } ] } ] } }
Available Commands
edited- Tracks edited Python files for deferred processing (used in PostToolUse hook)git status- Shows git statusmypy- Runs mypy type checking on edited files (used in Stop hook)pytest- Runs pytestruff check- Runs ruff check on collected files with auto-fix (used in Stop hook)ruff format- Runs ruff format on collected files (used in Stop hook)session start- Prints introductory message about automatic hooks
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.4.0.tar.gz.
File metadata
- Download URL: python_claude-0.4.0.tar.gz
- Upload date:
- Size: 5.9 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 |
66a81f9cc0ab3bca954d541e498e1bbbfaa486153b6bb35f5c9d67ab6d7a899c
|
|
| MD5 |
9d3135151f1dbff6624730959b29dc0e
|
|
| BLAKE2b-256 |
2fa764e914b87ab81f2c6d1d53ac0a0da4ba6b0ef92eb3a11131c4772c4cc3bc
|
File details
Details for the file python_claude-0.4.0-py3-none-any.whl.
File metadata
- Download URL: python_claude-0.4.0-py3-none-any.whl
- Upload date:
- Size: 11.1 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 |
00d2cb35f9bb07d3e6fa0ce437ea0f2d598c22da25107aa8ea0aab85680daa2c
|
|
| MD5 |
2038110ea0a899ff179ec6ce7eaa3ce3
|
|
| BLAKE2b-256 |
274d335602b1254ebead8124a50256099067a4b7d80825db3743eb9c08b217b7
|