mirror of
https://github.com/davila7/claude-code-templates.git
synced 2026-09-19 01:30:23 +08:00
e5177fbe27
✅ Fixed ALL remaining hooks (20 total): - Updated post-tool/ and pre-tool/ hooks to Claude Code array format - Fixed git-add-changes, format-javascript-files, format-python-files, run-tests-after-changes - Fixed backup-before-edit, notify-before-bash 🧠 Added AI Hook Specification System: - CLAUDE_HOOK_SPECIFICATION.md - Complete hook format guide for AI - AI_HOOK_TEMPLATE.json - Structured template with examples for AI parsing - HOOK_PATTERNS_COMPRESSED.json - Compressed patterns for rapid AI reference 📊 Technical Improvements: - All 20 hooks now use proper array/matcher structure - Regenerated components.json with corrected hook metadata - Added comprehensive validation rules and anti-patterns - Included environment variables and cross-platform compatibility guides 🎯 AI Context Enhancement: - Future Claude Code sessions can reference these files for correct hook generation - Compressed format optimizes AI parsing while maintaining completeness - Common patterns and validation rules prevent structure errors 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 line
3.4 KiB
JSON
1 line
3.4 KiB
JSON
{"patterns":{"logging":{"desc":"Log tool usage","struct":{"hooks":{"PreToolUse":[{"matcher":"*","hooks":[{"type":"command","command":"echo \"[$(date)] $CLAUDE_TOOL_NAME\" >> ~/.claude/activity.log"}]}]}}},"backup":{"desc":"Backup before edit","struct":{"hooks":{"PreToolUse":[{"matcher":"Edit|MultiEdit","hooks":[{"type":"command","command":"[[ -f \"$CLAUDE_TOOL_FILE_PATH\" ]] && cp \"$CLAUDE_TOOL_FILE_PATH\" \"$CLAUDE_TOOL_FILE_PATH.$(date +%s).bak\" 2>/dev/null || true"}]}]}}},"format":{"desc":"Auto-format files","struct":{"hooks":{"PostToolUse":[{"matcher":"Edit","hooks":[{"type":"command","command":"if [[ \"$CLAUDE_TOOL_FILE_PATH\" =~ \\.(js|ts)$ ]]; then npx prettier --write \"$CLAUDE_TOOL_FILE_PATH\" 2>/dev/null || true; elif [[ \"$CLAUDE_TOOL_FILE_PATH\" == *.py ]]; then black \"$CLAUDE_TOOL_FILE_PATH\" 2>/dev/null || true; fi"}]}]}}},"git":{"desc":"Git operations","struct":{"hooks":{"PostToolUse":[{"matcher":"Edit|Write","hooks":[{"type":"command","command":"git rev-parse --git-dir >/dev/null 2>&1 && git add \"$CLAUDE_TOOL_FILE_PATH\" 2>/dev/null || true"}]}]}}},"notify":{"desc":"Desktop notifications","struct":{"hooks":{"PostToolUse":[{"matcher":"*","hooks":[{"type":"command","command":"if command -v osascript >/dev/null; then osascript -e 'display notification \"$CLAUDE_TOOL_NAME completed\" with title \"Claude Code\"'; elif command -v notify-send >/dev/null; then notify-send \"Claude Code\" \"$CLAUDE_TOOL_NAME completed\"; fi"}]}]}}},"test":{"desc":"Run tests","struct":{"hooks":{"PostToolUse":[{"matcher":"Edit","hooks":[{"type":"command","command":"if [[ -f package.json ]]; then npm test 2>/dev/null || yarn test 2>/dev/null || true; elif [[ -f pytest.ini ]]; then pytest 2>/dev/null || true; fi"}]}]}}},"build":{"desc":"Auto build","struct":{"hooks":{"PostToolUse":[{"matcher":"Edit","hooks":[{"type":"command","command":"if [[ -f package.json ]] && grep -q '\"build\"' package.json; then npm run build 2>/dev/null || true; elif [[ -f Makefile ]]; then make 2>/dev/null || true; fi"}]}]}}},"security":{"desc":"Security scan","struct":{"hooks":{"PostToolUse":[{"matcher":"Edit|Write","hooks":[{"type":"command","command":"if command -v gitleaks >/dev/null; then gitleaks detect --source=\"$CLAUDE_TOOL_FILE_PATH\" --no-git 2>/dev/null || true; fi; grep -qE '(password|secret|key)\\s*=' \"$CLAUDE_TOOL_FILE_PATH\" && echo \"⚠️ Potential secrets in $CLAUDE_TOOL_FILE_PATH\" || true"}]}]}}},"protect":{"desc":"File protection","struct":{"hooks":{"PreToolUse":[{"matcher":"Edit|Write","hooks":[{"type":"command","command":"for p in '/etc/*' '/usr/bin/*' '*.production.*' '*prod*config*' '/node_modules/*'; do [[ \"$CLAUDE_TOOL_FILE_PATH\" == $p ]] && echo \"Error: Protected file\" >&2 && exit 1; done"}]}]}}}},"commands":{"check_file":"[[ -f \"$CLAUDE_TOOL_FILE_PATH\" ]]","check_git":"git rev-parse --git-dir >/dev/null 2>&1","suppress_errors":"2>/dev/null || true","timestamp":"$(date +%Y%m%d_%H%M%S)","check_package":"[[ -f package.json ]]","file_ext_js":"[[ \"$CLAUDE_TOOL_FILE_PATH\" =~ \\.(js|ts|jsx|tsx)$ ]]","file_ext_py":"[[ \"$CLAUDE_TOOL_FILE_PATH\" == *.py ]]","macos_notify":"osascript -e 'display notification \"$CLAUDE_TOOL_NAME\" with title \"Claude Code\"'","linux_notify":"notify-send \"Claude Code\" \"$CLAUDE_TOOL_NAME\""},"structure":"ALWAYS_USE_ARRAYS_FOR_EVENTS","required_fields":["description","hooks"],"env_vars":{"CLAUDE_TOOL_NAME":"current_tool","CLAUDE_TOOL_FILE_PATH":"file_path","CLAUDE_PROJECT_DIR":"project_root"}} |