glossaryGit hooks that run automatically before a commit is recorded, allowing teams to enforce code quality checks, linting, or message format validation without manual steps.
Git hooks are shell scripts stored in the .git/hooks directory that Git executes at defined lifecycle points. The pre-commit hook runs after git commit is invoked but before the commit object is written. If the hook exits with a non-zero status, the commit is aborted and the developer must fix the reported issue before trying again. Pre-commit hooks are commonly used to run linters (ESLint, Ruff, golangci-lint), formatters (Prettier, Black, gofmt), type checkers, and test suites on staged files. They can also validate commit message format, check for secrets, or enforce file size limits. Popular frameworks for managing hook installation include pre-commit (Python), Husky (Node.js), and lefthook (Go). One challenge with hooks and AI-generated commit messages is that the hook may reject a message that does not fully conform to the project's specific conventional commit format. A retry loop that regenerates the message with the hook's error output as context can resolve this automatically.
#!/bin/sh
npx eslint --max-warnings=0 $(git diff --cached --name-only -- '*.js')#!/bin/sh
gofmt -l $(git diff --cached --name-only -- '*.go') | grep . && exit 1 || exit 0#!/bin/sh
python -m pytest tests/unit/ -q --no-header# commit-msg hook
if ! grep -qE '^(feat|fix|chore|docs|refactor|test|perf|style|ci)(\(.+\))?: .{1,72}$' "$1"; then exit 1; figit-agent installs a pre-commit hook via git-agent init that validates each generated message. When a hook rejects a message, git-agent automatically retries message generation up to 3 times, passing the hook's error output back to the LLM as context to produce a conforming message.
brew install gitagenthq/tap/git-agentDoes git-agent bypass my existing pre-commit hooks?How many retry attempts does git-agent make when a hook rejects the message?Can I use git-agent with Husky or pre-commit framework?