Skip to main content

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

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 processing (used in PostToolUse hook)
  • git status - Shows git status
  • mypy - Runs mypy type checking on edited files (used in Stop hook)
  • pytest - Runs pytest
  • ruff 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

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 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"
          }
        ]
      }
    ]
  }
}

Development

poetry install
poetry run pytest
poetry run ruff check
poetry run mypy src

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_claude-0.3.2.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_claude-0.3.2-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file python_claude-0.3.2.tar.gz.

File metadata

  • Download URL: python_claude-0.3.2.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.13.3 Darwin/25.1.0

File hashes

Hashes for python_claude-0.3.2.tar.gz
Algorithm Hash digest
SHA256 693ab32490a5f76651f47b0ea2058b9f4b02667d9eee74895562d4ec1fdd0288
MD5 4ed3d57ce6daeda3f3f7c09dc28555f2
BLAKE2b-256 08288074d26b7e9da5df0329bad3d60365b066c83c286b2dc5745219a0fd2117

See more details on using hashes here.

File details

Details for the file python_claude-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: python_claude-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 10.6 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

Hashes for python_claude-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5b3c458746df728074f4b7f9297fdb887ad906f960f17da21f13f77fca31bca9
MD5 6f9f18e39befd746388cf57ef3c09532
BLAKE2b-256 1bdc277b53ca6b02057536d0d41c18ccab647fff52845b4c7a4363ec1c2e9e65

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page