Stats
Actions
Tags
From dobeutech-claude-code-custom
Runs a git workflow guard before Bash tool execution to enforce policy, checks dependency versions after file edits, and performs a self-check on stop. Executes bash scripts with file access.
3 events · 11 hooks
Safety signals detected in this hook configuration
Where this hook configuration is defined
Defined in hooks/hooks.json
Event handlers and matchers — expand Raw Configuration for the full JSON
*#!/bin/bash
# Final check for console.logs in modified files
input=$(cat)
if git rev-parse --git-dir > /dev/null 2>&1; then
modified_files=$(git diff --name-only HEAD 2>/dev/null | grep -E '\.(ts|tsx|js|jsx)$' || true)
if [ -n "$modified_files" ]; then
has_console=false
while IFS= read -r file; do
if [ -f "$file" ]; then
if grep -q "console\.log" "$file" 2>/dev/null; then
echo "[Hook] WARNING: console.log found in $file" >&2
has_console=true
fi
fi
done <<< "$modified_files"
if [ "$has_console" = true ]; then
echo "[Hook] Remove console.log statements before committing" >&2
fi
fi
fi
echo "$input"tool == "Bash" && tool_input.command matches "(npm run dev|pnpm( run)? dev|yarn dev|bun run dev)"#!/bin/bash
input=$(cat)
cmd=$(echo "$input" | jq -r '.tool_input.command // ""')
# Block dev servers that aren't run in tmux
echo '[Hook] BLOCKED: Dev server must run in tmux for log access' >&2
echo '[Hook] Use this command instead:' >&2
echo "[Hook] tmux new-session -d -s dev 'npm run dev'" >&2
echo '[Hook] Then: tmux attach -t dev' >&2
exit 1tool == "Bash" && tool_input.command matches "(npm (install|test)|pnpm (install|test)|yarn (install|test)|bun (install|test)|cargo build|make|docker|pytest|vitest|playwright)"#!/bin/bash
input=$(cat)
if [ -z "$TMUX" ]; then
echo '[Hook] Consider running in tmux for session persistence' >&2
echo '[Hook] tmux new -s dev | tmux attach -t dev' >&2
fi
echo "$input"tool == "Bash" && tool_input.command matches "git push"#!/bin/bash
# Open editor for review before pushing
echo '[Hook] Review changes before push...' >&2
# Uncomment your preferred editor:
# zed . 2>/dev/null
# code . 2>/dev/null
# cursor . 2>/dev/null
echo '[Hook] Press Enter to continue with push or Ctrl+C to abort...' >&2
read -rtool == "Bash" && tool_input.command matches "git commit"#!/bin/bash
# Pre-commit security scan
input=$(cat)
if git rev-parse --git-dir > /dev/null 2>&1; then
staged_files=$(git diff --cached --name-only 2>/dev/null || true)
if [ -n "$staged_files" ]; then
echo "[Hook] Running pre-commit security checks..." >&2
# Check for secrets
secrets_found=false
while IFS= read -r file; do
if [ -f "$file" ]; then
# Check for common secret patterns
if grep -qiE '(api[_-]?key|secret|password|token|private[_-]?key)\s*[:=]\s*["\']?[a-zA-Z0-9]{20,}' "$file" 2>/dev/null; then
echo "[Hook] WARNING: Potential secret found in $file" >&2
secrets_found=true
fi
fi
done <<< "$staged_files"
if [ "$secrets_found" = true ]; then
echo "[Hook] BLOCKED: Potential secrets detected. Review before committing." >&2
exit 1
fi
# Check dependency vulnerabilities
if [ -f "package.json" ] || [ -f "package-lock.json" ]; then
echo "[Hook] Checking for dependency vulnerabilities..." >&2
if command -v npm >/dev/null 2>&1; then
npm audit --audit-level=moderate 2>&1 | head -20 >&2 || true
fi
fi
fi
fi
echo "$input"tool == "Write" && tool_input.file_path matches "\\.(md|txt)$" && !(tool_input.file_path matches "README\\.md|CLAUDE\\.md|AGENTS\\.md|CONTRIBUTING\\.md")#!/bin/bash
# Block creation of unnecessary documentation files
input=$(cat)
file_path=$(echo "$input" | jq -r '.tool_input.file_path // ""')
if [[ "$file_path" =~ \.(md|txt)$ ]] && [[ ! "$file_path" =~ (README|CLAUDE|AGENTS|CONTRIBUTING)\.md$ ]]; then
echo "[Hook] BLOCKED: Unnecessary documentation file creation" >&2
echo "[Hook] File: $file_path" >&2
echo "[Hook] Use README.md for documentation instead" >&2
exit 1
fi
echo "$input"tool == "Bash"#!/bin/bash
# Auto-detect PR creation and log useful info
input=$(cat)
cmd=$(echo "$input" | jq -r '.tool_input.command')
if echo "$cmd" | grep -qE 'gh pr create'; then
output=$(echo "$input" | jq -r '.tool_output.output // ""')
pr_url=$(echo "$output" | grep -oE 'https://github.com/[^/]+/[^/]+/pull/[0-9]+')
if [ -n "$pr_url" ]; then
echo "[Hook] PR created: $pr_url" >&2
echo "[Hook] Checking GitHub Actions status..." >&2
repo=$(echo "$pr_url" | sed -E 's|https://github.com/([^/]+/[^/]+)/pull/[0-9]+|\1|')
pr_num=$(echo "$pr_url" | sed -E 's|.*/pull/([0-9]+)|\1|')
echo "[Hook] To review PR: gh pr review $pr_num --repo $repo" >&2
fi
fi
echo "$input"tool == "Edit" && tool_input.file_path matches "\\.(ts|tsx|js|jsx)$"#!/bin/bash
# Auto-format with Prettier after editing JS/TS files
input=$(cat)
file_path=$(echo "$input" | jq -r '.tool_input.file_path // ""')
if [ -n "$file_path" ] && [ -f "$file_path" ]; then
if command -v prettier >/dev/null 2>&1; then
prettier --write "$file_path" 2>&1 | head -5 >&2
fi
fi
echo "$input"tool == "Edit" && tool_input.file_path matches "\\.(ts|tsx)$"#!/bin/bash
# Run TypeScript check after editing TS files
input=$(cat)
file_path=$(echo "$input" | jq -r '.tool_input.file_path // ""')
if [ -n "$file_path" ] && [ -f "$file_path" ]; then
dir=$(dirname "$file_path")
project_root="$dir"
while [ "$project_root" != "/" ] && [ ! -f "$project_root/package.json" ]; do
project_root=$(dirname "$project_root")
done
if [ -f "$project_root/tsconfig.json" ]; then
cd "$project_root" && npx tsc --noEmit --pretty false 2>&1 | grep "$file_path" | head -10 >&2 || true
fi
fi
echo "$input"tool == "Edit" && tool_input.file_path matches "\\.(ts|tsx|js|jsx)$"#!/bin/bash
# Warn about console.log in edited files
input=$(cat)
file_path=$(echo "$input" | jq -r '.tool_input.file_path // ""')
if [ -n "$file_path" ] && [ -f "$file_path" ]; then
console_logs=$(grep -n "console\\.log" "$file_path" 2>/dev/null || true)
if [ -n "$console_logs" ]; then
echo "[Hook] WARNING: console.log found in $file_path" >&2
echo "$console_logs" | head -5 >&2
echo "[Hook] Remove console.log before committing" >&2
fi
fi
echo "$input"tool == "Bash" && tool_input.command matches "git commit"#!/bin/bash
# Post-commit automation and reminders
input=$(cat)
if git rev-parse --git-dir > /dev/null 2>&1; then
commit_hash=$(git rev-parse HEAD 2>/dev/null || true)
commit_message=$(git log -1 --pretty=%B 2>/dev/null || true)
if [ -n "$commit_hash" ]; then
echo "[Hook] Commit $commit_hash created" >&2
# Auto-generate changelog reminder
if [ -f "CHANGELOG.md" ]; then
echo "[Hook] Consider updating CHANGELOG.md" >&2
fi
# Check if documentation needs updating
if echo "$commit_message" | grep -qiE '(api|endpoint|route|function|class)'; then
echo "[Hook] Consider updating API documentation" >&2
fi
fi
fi
echo "$input"npx claudepluginhub dobeu-tech-eco/dobeutech-claude-code-custom