Skip to main content

python-claude

Python hooks for Claude Code for projects using:

  • uv
  • 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 the project with mypy (only if files were edited)
  • Run the tests with pytest (only if files were edited)

Note: We defer all quality checks 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. Quality checks only run when at least one Python file has been edited during the session.

Installation

uv 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
  • toggle <check> - Enable/disable a quality check (pytest, mypy, or ruff)

Claude Code Settings

Add hooks to your Claude Code settings.json:

{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "uv run python-claude session start"
          },
          {
            "type": "command",
            "command": "uv run python-claude git status"
          }
        ]
      }
    ],
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "uv run python-claude ruff format"
          },
          {
            "type": "command",
            "command": "uv run python-claude ruff check"
          },
          {
            "type": "command",
            "command": "uv run python-claude mypy"
          },
          {
            "type": "command",
            "command": "uv run python-claude pytest"
          }
        ]
      }
    ],
    "PostToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [
          {
            "type": "command",
            "command": "uv run python-claude edited"
          }
        ]
      }
    ]
  }
}

Toggling Quality Checks

You can temporarily disable quality checks when needed. This is useful when:

  • Tests are failing and you want to focus on type errors first
  • You want to make multiple changes before running checks
  • You're working on a feature that temporarily breaks tests

Using Slash Commands (Recommended)

The easiest way is to use the provided slash commands in Claude Code:

  • /pytest - Toggle pytest on/off
  • /mypy - Toggle mypy on/off
  • /ruff - Toggle ruff (format + check) on/off

Each command will show whether the check is now enabled or disabled.

Using CLI Directly

You can also use the CLI directly:

uv run python-claude toggle pytest
uv run python-claude toggle mypy
uv run python-claude toggle ruff

The toggle state persists across Claude Code sessions, stored in .claude/quality-checks.json (which is gitignored). All checks are enabled by default.

Development

uv sync
uv run pytest
uv run ruff check
uv run mypy src

Metadata

Release files for python-claude 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-claude 0.5.0
File Size Uploaded Provenance
python_claude-0.5.0.tar.gz 33.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for python-claude 0.5.0
File Interpreter ABI Platform
python_claude-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 47.6 kB

Release files / python_claude-0.5.0.tar.gz

Download URL python_claude-0.5.0.tar.gz
Size 33.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7e1dad8d4463cd512cda756d72dfa4e0f4635f7a111f845afe44280d3564ca6a
BLAKE2b-256 checksum
How to use checksums
aef62b20946fafcf9384195293dddd13be73ed78d757f41f9ce6df57b169068b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.4 {"installer":{"name":"uv","version":"0.11.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / python_claude-0.5.0-py3-none-any.whl

Download URL python_claude-0.5.0-py3-none-any.whl
Size 14.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
29a5f7af9c104e0329446c31c448b6d79015289f63ce91c9b6e617dbeb44ddd0
BLAKE2b-256 checksum
How to use checksums
c44d9add4532ca4c9b1a121870d188b7a8220364f167f510e4cbece079f0b8f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.4 {"installer":{"name":"uv","version":"0.11.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for python-claude 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page