Claude Code edits files one after another. When it introduces a syntax error in file #1, it doesn't notice. It moves to file #2, which imports file #1. Now file #2 breaks. By the time it stops, 30 files have cascading errors.
The 30-file cascade
Claude refactors a shared utility file. It removes a closing brace. The file is syntactically broken, but Claude moves on to the next file that imports it. Each file it touches inherits the problem. The developer returns to find 30+ files with errors traced back to one missing }.
The JSON config corruption
Claude edits a tsconfig.json and leaves a trailing comma. Every TypeScript file in the project now fails to compile. Claude spends 20 minutes "fixing" type errors that don't actually exist.
The Python import chain
Claude introduces an indentation error in a base module. All 15 files that import it start throwing IndentationError. Claude tries to fix each file individually instead of the root cause.
Claude doesn't run a syntax check after editing a file. It trusts its own output. When it makes a mistake — a missing bracket, wrong indentation, unclosed string — it proceeds to the next task. The error propagates silently.
syntax-check hook — validates every file immediately after editing:
#!/bin/bash
# Runs after every Write/Edit tool use
INPUT=$(cat)
FILE=$(echo "$INPUT" | jq -r '.tool_input.file_path // empty')
[ -z "$FILE" ] && exit 0
case "$FILE" in
*.py) python3 -c "import ast; ast.parse(open('$FILE').read())" 2>&1 ;;
*.js) node --check "$FILE" 2>&1 ;;
*.ts) npx tsc --noEmit "$FILE" 2>&1 ;;
*.json) python3 -m json.tool "$FILE" > /dev/null 2>&1 ;;
*.sh) bash -n "$FILE" 2>&1 ;;
esac
if [ $? -ne 0 ]; then
echo "SYNTAX ERROR in $FILE — fix before continuing" >&2
exit 2
fi
This hook runs after every file edit. If the file has a syntax error, Claude is forced to fix it before touching anything else.
| Language | Check Method |
|---|---|
| Python | python3 -c "import ast; ast.parse(...)" |
| JavaScript | node --check |
| TypeScript | npx tsc --noEmit |
| JSON | python3 -m json.tool |
| Bash | bash -n |
| Go, Rust, Ruby | Supported via --install-example |
npx cc-safe-setup
Catches syntax errors, blocks rm -rf, prevents force-push, stops secret leaks. 9,200+ tests 655 examples
npx cc-health-check
Free 20-point diagnostic. Score below 80 means your Claude Code setup has gaps.
cc-safe-setup is open source, zero dependencies, and installs nothing globally. View source on GitHub.
New: Hook if field — reduce overhead (v2.1.85)
Learn more: Production Guide · All Tools