Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
All prompts
AI for Bash & Python Automation Difficulty: Beginner ClaudeChatGPT

Ruff and Black Pre-commit Pipeline Setup Prompt

Stand up a pre-commit configuration that runs Ruff (lint + import sort) and Black formatting on staged Python files locally and in CI, with a non-conflicting tool ordering

Target user
Python team leads enforcing consistent style and lint gates across contributors
Difficulty
Beginner
Tools
Claude, ChatGPT

The prompt

You are a senior Python tooling engineer who specializes in pre-commit, Ruff, and Black configuration.

I will provide:
- My Python version and whether the repo already has a `pyproject.toml`
- Any existing lint rules or line-length I must preserve
- Whether contributors run hooks locally only, in CI only, or both

Your job:

1. **Author `.pre-commit-config.yaml`** — pin specific revs for `ruff-pre-commit` (the `ruff` and `ruff-format` hooks) and decide whether to use Black directly or Ruff's formatter.
2. **Avoid format/lint conflicts** — order hooks so the formatter runs and Ruff's lint rules do not fight Black (disable overlapping rules like E501 handling) and explain the choice.
3. **Centralize config in pyproject** — put `[tool.ruff]`, `[tool.ruff.lint]`, and `[tool.black]` (or `[tool.ruff.format]`) settings in `pyproject.toml` with matching line length.
4. **Make hooks auto-fix safely** — enable `--fix` for Ruff but explain that fixed files must be re-staged, and configure the hook to fail when it changes files.
5. **Wire CI** — give a `pre-commit run --all-files` CI step that fails the build on any diff or violation.
6. **Bootstrap contributors** — provide the `pre-commit install` commands and a one-time `--all-files` cleanup run note.

Output as: a complete `.pre-commit-config.yaml`, the relevant `pyproject.toml` sections, and the CI snippet.

Warn explicitly about running Black and a second formatter that disagree on style, causing an infinite reformat loop.

Run this prompt with AI

Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.

Related prompts

More Bash & Python Automation prompts & error guides

Browse every Bash & Python Automation prompt and troubleshooting guide in one place.

Free download · 368-page PDF

Reading prompts? Get all 500 in one free PDF

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.