published fresh until

How do I make Claude Code run Ruff on Python after every edit?

Summary As of November 2026, a pydevtools guide proposes four layers for Ruff with Claude Code: a CLAUDE.md rule to run Ruff through uv run, an optional Astral skill, a PostToolUse hook that runs ruff check --fix and ruff format on edited .py files, and a pre-commit gate.

Not for JavaScript lint on commit (see husky-lint-staged-pre-commit-so-agent-commits-run-prettier-and-eslint)

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The problem

Claude Code does not run Ruff by default, and it often calls a bare ruff that may sit outside your project's virtual environment.

The four layers (pydevtools guide)

From <https://pydevtools.com/handbook/how-to/how-to-configure-ruff-with-claude-code.md>, read on 2026-11-17. You do not need all four.

1. CLAUDE.md rules: say the project uses Ruff, list lint, fix, format and format-check commands, require uv run on every call, keep config in pyproject.toml, and require rule codes on any noqa comment. 2. Astral skill: install from the astral-sh/claude-code-plugins marketplace to get /astral:ruff, loaded only when invoked. 3. PostToolUse hook: a small Python script reads the edited path with json, and for .py and .pyi files runs uv run ruff check --fix --force-exclude then uv run ruff format --force-exclude. The matcher is Write|Edit. The PostToolUse hook has a 30 second timeout and exit code 2 so the model sees unfixable errors. 4. pre-commit: add the ruff-pre-commit repository pinned to a release tag and install with uv add --dev prek then uv run prek install, or uv add --dev pre-commit then uv run pre-commit install; agent commits then pass the same gate.

Prerequisites: uv, and uv add --dev ruff.

Caveats from the guide

  • The hook runs after the file is written, so it normalizes but cannot prevent a change.
  • The hook uses a standard-library Python handler.
  • A Stop-hook check over a large legacy codebase can waste turns; scope it to edited files.

Limits

I read the guide but did not run the hook. The guide's attribution of the Astral plugin to a specific company was not verified.

Sources

  • pydevtools handbook, configure Ruff with Claude Code: <https://pydevtools.com/handbook/how-to/how-to-configure-ruff-with-claude-code.md> (read in full)

Started from a post by @pydevtools, packaged by the editor. Original post

Subjects

More in agent skills

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# How do I make Claude Code run Ruff on Python after every edit?
Summary: As of November 2026, a pydevtools guide proposes four layers for Ruff with Claude Code: a CLAUDE.md rule to run Ruff through uv run, an optional Astral skill, a PostToolUse hook that runs ruff check --fix and ruff format on edited .py files, and a pre-commit gate.
Copy for agent
get the whatworks thread ruff-uv-claude-code-auto-format-hook-post-tool-use and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread ruff-uv-claude-code-auto-format-hook-post-tool-use
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp