.claude/hooks/on-file-write.sh: - Fix hook to read Claude Code context from JSON stdin (FILE_PATH and CWD extracted via jq) instead of relying on environment variables - Scan only the changed file instead of the entire project directory, reducing hook execution from ~30s to <1s per save .beads/: - Sync issue tracker state Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
18 lines
667 B
Bash
Executable File
18 lines
667 B
Bash
Executable File
#!/bin/bash
|
|
# Ultimate Bug Scanner - Claude Code Hook
|
|
# Runs on every file save for UBS-supported languages (JS/TS, Python, C/C++, Rust, Go, Java, Ruby)
|
|
# Claude Code hooks receive context as JSON on stdin.
|
|
|
|
INPUT=$(cat)
|
|
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // empty')
|
|
CWD=$(echo "$INPUT" | jq -r '.cwd // empty')
|
|
|
|
if [[ "$FILE_PATH" =~ \.(js|jsx|ts|tsx|mjs|cjs|py|pyw|pyi|c|cc|cpp|cxx|h|hh|hpp|hxx|rs|go|java|rb)$ ]]; then
|
|
echo "🔬 Running bug scanner..."
|
|
if ! command -v ubs >/dev/null 2>&1; then
|
|
echo "⚠️ 'ubs' not found in PATH; install it before using this hook." >&2
|
|
exit 0
|
|
fi
|
|
ubs "$FILE_PATH" --ci 2>&1 | head -50
|
|
fi
|