From edbe1bcbf9daf0a2e37c95e692e5535e596560ae Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Wed, 11 Mar 2026 20:28:25 +0100 Subject: [PATCH] chore: add Husky hooks to prevent Claude Code from bad git practices (#10937) - Adds two Husky hooks to prevent Claude Code from bad git practices: - \`prepare-commit-msg\`: blocks \`git commit --amend\` (detected via the \`commit\` source argument) - \`pre-commit\`: blocks committing directly to \`main\` - Both hooks detect Claude Code sessions via the \`CLAUDECODE\` environment variable, so regular users are unaffected - Error messages explicitly tell Claude what to do instead --- .husky/pre-commit | 7 +++++++ .husky/prepare-commit-msg | 8 ++++++++ 2 files changed, 15 insertions(+) create mode 100755 .husky/pre-commit create mode 100755 .husky/prepare-commit-msg diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 0000000000..c14803f702 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,7 @@ +#!/bin/sh +# Prevent Claude Code from committing directly on the main branch. + +if [ -n "$CLAUDECODE" ] && [ "$(git rev-parse --abbrev-ref HEAD)" = "main" ]; then + echo "error: Committing directly to the main branch is not allowed. Create a new branch and open a pull request instead." >&2 + exit 1 +fi diff --git a/.husky/prepare-commit-msg b/.husky/prepare-commit-msg new file mode 100755 index 0000000000..6da87ff9e3 --- /dev/null +++ b/.husky/prepare-commit-msg @@ -0,0 +1,8 @@ +#!/bin/sh +# Prevent Claude Code from amending commits. +# The prepare-commit-msg hook receives "commit" as $2 when --amend is used. + +if [ "$2" = "commit" ] && [ -n "$CLAUDECODE" ]; then + echo "error: Amending commits is not allowed. Create a new commit instead." >&2 + exit 1 +fi