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:

  • 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 add import statements in a dedicated edit, ahead of adding the code that uses it. In this case, ruff check --fix would 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 processing
  • git status - Shows git status
  • mypy - Runs mypy type checking on edited files
  • pytest - Runs pytest
  • ruff check - Runs ruff check on collected files with auto-fix
  • ruff format - Runs ruff format on edited files
  • 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 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


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.1.1.tar.gz (5.1 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.1.1-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: python_claude-0.1.1.tar.gz
  • Upload date:
  • Size: 5.1 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.1.1.tar.gz
Algorithm Hash digest
SHA256 635c619894a2ab09243ddb353dd1cb7958df08ef11102b5708a9b303a7030209
MD5 6c5e21e9928a93ca5b41e937b30a577c
BLAKE2b-256 220cf292f6865fca06bd5d219ff9b9109bfe3bd1668a4adc65d34448b014fd4a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_claude-0.1.1-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

Hashes for python_claude-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9f3c1a44be71cfd50f2a24b89c3a58b54c86c00b215733a5b48676fb8773c02f
MD5 148c969168f55871950942a8106837af
BLAKE2b-256 3b32eb1af44e80b2d853b02ba246bdea42bfd1359b4f09e2a813a9b36e8dc9a1

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