Created
July 21, 2025 22:47
-
-
Save rafaelquintanilha/8c8aad3d31e31cb31ea1f34b87920453 to your computer and use it in GitHub Desktop.
Claude Code Hooks
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
{ | |
"hooks": { | |
"PreToolUse": [ | |
{ | |
"matcher": "Bash", | |
"hooks": [ | |
{ | |
"type": "command", | |
"command": "jq -r '\"\\(.tool_input.command) - \\(.tool_input.description // \"No description\")\"' >> ~/.claude/bash-command-log.txt" | |
} | |
] | |
} | |
], | |
"PostToolUse": [ | |
{ | |
"matcher": "Write|Edit|MultiEdit", | |
"hooks": [ | |
{ | |
"type": "command", | |
"command": "jq -r '.tool_input.file_path' | { read file_path; if echo \"$file_path\" | grep -qE '\\.(js|jsx|ts|tsx)$'; then echo \"[$(date)] Running prettier on: $file_path\" >> ~/.claude/command-log.txt; dir=\"$(dirname \"$file_path\")\"; while [ \"$dir\" != \"/\" ] && [ ! -f \"$dir/package.json\" ]; do dir=\"$(dirname \"$dir\")\"; done; if [ -f \"$dir/package.json\" ]; then cd \"$dir\" && npx prettier --write \"$file_path\" 2>&1 | tee -a ~/.claude/command-log.txt; else echo \"[$(date)] No package.json found for: $file_path\" >> ~/.claude/command-log.txt; fi; else echo \"[$(date)] Skipping non-JS/TS file: $file_path\" >> ~/.claude/command-log.txt; fi; }" | |
} | |
] | |
}, | |
{ | |
"matcher": "Write|Edit|MultiEdit", | |
"hooks": [ | |
{ | |
"type": "command", | |
"command": "jq -r '.tool_input.file_path' | { read file_path; if echo \"$file_path\" | grep -qE '\\.(js|jsx|ts|tsx)$'; then echo \"[$(date)] Running eslint on: $file_path\" >> ~/.claude/command-log.txt; dir=\"$(dirname \"$file_path\")\"; while [ \"$dir\" != \"/\" ] && [ ! -f \"$dir/package.json\" ]; do dir=\"$(dirname \"$dir\")\"; done; if [ -f \"$dir/package.json\" ]; then cd \"$dir\" && output=$(npx eslint \"$file_path\" --max-warnings 0 2>&1); exit_code=$?; echo \"$output\" | tee -a ~/.claude/command-log.txt; if [ $exit_code -ne 0 ]; then echo \"ESLint found issues in $file_path. Please fix the following:\" >&2; echo \"$output\" >&2; exit 2; fi; else echo \"[$(date)] No package.json found for: $file_path\" >> ~/.claude/command-log.txt; fi; else echo \"[$(date)] Skipping lint for non-JS/TS file: $file_path\" >> ~/.claude/command-log.txt; fi; }" | |
} | |
] | |
}, | |
{ | |
"matcher": "Write|Edit|MultiEdit", | |
"hooks": [ | |
{ | |
"type": "command", | |
"command": "jq -r '.tool_input.file_path' | { read file_path; if echo \"$file_path\" | grep -qE '\\.(ts|tsx)$'; then app=$(echo \"$file_path\" | sed -n 's|.*/monorepo/apps/\\([^/]*\\)/.*|\\1|p'); if [ -n \"$app\" ]; then echo \"[$(date)] Running full typecheck for $app (triggered by: $file_path)\" >> ~/.claude/command-log.txt; dir=\"$(dirname \"$file_path\")\"; while [ \"$dir\" != \"/\" ] && [ ! -f \"$dir/turbo.json\" ]; do dir=\"$(dirname \"$dir\")\"; done; if [ -f \"$dir/turbo.json\" ]; then cd \"$dir\" && output=$(npx turbo typecheck --filter \"$app\" 2>&1); exit_code=$?; echo \"$output\" | tee -a ~/.claude/command-log.txt; if [ $exit_code -ne 0 ]; then echo \"TypeScript found type errors in $app. Please fix the following:\" >&2; echo \"$output\" >&2; exit 2; fi; fi; fi; else echo \"[$(date)] Skipping typecheck for non-TS file: $file_path\" >> ~/.claude/command-log.txt; fi; }" | |
} | |
] | |
} | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment