Created
July 1, 2025 08:05
-
-
Save nishimura/96ac903692fa14c65038deaf923cd067 to your computer and use it in GitHub Desktop.
Blank check hooks for Claude Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Format check and fix script for Claude | |
| # Fixes files according to CLAUDE.md formatting rules | |
| # Hooks-compatible version - Can be auto-executed on PostToolUse events | |
| # When called via hooks (JSON is passed via stdin) | |
| if [ ! -t 0 ]; then | |
| # Read JSON from stdin | |
| json=$(cat) | |
| # Process only for Edit, Write, or MultiEdit tools | |
| tool_name=$(echo "$json" | jq -r '.tool_name // empty') | |
| if [ "$tool_name" != "Edit" ] && [ "$tool_name" != "Write" ] && [ "$tool_name" != "MultiEdit" ]; then | |
| exit 0 | |
| fi | |
| # Extract file path | |
| file_path=$(echo "$json" | jq -r '.tool_input.file_path // empty') | |
| if [ -z "$file_path" ]; then | |
| exit 0 | |
| fi | |
| # Process as single file | |
| files=("$file_path") | |
| else | |
| # When called with command line arguments | |
| if [ $# -eq 0 ]; then | |
| echo "Usage: $0 <file1> [file2] ..." | |
| echo "Example: $0 CLAUDE.md docs/*.md" | |
| exit 1 | |
| fi | |
| files=("$@") | |
| fi | |
| for file in "${files[@]}"; do | |
| if [ ! -f "$file" ]; then | |
| echo "File not found: $file" | |
| continue | |
| fi | |
| echo "Checking: $file" | |
| # Remove trailing spaces | |
| sed -i 's/[[:space:]]*$//' "$file" | |
| echo " - Removed trailing spaces" | |
| # Check and add final newline | |
| if [ $(tail -c 1 "$file" | wc -l) -eq 0 ]; then | |
| echo >> "$file" | |
| echo " - Added final newline" | |
| else | |
| echo " - Final newline OK" | |
| fi | |
| done | |
| echo "Format check completed." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment