Skip to content

post-edit-format

Run best-effort formatter after edits.

hook PostToolUse github-copilot

Run best-effort formatter after edits.

FieldValue
idpost-edit-format
logical_eventPostToolUse
matcherEdit|Write|MultiEdit|edit|create|write_file|replace
command./hooks/auto-format.sh
timeout30
harnesses["github-copilot"]
Full hook config + command reference
config/hook-registry.json (entry)
{
"id": "post-edit-format",
"description": "Run best-effort formatter after edits.",
"logical_event": "PostToolUse",
"matcher": "Edit|Write|MultiEdit|edit|create|write_file|replace",
"command": "./hooks/auto-format.sh",
"timeout": 30,
"harnesses": [
"github-copilot"
]
}
hooks/auto-format.sh
#!/bin/bash
command -v jq &>/dev/null || exit 0
INPUT=$(cat)
FILE_PATH=$(echo "$INPUT" | jq -r '
.tool_input.file_path
// (
(.toolArgs | fromjson? // .toolArgs // {})
| if type == "object" then (.filePath // .path // .target_file // empty) else empty end
)
// empty
')
[ -z "$FILE_PATH" ] || [ ! -f "$FILE_PATH" ] && exit 0
case "${FILE_PATH##*.}" in
py)
if [ -f "pyproject.toml" ] && command -v uv &>/dev/null; then
uv run ruff format "$FILE_PATH" 2>/dev/null
elif command -v ruff &>/dev/null; then
ruff format "$FILE_PATH" 2>/dev/null
fi ;;
js|jsx|ts|tsx|css|scss|html|json|yaml|yml)
if [ -f "node_modules/.bin/prettier" ]; then
node_modules/.bin/prettier --write "$FILE_PATH" 2>/dev/null
elif command -v prettier &>/dev/null; then
prettier --write "$FILE_PATH" 2>/dev/null
fi ;;
rs) command -v rustfmt &>/dev/null && rustfmt "$FILE_PATH" 2>/dev/null ;;
go) command -v gofmt &>/dev/null && gofmt -w "$FILE_PATH" 2>/dev/null ;;
esac
exit 0

View source on GitHub