Skip to main content
hooksSource-backedReview first Safety Privacy

Python Linter Integration - Hooks

Claude Code PostToolUse hook recipe that runs an installed Python linter after Write/Edit tool calls touch a .py file.

by JSONbored·added 2025-09-19·
HarnessClaude Code
Trigger:PostToolUse
Review first review before installing

Open the source and read safety notes before installing.

Citation facts

Source-backed facts for citing this resource, derived directly from the registry — also available as plain text for AI assistants.

Source URLs
https://code.claude.com/docs/en/hooks, https://github.com/JSONbored/awesome-claude/blob/main/content/hooks/python-linter-integration.mdx
Safety notes
Hooks run local shell commands automatically after matching tool calls; review the script before enabling it in a shared repository., The hook executes whichever supported linter is first available on PATH and can fail the hook if that linter exits non-zero., Project-level hooks in .claude/settings.json are shared through git, so treat hook configuration as executable project policy.
Privacy notes
The hook reads the edited Python file path from Claude Code's hook JSON input and passes that path to local lint tools., Lint output may include source lines, file paths, comments, TODOs, and other local code details in the Claude Code session.
Author
JSONbored
Claim status
unclaimed
Last verified
2025-09-19

Decision playbook

Review trust signals before you adopt

Signals are present but mixed. Use the checklist below to confirm the source and operational safety for your environment.

Compare context
Selected

0

Current score

78

Baseline

Delta

No baseline selected

No major trust-signal divergence detected in the current selection.

Source and provenance checks

Complete

Confirm ownership and provenance before trusting install instructions.

  • Source link availableRequired

    Open the canonical repository and verify ownership.

    Done
  • Source provenance statusRequired

    Marked as source-backed.

    Done
  • Metadata reviewed

    Registry metadata indicates a reviewed listing.

    Done

Safety and privacy checks

Complete

Validate risk disclosures before installation or API wiring.

  • Safety notes presentRequired

    Review the listed safety guidance before running commands.

    Done
  • Privacy notes presentRequired

    Review data handling notes before connecting accounts or secrets.

    Done
  • Trust level risk gateRequired

    Trust level does not block evaluation.

    Done

Package and install checks

Needs review

Check package metadata and artifact integrity signals.

  • Install payload available

    Install or copy payload is available for review.

    Done
  • Package verification flag

    No package verification flag provided.

    Pending
  • Checksum metadata

    No checksum provided for downloaded artifact.

    Pending

Compare-driven decision checks

Needs review

Use compare context to validate trade-offs before adoption.

  • Compare tray has multiple entries

    Add at least one more entry to compare trust differences.

    Pending
  • Baseline comparison available

    No baseline peer selected yet.

    Pending
  • Diverging trust signals identified

    No major trust-signal divergence found.

    Pending

Setup at a glance

CLI install

Copy-ready — paste the snippet to get started.

Install command

Provided

Config snippet

Provided

Copy snippet

Provided

Prerequisites

None

Platforms

1 listed

Difficulty

20/100

Adoption plan

Balanced adoption plan

Current risk score 16/100. Use staged verification before broader rollout.

Risk 16

Pre-adoption checks

Validate source and review signals before any execution.

  • Confirm source provenanceRequired

    Source URL/provenance metadata is present.

    Done
  • Confirm metadata review state

    Listing has review metadata.

    Done
  • Verify install payload

    Install/config payload exists and can be inspected.

    Done

Security checks

Confirm safety, privacy, and package integrity signals.

  • Review safety notesRequired

    Safety notes are present.

    Done
  • Review privacy notesRequired

    Privacy notes are present.

    Done
  • Verify package integrity metadata

    No package verification/checksum metadata.

    Pending

Rollout

Adopt in controlled steps based on the selected plan.

  • Run in isolated sandbox firstRequired

    Use a constrained sandbox and observe behavior across multiple tasks.

    Pending
  • Roll out graduallyRequired

    Roll out to a small cohort before wider usage.

    Pending
  • Set monitoring and fallback

    Define rollback path and monitor errors after adoption.

    Pending

Evidence readiness

Evidence readiness matrix · balanced

Required evidence gates are covered (5/6 signals complete).

Risk 15

Source provenance

Present

Source repository/provenance is listed.

Required in this preset

Metadata review

Present

Review metadata is present.

Required in this preset

Safety notes

Present

Safety notes are present.

Required in this preset

Privacy notes

Present

Privacy notes are present.

Optional in this preset

Package integrity

Missing

Package integrity metadata is missing.

Optional in this preset

Install payload

Present

Install payload is available.

Required in this preset

Required evidence gates are covered for this preset.

Decision timeline

Decision timeline · balanced

5/6 steps complete with no blocking gaps for this preset.

Risk 14

triage

Confirm source provenanceRequired

Source/provenance metadata is available.

Done

triage

Check metadata review statusRequired

Review metadata is available.

Done

verify

Review safety notesRequired

Safety notes are available.

Done

verify

Review privacy notes

Privacy notes are available.

Done

verify

Validate package integrity metadata

Package integrity metadata is missing.

Pending

rollout

Verify install payload and commandsRequired

Install payload is available.

Done

No required blockers for this timeline preset.

Safety & privacy surface

Safety & privacy surface

3 safety and 2 privacy notes across 4 risk areas. Review closely: credentials & tokens.

4 areas
  • SafetyExecution & processesHooks run local shell commands automatically after matching tool calls; review the script before enabling it in a shared repository.
  • SafetyLocal filesThe hook executes whichever supported linter is first available on PATH and can fail the hook if that linter exits non-zero.
  • SafetyGeneralProject-level hooks in .claude/settings.json are shared through git, so treat hook configuration as executable project policy.
  • PrivacyLocal filesThe hook reads the edited Python file path from Claude Code's hook JSON input and passes that path to local lint tools.
  • PrivacyCredentials & tokensLint output may include source lines, file paths, comments, TODOs, and other local code details in the Claude Code session.

Safety notes

  • Hooks run local shell commands automatically after matching tool calls; review the script before enabling it in a shared repository.
  • The hook executes whichever supported linter is first available on PATH and can fail the hook if that linter exits non-zero.
  • Project-level hooks in .claude/settings.json are shared through git, so treat hook configuration as executable project policy.

Privacy notes

  • The hook reads the edited Python file path from Claude Code's hook JSON input and passes that path to local lint tools.
  • Lint output may include source lines, file paths, comments, TODOs, and other local code details in the Claude Code session.

Schema details

Install type
cli
Reading time
4 min
Difficulty score
20
Troubleshooting
Yes
Breaking changes
No
Skill and platform metadata
Retrieval sources
https://code.claude.com/docs/en/hookshttps://code.claude.com/docs/en/hooks-guidehttps://pylint.readthedocs.io/en/stable/user_guide/usage/run.htmlhttps://flake8.pycqa.org/en/latest/user/invocation.htmlhttps://pycodestyle.pycqa.org/en/latest/intro.html
Runtime and command metadata
Trigger
PostToolUse
Script language
bash
Script body
#!/usr/bin/env bash
set -euo pipefail

INPUT="$(cat)"
FILE_PATH="$(printf '%s' "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // empty')"

if [ -z "$FILE_PATH" ] || [ "${FILE_PATH##*.}" != "py" ]; then
  exit 0
fi

if [ ! -f "$FILE_PATH" ]; then
  echo "Python linter hook skipped: file not found: $FILE_PATH"
  exit 0
fi

if command -v pylint >/dev/null 2>&1; then
  pylint "$FILE_PATH" --score=yes --reports=no --msg-template="{line}:{column}: {category}: {msg} ({symbol})"
elif command -v flake8 >/dev/null 2>&1; then
  flake8 "$FILE_PATH" --max-line-length=88
elif command -v pycodestyle >/dev/null 2>&1; then
  pycodestyle "$FILE_PATH" --max-line-length=88
else
  echo "Python linter hook skipped: install pylint, flake8, or pycodestyle."
fi
Full copyable content
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [
          {
            "type": "command",
            "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/python-linter-integration.sh"
          }
        ]
      }
    ]
  }
}

About this resource

This hook runs after Claude Code successfully uses a matching file-editing tool. It checks only edited .py files and uses the first available linter in this order: pylint, flake8, then pycodestyle.

It does not install a linter for you, aggregate multiple tools, run ruff, or calculate historical quality trends. Install and configure the linter you want the hook to use before enabling it.

Installation

Create the hook script:

mkdir -p .claude/hooks
touch .claude/hooks/python-linter-integration.sh
chmod +x .claude/hooks/python-linter-integration.sh

Save the script from this entry to .claude/hooks/python-linter-integration.sh.

Add this to .claude/settings.json for a project-wide hook, or to ~/.claude/settings.json for a personal hook:

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [
          {
            "type": "command",
            "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/python-linter-integration.sh"
          }
        ]
      }
    ]
  }
}

Hook Script

#!/usr/bin/env bash
set -euo pipefail

INPUT="$(cat)"
FILE_PATH="$(printf '%s' "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // empty')"

if [ -z "$FILE_PATH" ] || [ "${FILE_PATH##*.}" != "py" ]; then
  exit 0
fi

if [ ! -f "$FILE_PATH" ]; then
  echo "Python linter hook skipped: file not found: $FILE_PATH"
  exit 0
fi

if command -v pylint >/dev/null 2>&1; then
  pylint "$FILE_PATH" --score=yes --reports=no --msg-template="{line}:{column}: {category}: {msg} ({symbol})"
elif command -v flake8 >/dev/null 2>&1; then
  flake8 "$FILE_PATH" --max-line-length=88
elif command -v pycodestyle >/dev/null 2>&1; then
  pycodestyle "$FILE_PATH" --max-line-length=88
else
  echo "Python linter hook skipped: install pylint, flake8, or pycodestyle."
fi

Requirements

  • Claude Code with hooks enabled.
  • jq available on PATH so the script can read hook input JSON.
  • At least one supported linter installed: pylint, flake8, or pycodestyle.

Source Verification Notes

Verified on 2026-06-19:

  • Claude Code hooks are user-defined shell commands, HTTP endpoints, or prompts that run at lifecycle events such as PostToolUse.
  • The hooks reference documents command hooks receiving JSON on stdin and using matcher groups to narrow which tool calls trigger a handler.
  • This entry combines that hook mechanism with documented Python linter command invocations. The hook itself is a local recipe, not an official bundled hook.

Troubleshooting

  • If the hook never fires, confirm the event key is PostToolUse and the matcher covers the edit tool names used by your Claude Code version.
  • If the hook fires but skips every file, inspect the hook input shape and adjust the jq path for the edited file.
  • If lint output is too noisy, configure the selected linter with its normal project config file instead of adding more logic to the hook.

Source citations

Add this badge to your README

Show that Python Linter Integration - Hooks is listed on HeyClaude. Paste this Markdown into your README — it renders the badge and links back to this page.

Listed on HeyClaude
[![Listed on HeyClaude](https://heyclau.de/badge/hooks/python-linter-integration.svg)](https://heyclau.de/entry/hooks/python-linter-integration)

How it compares

Python Linter Integration - Hooks side by side with 3 alternatives on trust, install, platform support, and disclosed safety notes — all from reviewed registry metadata.

Next steps differ across entries — use the actions in the table below to copy install commands and source links per resource.

Field

Claude Code PostToolUse hook recipe that runs an installed Python linter after Write/Edit tool calls touch a .py file.

Open dossier

A PostToolUse hook that reminds you to enable native query logging for PostgreSQL, Prisma, Sequelize, and TypeORM, and flags possible N+1 patterns when you edit SQL or data-access files.

Open dossier

Lints Vue 3 components for Composition API best practices and common issues.

Open dossier

A Claude Code hook that flags files exceeding complexity thresholds after you edit them — estimating cyclomatic complexity, line and function counts, and nesting depth (via ESLint's complexity rule and Radon).

Open dossier
Next stepsDiffers
Trust
Review statusReviewedMaintainer reviewedReviewedMaintainer reviewedReviewedMaintainer reviewedReviewedMaintainer reviewed
Package trustPackage not verifiedPackage not verifiedPackage not verifiedPackage not verified
Source provenanceSource-backedSource-backedSource-backedSource-backed
Submitter
Install riskReview firstReview firstReview firstReview first
Notes Safety Privacy Safety Privacy Safety Privacy Safety Privacy
Brand
Categoryhookshookshookshooks
Sourcesource-backedsource-backedsource-backedsource-backed
AuthorJSONboredJSONboredJSONboredJSONbored
Added2025-09-192025-10-192025-09-192025-09-19
Platforms
Claude Code
Claude Code
Claude Code
Claude Code
Source repo
Safety notesHooks run local shell commands automatically after matching tool calls; review the script before enabling it in a shared repository. The hook executes whichever supported linter is first available on PATH and can fail the hook if that linter exits non-zero. Project-level hooks in .claude/settings.json are shared through git, so treat hook configuration as executable project policy.Runs automatically after bash, write, or edit activity and inspects files that look like query, model, repository, DAO, or SQL files. Creates .claude/logs/query-performance.log and appends database command or file-analysis events. Uses grep-based heuristics for query warnings and should not be treated as proof of a performance defect.Runs automatically on its configured Claude Code hook event and executes shell logic that can read, modify, or delete files in your project (and may run builds, installs, or network calls); review the script and scope it to expected paths before enabling.Runs after edits to JS/TS/Python files and prints advisory warnings only; the line/function/brace counts are heuristics, not a substitute for ESLint or Radon run on the full project.
Privacy notesThe hook reads the edited Python file path from Claude Code's hook JSON input and passes that path to local lint tools. Lint output may include source lines, file paths, comments, TODOs, and other local code details in the Claude Code session.Reads query-related source files and may print file paths, query patterns, and database command strings to local hook output. Stores analyzed file paths and database command text in .claude/logs/query-performance.log. Database command text may include connection names, database names, or other operational details if typed directly into the command.Receives Claude Code hook input (session metadata, file paths, and tool output) and reads local project files; review what the script logs or forwards to external services and keep credentials out of its output.Reads the contents of files you edit to compute complexity locally; it prints warnings to hook output and does not transmit code, but those messages can reveal file structure.
Prerequisites— none listed— none listed— none listed— none listed
Install
mkdir -p .claude/hooks && touch .claude/hooks/python-linter-integration.sh && chmod +x .claude/hooks/python-linter-integration.sh
mkdir -p .claude/hooks && touch .claude/hooks/vue-composition-api-linter.sh && chmod +x .claude/hooks/vue-composition-api-linter.sh
mkdir -p .claude/hooks && touch .claude/hooks/code-complexity-alert-monitor.sh && chmod +x .claude/hooks/code-complexity-alert-monitor.sh
Config
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [
          {
            "type": "command",
            "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/python-linter-integration.sh"
          }
        ]
      }
    ]
  }
}
{
  "hooks": {
    "postToolUse": {
      "script": "./.claude/hooks/database-query-performance-logger.sh",
      "matchers": [
        "bash",
        "write",
        "edit"
      ]
    }
  }
}
{
  "hooks": {
    "postToolUse": {
      "script": "./.claude/hooks/vue-composition-api-linter.sh",
      "matchers": [
        "write",
        "edit"
      ]
    }
  }
}
{
  "hooks": {
    "notification": {
      "script": "./.claude/hooks/code-complexity-alert-monitor.sh"
    }
  }
}
Citations
ClaimUnclaimedUnclaimedUnclaimedUnclaimed
Open 4 picks in the interactive comparison tool

Related guides

Signals

Loading live community signals…

More like this, weekly

A short, calm digest of reviewed Claude resources. Unsubscribe any time.