Skip to content

Commit 8e373eb

Browse files
committed
feat: auto-install pre-commit in session start hook
Update the SessionStart hook to automatically install pre-commit using pip if it's not already available, rather than just showing an error message. This ensures pre-commit is always available when starting a Claude Code session.
1 parent edfeebf commit 8e373eb

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

‎.claude/hooks/SessionStart.sh‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
#!/bin/bash
22

33
# Session start hook to ensure pre-commit is installed
4-
echo "Installing pre-commit hooks..."
4+
echo "Setting up pre-commit..."
55

6-
# Check if pre-commit is available
6+
# Check if pre-commit is available, install if not
77
if ! command -v pre-commit &> /dev/null; then
8-
echo "Error: pre-commit is not installed. Please install it with: pip install pre-commit"
9-
exit 1
8+
echo "pre-commit is not installed. Installing pre-commit..."
9+
10+
# Try to install pre-commit using pip
11+
if command -v pip3 &> /dev/null; then
12+
pip3 install pre-commit
13+
elif command -v pip &> /dev/null; then
14+
pip install pre-commit
15+
else
16+
echo "Error: pip is not installed. Cannot install pre-commit."
17+
exit 1
18+
fi
19+
20+
# Verify installation
21+
if ! command -v pre-commit &> /dev/null; then
22+
echo "Error: Failed to install pre-commit."
23+
exit 1
24+
fi
25+
26+
echo "pre-commit installed successfully!"
1027
fi
1128

1229
# Install pre-commit hooks

0 commit comments

Comments
 (0)