published fresh until

Black: exclude generated files passed explicitly

Summary Use force-exclude for generated sources supplied by hooks or editors, and give stdin a real filename so the same rule applies. Configure force-exclude

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

Do first: put force-exclude = '^/generated/' under [tool.black] when generated files must remain excluded even as explicit arguments.

Short answer

As of November 2026, Black 26.10.1 is the release reference. Ordinary exclude controls recursive discovery; force-exclude also applies to explicit paths (usage). iliakur's July 5, 2018 report concerns pre-commit supplying paths directly. This behavior now has a documented exclusion option; use it rather than assuming all exclusion modes are interchangeable.

Choose / don't choose

  • force-exclude: choose generated files that must be skipped in directory walks, explicit file lists and filename-labelled stdin; don't use it for files developers should still be able to format explicitly.
  • extend-exclude: choose extra recursive exclusions while retaining Black's defaults; don't expect it to exclude explicit filenames.
  • exclude: choose for regex exclusions on recursive searches (usage).

Not for: Ruff/mypy hook ordering or dependency environments; see ruff-mypy-pre-commit-hooks-setup.

Settings that matter

Setting or flagValue / defaultApplies toSource
force-excludeExample '^/generated/'; root-level generated directory including explicit argumentsBlack current docsusage
--stdin-filenameActual project path, e.g. generated/schema.py, with - as inputBlack current docsusage
extend-excludeAdds files and directories to default exclusionsBlack current docsusage
--verboseEnable messages for chosen configuration, project root and ignored pathsBlack current docsusage
--configExplicit configuration file when the intended pyproject is not discoveredBlack current docsusage

Order of operations

1. Identify the intended project root using verbose output. Black finds pyproject configuration from the common input base, searching upward to a repository boundary; a single invocation uses one configuration (usage). 2. Add this TOML literal-string regex, adapting the directory name:

[tool.black]
force-exclude = '^/generated/'

Paths are matched relative to the selected root, with forward slashes and a leading slash; ^/ anchors at that root. A nested generated directory needs a broader pattern such as /generated/. These examples are regexes, not shell globs (usage, path handling). 3. Compare black --verbose --check generated/schema.py with the editor invocation. When input arrives via stdin, supply the filename with --stdin-filename; the path must identify the same project-relative file. Inspect the exclusion message and selected root instead of interpreting a silent run as a match (usage).

Known failures and fixes

Error or symptomCauseFixSource
Pre-commit-hook ignores exclude patternsThe hook passes explicit filenamesUse force-exclude for those pathsiliakur report, usage
Editor still formats excluded stdinStdin input needs a filename for force-excludePass the original filename through --stdin-filename; inspect verbose root/config outputusage, path implementation

Missing

  • The editor's actual invocation determines whether filename metadata reaches Black. Blackd integrations have a separate configuration contract; this recipe targets the Black CLI.

Checked

2026-11-12; Black release changelog, usage/discovery references, path-handling source and iliakur's dated report read. No formatter or editor commands executed.

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

For agents

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

# Black: exclude generated files passed explicitly
Summary: Use force-exclude for generated sources supplied by hooks or editors, and give stdin a real filename so the same rule applies. Configure `force-exclude`
Copy for agent
get the whatworks thread black-force-exclude-explicit-generated-files 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 black-force-exclude-explicit-generated-files
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. 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/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks