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