CClaude Code Catalog
All Hooks

Pre-Commit Lint

Pre-ToolBeginnerHook Type: pre-tool-use

Pre-Commit Lint hooks into the pre-tool-use event for Bash commands that contain 'git commit'. Before the commit executes, it runs ESLint on staged files and checks Prettier formatting. If any lint errors or formatting issues are found, it blocks the commit and reports the problems so Claude can fix them first. This ensures every commit meets your project's code quality standards without manual intervention.

linteslintprettiercode-qualitycommit

Hook Code

#!/bin/bash # Pre-Commit Lint Hook # Runs ESLint and Prettier on staged files before git commit # Only intercept git commit commands if [[ "$TOOL_NAME" != "Bash" ]] || ! echo "$TOOL_INPUT" | grep -q "git commit"; then exit 0 fi STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACMR | grep -E '\.(ts|tsx|js|jsx)$') if [ -z "$STAGED_FILES" ]; then exit 0 fi echo "Running ESLint on staged files..." npx eslint $STAGED_FILES --quiet LINT_EXIT=$? echo "Checking Prettier formatting..." npx prettier --check $STAGED_FILES 2>/dev/null FORMAT_EXIT=$? if [ $LINT_EXIT -ne 0 ] || [ $FORMAT_EXIT -ne 0 ]; then echo "ERROR: Lint or format issues found. Fix before committing." exit 1 fi echo "All checks passed." exit 0

Add this hook to your Claude Code settings or .claude/settings.json to activate.

Terminal Preview

Pre-Commit Lint

About Pre-Commit Lint

Claude Code hooks let you run custom shell commands automatically in response to specific events during Claude's operation. Pre-Commit Lint is a Pre-Tool hook at the Beginner level that automates tasks at key moments in your development workflow, reducing manual steps and enforcing consistency across your team.

Related Hooks