mirror of
https://github.com/wasrusgen/zov-tech.git
synced 2026-06-03 15:44:47 +00:00
.claude/settings.json — hook fires after every Edit/Write: - .js files → node --check - .py files → py_compile.compile (doraise=True) - exit 2 on failure → Claude sees the error immediately and fixes it Scripts: - .claude/hooks/syntax_check.ps1 (Windows, primary) - .claude/hooks/syntax_check.sh (bash fallback) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
42 lines
1.2 KiB
PowerShell
42 lines
1.2 KiB
PowerShell
# ================================================================
|
|
# Claude Code — PostToolUse hook (Windows PowerShell fallback)
|
|
# Syntax check after every Edit / Write tool call.
|
|
# Exit code 2 = Claude sees the error and can fix immediately.
|
|
# ================================================================
|
|
|
|
param()
|
|
|
|
# Read file_path from CLAUDE_TOOL_INPUT env var (JSON)
|
|
$filePath = ""
|
|
try {
|
|
$input_json = $env:CLAUDE_TOOL_INPUT | ConvertFrom-Json -ErrorAction Stop
|
|
$filePath = $input_json.file_path
|
|
} catch {}
|
|
|
|
if (-not $filePath -or -not (Test-Path $filePath)) { exit 0 }
|
|
|
|
$ext = [System.IO.Path]::GetExtension($filePath).TrimStart('.')
|
|
|
|
switch ($ext) {
|
|
"js" {
|
|
$result = & node --check $filePath 2>&1
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Output "❌ JS SYNTAX ERROR: $filePath"
|
|
Write-Output $result
|
|
exit 2
|
|
}
|
|
}
|
|
"py" {
|
|
$escaped = $filePath -replace "'", "''"
|
|
$result = & python -c "import py_compile,sys; py_compile.compile('$escaped', doraise=True)" 2>&1
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Output "❌ PY SYNTAX ERROR: $filePath"
|
|
Write-Output $result
|
|
exit 2
|
|
}
|
|
}
|
|
default { exit 0 }
|
|
}
|
|
|
|
exit 0
|