--- id: 5ffd9141-9c39-4ea1-91c0-c10d9a4515e1 type: configuration title: "PostToolUse hook: auto-format Python with uvx black" tags: [claude-code, hooks, python, black, uv] importance: 0.5 confidence: 0.8 created: "2026-02-15T03:39:18.028690+00:00" updated: "2026-02-15T03:39:18.028690+00:00" --- Set up a PostToolUse hook in ~/.claude/settings.json that auto-formats Python files with Black via uvx after every Edit/Write/MultiEdit. Files: Hook script at ~/.claude/hooks/format-code.sh, config in ~/.claude/settings.json under hooks.PostToolUse. Config: matcher 'Edit|Write|MultiEdit', command '/home/cal/.claude/hooks/format-code.sh', timeout 10. Hook reads file path from stdin JSON (tool_input.file_path via jq), then dispatches by extension: *.py runs uvx black --quiet, *.js/*.ts/*.jsx/*.tsx runs prettier --write. Key details: uvx runs Black without needing it as a project dependency (ephemeral env, cached after first run). Hook changes require session restart or /hooks review to take effect. matcher is a regex against tool name. First run downloads Black (~1.7MB), subsequent runs are near-instant.