#!/bin/bash # PostToolUse hook: run shellcheck after editing a bash.d script. # Skips non-script files (markdown, .gitignore, etc). set -euo pipefail input=$(cat) file_path=$(echo "$input" | jq -r '.tool_input.file_path // empty') # No file path — nothing to check [[ -z "$file_path" ]] && exit 0 basename=$(basename "$file_path") # Only check files that match the numbered script naming convention # or .example templates (which are also valid shell scripts) case "$basename" in [0-9][0-9]-*|[0-9][0-9]-*.example) ;; *) exit 0 ;; esac # File must still exist (Write could have been to a new path) [[ -f "$file_path" ]] || exit 0 # Run shellcheck — exit 2 feeds stderr back to Claude if ! shellcheck "$file_path" 2>&1; then echo "shellcheck failed on $basename — please fix the issues above" >&2 exit 2 fi exit 0