Replaced the old inline command (which just printed raw text and exited non-zero) with a small script at .claude/hooks/lint-on-edit.sh. When oxlint finds errors, the script outputs JSON with hookSpecificOutput .additionalContext, which explicitly injects the lint errors into Claude's context so it fixes them immediately rather than missing a background notification. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
35 lines
898 B
Bash
Executable file
35 lines
898 B
Bash
Executable file
#!/bin/bash
|
|
# Run oxlint on the edited file and inject errors back into Claude's context.
|
|
# Reads the PostToolUse JSON payload from stdin.
|
|
# Exits 0 silently on pass or non-TS file; outputs JSON additionalContext on failure.
|
|
|
|
set -euo pipefail
|
|
|
|
FILE=$(python3 -c "
|
|
import sys, json
|
|
d = json.load(sys.stdin)
|
|
print(d.get('tool_input', {}).get('file_path', ''))
|
|
")
|
|
|
|
# Only lint TypeScript files
|
|
case "$FILE" in
|
|
*.ts|*.tsx) ;;
|
|
*) exit 0 ;;
|
|
esac
|
|
|
|
cd /home/chris/Projects/brackt.com
|
|
|
|
OUTPUT=$(npm run lint:path -- "$FILE" 2>&1) && exit 0
|
|
|
|
# Lint failed — inject errors into Claude's context so it fixes them immediately
|
|
python3 -c "
|
|
import json, sys
|
|
out = sys.argv[1]
|
|
f = sys.argv[2]
|
|
print(json.dumps({
|
|
'hookSpecificOutput': {
|
|
'hookEventName': 'PostToolUse',
|
|
'additionalContext': 'Lint errors found in ' + f + ' — fix before continuing:\n' + out
|
|
}
|
|
}))
|
|
" "$OUTPUT" "$FILE"
|