Commit 50ae1abed1fe

Vincent Demeester <vincent@sbr.pm>
2026-01-29 14:08:13
fix(claude-hooks): output validation errors to stderr
Claude Code reads stderr for hook error messages. Previously the validate-git-push hook wrote to stdout, causing "No stderr output" errors instead of showing helpful guidance. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 12e455a
Changed files (1)
tools
claude-hooks
cmd
validate-git-push
tools/claude-hooks/cmd/validate-git-push/main.go
@@ -80,16 +80,16 @@ func main() {
 
 	// Check if it has explicit refspec
 	if !hasExplicitRefspec(command) {
-		// Block the command - output error message and exit non-zero
-		fmt.Println("BLOCKED: git push without explicit refspec detected!")
-		fmt.Println("")
-		fmt.Println("The command uses implicit branch tracking which can push to wrong branches.")
-		fmt.Println("")
-		fmt.Println("Use explicit refspec instead:")
-		fmt.Println("  git push origin <branch>:<branch>")
-		fmt.Println("  git push origin HEAD:<branch>")
-		fmt.Println("")
-		fmt.Printf("Blocked command: %s\n", command)
+		// Block the command - output error message to stderr and exit non-zero
+		fmt.Fprintln(os.Stderr, "BLOCKED: git push without explicit refspec detected!")
+		fmt.Fprintln(os.Stderr, "")
+		fmt.Fprintln(os.Stderr, "The command uses implicit branch tracking which can push to wrong branches.")
+		fmt.Fprintln(os.Stderr, "")
+		fmt.Fprintln(os.Stderr, "Use explicit refspec instead:")
+		fmt.Fprintln(os.Stderr, "  git push origin <branch>:<branch>")
+		fmt.Fprintln(os.Stderr, "  git push origin HEAD:<branch>")
+		fmt.Fprintln(os.Stderr, "")
+		fmt.Fprintf(os.Stderr, "Blocked command: %s\n", command)
 		os.Exit(2) // Non-zero exit blocks the tool
 	}