Skip to content

Instantly share code, notes, and snippets.

@boxabirds
Created March 9, 2026 07:08
Show Gist options
  • Select an option

  • Save boxabirds/9e9261700533c7636c940e2a107c27b5 to your computer and use it in GitHub Desktop.

Select an option

Save boxabirds/9e9261700533c7636c940e2a107c27b5 to your computer and use it in GitHub Desktop.
No fallbacks! Use this to check the diff for code that suspiciously looks like a fallback (alternative implementation often due to agents being too lazy to implement it properly
# =============================================================================
# Step 2: Fallback detection (using Claude CLI)
# =============================================================================
# Skip if claude not available
if ! command -v claude &> /dev/null; then
echo "Warning: claude CLI not found, skipping fallback check"
exit 0
fi
# Get the staged diff (only code files)
DIFF=$(git diff --cached --diff-filter=ACM -- '*.ts' '*.js' '*.sh')
if [[ -z "$DIFF" ]]; then
exit 0
fi
echo "Checking for suspicious fallbacks..."
# Pipe diff to Claude for review
RESULT=$(echo "$DIFF" | claude -p "Review this git diff (provided via stdin) for silent fallbacks that could hide bugs.
Look for:
- Default values that mask missing config (like defaulting to prod URL)
- Catch blocks that swallow errors without logging
- Nullish coalescing or OR that provides a 'safe' value hiding a real problem
- Any pattern where a failure is silently converted to a default
DO NOT flag:
- UI display defaults like || 'unassigned' or || 'none'
- Empty array defaults || []
- Legitimate optional parameters with defaults
- Lines with // FALLBACK: comment (explicit sign-off)
If you find suspicious fallbacks, output ONLY:
BLOCK: <file>:<line> - <reason>
If nothing suspicious, output ONLY:
OK
Be conservative - only flag things that genuinely look like they could hide bugs." 2>&1) || true
# Check for API/auth errors - don't block commits if Claude is unavailable
# Be specific to avoid false positives when code contains words like "error"
if echo "$RESULT" | grep -qiE "(api error|rate limit|insufficient credit|401|403|connection refused|ECONNREFUSED|timed out|network error)"; then
echo "Warning: Claude check skipped (API unavailable)"
exit 0
fi
if echo "$RESULT" | grep -q "^BLOCK:"; then
echo ""
echo "Suspicious fallback detected:"
echo "$RESULT"
echo ""
echo "Either fix the fallback or add: // FALLBACK: <reason>"
exit 1
fi
echo "Fallback check passed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment