From 286a9afbbe415c8a8cc33470654ddb655ec62926 Mon Sep 17 00:00:00 2001 From: Chris Parsons Date: Tue, 24 Mar 2026 21:50:36 -0700 Subject: [PATCH] Fix lint hook: output additionalContext JSON so Claude sees errors in-context 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 --- .claude/hooks/lint-on-edit.sh | 35 +++++++++++++++++++++++++++++++++++ .claude/settings.json | 4 +++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100755 .claude/hooks/lint-on-edit.sh diff --git a/.claude/hooks/lint-on-edit.sh b/.claude/hooks/lint-on-edit.sh new file mode 100755 index 0000000..6db1c8b --- /dev/null +++ b/.claude/hooks/lint-on-edit.sh @@ -0,0 +1,35 @@ +#!/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" diff --git a/.claude/settings.json b/.claude/settings.json index 146f831..76caf3d 100644 --- a/.claude/settings.json +++ b/.claude/settings.json @@ -6,7 +6,9 @@ "hooks": [ { "type": "command", - "command": "python3 -c \"import sys,json; d=json.load(sys.stdin); f=d.get('tool_input',{}).get('file_path',''); print(f)\" | xargs -I{} sh -c 'case \"{}\" in *.ts|*.tsx) npm run lint:path -- \"{}\" 2>&1 ;; esac'" + "command": ".claude/hooks/lint-on-edit.sh", + "timeout": 30, + "statusMessage": "Linting..." } ] }