Run linting and type checks before every commit.
## Claude Code Pre-Commit Hook
Configure Claude Code hooks for automatic pre-commit actions.
### .claude/hooks/pre-commit.json
```json
{
"hooks": {
"pre-commit": {
"description": "Run linting and type checks before every commit.",
"command": ".claude/scripts/pre-commit.sh",
"timeout": 30000,
"enabled": true
}
}
}
```
### .claude/scripts/pre-commit.sh
```bash
#!/bin/bash
set -e
echo "Running Pre-Commit hook..."
# Step 1: Validate environment
if [ -z "$PROJECT_ROOT" ]; then
PROJECT_ROOT=$(git rev-parse --show-toplevel)
fi
# Step 2: Run checks
cd "$PROJECT_ROOT"
# Run linting
npm run lint --quiet 2>/dev/null || echo "Lint warnings found"
# Run type checking
npm run typecheck 2>/dev/null || echo "Type errors found"
# Step 3: Report results
echo "Pre-Commit hook completed successfully"
```
### Setup
1. Create `.claude/hooks/` directory
2. Add the JSON config file
3. Create the shell script and make executable
4. Claude Code will run this automaticallyFree to copy and use. Compatible with Claude Code, Claude 4 Opus.
Copy this prompt into your Claude Code project. Customize bracketed variables for your specific setup.
Initial release
Sign in and download this prompt to leave a review.