#!/usr/bin/env python3 """ Generate comprehensive Claude Code hook configurations. """ import json from typing import Dict, Any def generate_basic_config() -> Dict[str, Any]: """Generate basic hook configuration.""" return { "hooks": { # Session Management "session_start": 'curl -X POST http://localhost:8000/api/sessions/start -H "Content-Type: application/json" -d \'{"project_path": "$PWD", "start_time": "$TIMESTAMP"}\'', "session_end": 'curl -X POST http://localhost:8000/api/sessions/end -H "Content-Type: application/json" -d \'{"session_id": "$SESSION_ID", "end_time": "$TIMESTAMP"}\'', # Core Interactions "conversation_update": 'curl -X POST http://localhost:8000/api/conversations -H "Content-Type: application/json" -d \'{"session_id": "$SESSION_ID", "content": "$CONTENT"}\'', "tool_call": 'curl -X POST http://localhost:8000/api/tool-calls -H "Content-Type: application/json" -d \'{"tool_name": "$TOOL_NAME", "parameters": $TOOL_PARAMS, "result_status": "$RESULT_STATUS", "execution_time_ms": $EXECUTION_TIME}\'', # File Operations "file_modified": 'curl -X POST http://localhost:8000/api/activities -H "Content-Type: application/json" -d \'{"session_id": "$SESSION_ID", "file_path": "$FILE_PATH", "action": "$ACTION"}\'', } } def generate_comprehensive_config() -> Dict[str, Any]: """Generate comprehensive hook configuration with all hook types.""" return { "hooks": { # Session Management "session_start": 'curl -X POST http://localhost:8000/api/sessions/start -H "Content-Type: application/json" -d \'{"project_path": "$PWD", "start_time": "$TIMESTAMP", "user": "$USER"}\'', "session_end": 'curl -X POST http://localhost:8000/api/sessions/end -H "Content-Type: application/json" -d \'{"session_id": "$SESSION_ID", "end_time": "$TIMESTAMP"}\'', # Core Interactions "conversation_update": 'curl -X POST http://localhost:8000/api/conversations -H "Content-Type: application/json" -d \'{"session_id": "$SESSION_ID", "content": "$CONTENT", "timestamp": "$TIMESTAMP"}\'', "tool_call": 'curl -X POST http://localhost:8000/api/tool-calls -H "Content-Type: application/json" -d \'{"tool_name": "$TOOL_NAME", "parameters": $TOOL_PARAMS, "result_status": "$RESULT_STATUS", "execution_time_ms": $EXECUTION_TIME, "timestamp": "$TIMESTAMP"}\'', # File Operations "file_modified": 'curl -X POST http://localhost:8000/api/activities -H "Content-Type: application/json" -d \'{"session_id": "$SESSION_ID", "file_path": "$FILE_PATH", "action": "$ACTION", "timestamp": "$TIMESTAMP"}\'', # Performance & Debugging "tool_error": 'curl -X POST http://localhost:8000/api/hooks/tool-error -H "Content-Type: application/json" -d \'{"tool_name": "$TOOL_NAME", "error_type": "$ERROR_TYPE", "error_message": "$ERROR_MESSAGE", "stack_trace": "$STACK_TRACE", "parameters": $TOOL_PARAMS}\'', "waiting_period_start": 'curl -X POST http://localhost:8000/api/hooks/waiting-period -H "Content-Type: application/json" -d \'{"reason": "thinking", "context": "$CONTEXT"}\'', "waiting_period_end": 'curl -X POST http://localhost:8000/api/hooks/waiting-period -H "Content-Type: application/json" -d \'{"reason": "thinking", "duration_ms": $DURATION_MS, "end_time": "$TIMESTAMP"}\'', "memory_usage": 'curl -X POST http://localhost:8000/api/hooks/performance -H "Content-Type: application/json" -d \'{"metric_type": "memory", "value": $MEMORY_MB, "unit": "MB", "threshold_exceeded": $THRESHOLD_EXCEEDED}\'', "large_file_warning": 'curl -X POST http://localhost:8000/api/hooks/performance -H "Content-Type: application/json" -d \'{"metric_type": "file_size", "value": $FILE_SIZE_MB, "unit": "MB", "threshold_exceeded": true}\'', # Code Quality & Analysis "code_analysis": 'curl -X POST http://localhost:8000/api/hooks/code-quality -H "Content-Type: application/json" -d \'{"event_type": "analysis", "file_path": "$FILE_PATH", "tool_name": "$ANALYSIS_TOOL", "status": "$STATUS", "issues_count": $ISSUES_COUNT, "details": $DETAILS}\'', "test_execution": 'curl -X POST http://localhost:8000/api/hooks/code-quality -H "Content-Type: application/json" -d \'{"event_type": "test", "tool_name": "$TEST_FRAMEWORK", "status": "$STATUS", "details": {"passed": $PASSED_COUNT, "failed": $FAILED_COUNT}, "duration_ms": $DURATION_MS}\'', "build_process": 'curl -X POST http://localhost:8000/api/hooks/code-quality -H "Content-Type: application/json" -d \'{"event_type": "build", "tool_name": "$BUILD_TOOL", "status": "$STATUS", "duration_ms": $DURATION_MS}\'', "dependency_change": 'curl -X POST http://localhost:8000/api/hooks/environment -H "Content-Type: application/json" -d \'{"event_type": "dependency_change", "config_file": "$PACKAGE_FILE", "changes": {"action": "$ACTION", "package": "$PACKAGE_NAME", "version": "$VERSION"}}\'', # Development Workflow "context_switch": 'curl -X POST http://localhost:8000/api/hooks/workflow -H "Content-Type: application/json" -d \'{"event_type": "context_switch", "description": "Switched to $NEW_PROJECT", "metadata": {"from": "$OLD_PROJECT", "to": "$NEW_PROJECT"}}\'', "search_query": 'curl -X POST http://localhost:8000/api/hooks/workflow -H "Content-Type: application/json" -d \'{"event_type": "search_query", "description": "$SEARCH_QUERY", "metadata": {"search_type": "$SEARCH_TYPE", "context": "$CONTEXT"}}\'', "browser_tab": 'curl -X POST http://localhost:8000/api/hooks/workflow -H "Content-Type: application/json" -d \'{"event_type": "browser_tab", "description": "$TAB_TITLE", "metadata": {"url": "$TAB_URL", "category": "$TAB_CATEGORY"}}\'', "copy_paste": 'curl -X POST http://localhost:8000/api/hooks/workflow -H "Content-Type: application/json" -d \'{"event_type": "copy_paste", "description": "Code copied/pasted", "metadata": {"action": "$ACTION", "source": "$SOURCE", "lines": $LINE_COUNT}}\'', # Collaboration & Communication "external_resource": 'curl -X POST http://localhost:8000/api/hooks/collaboration -H "Content-Type: application/json" -d \'{"event_type": "external_resource", "interaction_type": "$RESOURCE_TYPE", "resource_url": "$URL", "query_or_topic": "$TOPIC"}\'', "ai_question": 'curl -X POST http://localhost:8000/api/hooks/collaboration -H "Content-Type: application/json" -d \'{"event_type": "ai_question", "query_or_topic": "$QUESTION", "metadata": {"question_type": "$QUESTION_TYPE", "complexity": "$COMPLEXITY"}}\'', "code_explanation": 'curl -X POST http://localhost:8000/api/hooks/collaboration -H "Content-Type: application/json" -d \'{"event_type": "code_explanation", "query_or_topic": "$CODE_CONTEXT", "metadata": {"explanation_type": "$TYPE", "code_lines": $CODE_LINES}}\'', "review_request": 'curl -X POST http://localhost:8000/api/hooks/collaboration -H "Content-Type: application/json" -d \'{"event_type": "review_request", "query_or_topic": "$REVIEW_SCOPE", "metadata": {"files_count": $FILES_COUNT, "review_type": "$REVIEW_TYPE"}}\'', # Project Intelligence "refactor_start": 'curl -X POST http://localhost:8000/api/hooks/project-intelligence -H "Content-Type: application/json" -d \'{"event_type": "refactor", "scope": "$SCOPE", "complexity": "$COMPLEXITY", "files_affected": $FILES_LIST}\'', "refactor_end": 'curl -X POST http://localhost:8000/api/hooks/project-intelligence -H "Content-Type: application/json" -d \'{"event_type": "refactor", "end_time": "$TIMESTAMP", "duration_minutes": $DURATION_MIN, "outcome": "$OUTCOME", "notes": "$NOTES"}\'', "feature_flag": 'curl -X POST http://localhost:8000/api/hooks/project-intelligence -H "Content-Type: application/json" -d \'{"event_type": "feature_flag", "scope": "$SCOPE", "notes": "Feature flag: $FLAG_NAME - $ACTION"}\'', "debugging_session": 'curl -X POST http://localhost:8000/api/hooks/project-intelligence -H "Content-Type: application/json" -d \'{"event_type": "debugging_session", "complexity": "$COMPLEXITY", "files_affected": $FILES_LIST, "notes": "$DEBUG_CONTEXT"}\'', "documentation_update": 'curl -X POST http://localhost:8000/api/hooks/project-intelligence -H "Content-Type: application/json" -d \'{"event_type": "documentation_update", "scope": "small", "files_affected": ["$DOC_FILE"], "notes": "$UPDATE_DESCRIPTION"}\'', # Environment & Setup "environment_change": 'curl -X POST http://localhost:8000/api/hooks/environment -H "Content-Type: application/json" -d \'{"event_type": "env_change", "environment": "$NEW_ENV", "impact_level": "$IMPACT_LEVEL"}\'', "config_update": 'curl -X POST http://localhost:8000/api/hooks/environment -H "Content-Type: application/json" -d \'{"event_type": "config_update", "config_file": "$CONFIG_FILE", "changes": $CONFIG_CHANGES, "impact_level": "$IMPACT_LEVEL"}\'', "security_scan": 'curl -X POST http://localhost:8000/api/hooks/environment -H "Content-Type: application/json" -d \'{"event_type": "security_scan", "changes": {"tool": "$SCAN_TOOL", "vulnerabilities": $VULN_COUNT, "severity": "$MAX_SEVERITY"}}\'', "performance_benchmark": 'curl -X POST http://localhost:8000/api/hooks/environment -H "Content-Type: application/json" -d \'{"event_type": "performance_benchmark", "changes": {"benchmark_type": "$BENCHMARK_TYPE", "results": $BENCHMARK_RESULTS}}\'', # Learning & Knowledge "learning_session": 'curl -X POST http://localhost:8000/api/hooks/learning -H "Content-Type: application/json" -d \'{"event_type": "learning_session", "topic": "$LEARNING_TOPIC", "confidence_before": $CONFIDENCE_BEFORE, "confidence_after": $CONFIDENCE_AFTER, "duration_ms": $DURATION_MS}\'', "tutorial_follow": 'curl -X POST http://localhost:8000/api/hooks/learning -H "Content-Type: application/json" -d \'{"event_type": "tutorial", "topic": "$TUTORIAL_TOPIC", "resource_url": "$TUTORIAL_URL", "notes": "$TUTORIAL_NOTES"}\'', "experimentation": 'curl -X POST http://localhost:8000/api/hooks/learning -H "Content-Type: application/json" -d \'{"event_type": "experimentation", "topic": "$EXPERIMENT_TYPE", "notes": "$EXPERIMENT_DESCRIPTION"}\'', "knowledge_gap": 'curl -X POST http://localhost:8000/api/hooks/learning -H "Content-Type: application/json" -d \'{"event_type": "knowledge_gap", "topic": "$UNKNOWN_CONCEPT", "notes": "$GAP_DESCRIPTION"}\'', # Quality Assurance "manual_testing": 'curl -X POST http://localhost:8000/api/hooks/code-quality -H "Content-Type: application/json" -d \'{"event_type": "manual_test", "status": "$TEST_RESULT", "details": {"test_type": "$TEST_TYPE", "scenarios": $SCENARIO_COUNT}, "duration_ms": $DURATION_MS}\'', "bug_reproduction": 'curl -X POST http://localhost:8000/api/hooks/project-intelligence -H "Content-Type: application/json" -d \'{"event_type": "bug_reproduction", "complexity": "$BUG_COMPLEXITY", "notes": "$BUG_DESCRIPTION", "outcome": "$REPRODUCTION_RESULT"}\'', "edge_case_testing": 'curl -X POST http://localhost:8000/api/hooks/code-quality -H "Content-Type: application/json" -d \'{"event_type": "edge_case_test", "status": "$TEST_RESULT", "details": {"edge_cases": $EDGE_CASE_COUNT, "findings": "$FINDINGS"}}\'', "user_feedback": 'curl -X POST http://localhost:8000/api/hooks/collaboration -H "Content-Type: application/json" -d \'{"event_type": "user_feedback", "query_or_topic": "$FEEDBACK_TOPIC", "response_quality": $FEEDBACK_RATING, "metadata": {"feedback_type": "$FEEDBACK_TYPE", "urgency": "$URGENCY"}}\'', }, "hook_settings": { "timeout": 10, "retry_count": 3, "async": True, "log_errors": True, "log_file": "~/.claude-hooks.log" } } def generate_selective_config(categories: list) -> Dict[str, Any]: """Generate selective hook configuration based on categories.""" full_config = generate_comprehensive_config() category_hooks = { "essential": ["session_start", "session_end", "conversation_update", "tool_call", "file_modified"], "performance": ["tool_error", "waiting_period_start", "waiting_period_end", "memory_usage", "large_file_warning"], "code_quality": ["code_analysis", "test_execution", "build_process", "dependency_change"], "workflow": ["context_switch", "search_query", "browser_tab", "copy_paste"], "collaboration": ["external_resource", "ai_question", "code_explanation", "review_request"], "intelligence": ["refactor_start", "refactor_end", "feature_flag", "debugging_session", "documentation_update"], "environment": ["environment_change", "config_update", "security_scan", "performance_benchmark"], "learning": ["learning_session", "tutorial_follow", "experimentation", "knowledge_gap"], "testing": ["manual_testing", "bug_reproduction", "edge_case_testing", "user_feedback"] } selected_hooks = set() for category in categories: if category in category_hooks: selected_hooks.update(category_hooks[category]) return { "hooks": { hook: full_config["hooks"][hook] for hook in selected_hooks if hook in full_config["hooks"] }, "hook_settings": full_config["hook_settings"] } def main(): """Generate all hook configurations.""" configs = { "basic": generate_basic_config(), "comprehensive": generate_comprehensive_config(), "essential": generate_selective_config(["essential"]), "developer": generate_selective_config(["essential", "performance", "code_quality"]), "power_user": generate_selective_config(["essential", "performance", "workflow", "intelligence"]), "research": generate_selective_config(["essential", "learning", "collaboration", "intelligence"]), "team": generate_selective_config(["essential", "collaboration", "testing", "intelligence"]) } # Generate configuration files for config_name, config_data in configs.items(): filename = f"claude-hooks-{config_name}.json" with open(filename, "w") as f: json.dump(config_data, f, indent=2) print(f"Generated {filename}") # Generate README for configurations readme_content = """# Claude Code Hook Configurations This directory contains various pre-configured hook setups for different use cases: ## Available Configurations ### basic.json Essential hooks for basic session and tool tracking. - Session management - Tool calls - File modifications - Conversations ### comprehensive.json Complete hook setup with all available hook types. - All performance monitoring - Code quality tracking - Learning analytics - Collaboration insights - Project intelligence ### essential.json Minimal setup for core functionality. ### developer.json Focused on development workflow and code quality. - Essential hooks - Performance monitoring - Code quality checks ### power_user.json Advanced setup for productivity optimization. - Essential hooks - Performance tracking - Workflow analysis - Project intelligence ### research.json Optimized for learning and exploration. - Essential hooks - Learning tracking - External resource usage - Knowledge gap analysis ### team.json Team-focused configuration for collaboration. - Essential hooks - Collaboration tracking - Testing workflows - Project intelligence ## Installation 1. Choose the configuration that matches your needs 2. Copy the JSON content to your Claude Code settings file: - macOS/Linux: `~/.config/claude/settings.json` - Windows: `%APPDATA%\\claude\\settings.json` 3. Ensure Claude Code Tracker is running on port 8000 4. Start using Claude Code - hooks will automatically track your activity! ## Available Hook Variables Each hook can use these variables that Claude Code provides: ### Session Variables - `$SESSION_ID` - Current session identifier - `$TIMESTAMP` - Current timestamp (ISO format) - `$PWD` - Current working directory - `$USER` - System username ### Tool Variables - `$TOOL_NAME` - Name of tool being called - `$TOOL_PARAMS` - Tool parameters (JSON) - `$RESULT_STATUS` - Success/error status - `$EXECUTION_TIME` - Tool execution time (ms) - `$ERROR_TYPE` - Type of error - `$ERROR_MESSAGE` - Error message - `$STACK_TRACE` - Error stack trace ### File Variables - `$FILE_PATH` - Path to modified file - `$ACTION` - File action (created/modified/deleted) - `$FILE_SIZE_MB` - File size in megabytes ### Context Variables - `$CONTENT` - Conversation content - `$CONTEXT` - Current context description - `$SEARCH_QUERY` - What you're searching for - `$NEW_PROJECT` - Project being switched to - `$OLD_PROJECT` - Project being switched from ### Performance Variables - `$MEMORY_MB` - Memory usage in MB - `$DURATION_MS` - Duration in milliseconds - `$THRESHOLD_EXCEEDED` - Boolean for threshold alerts And many more! Each hook type has specific variables available. ## Customization You can modify any configuration by: 1. Adding/removing specific hooks 2. Changing API endpoints or ports 3. Adjusting timeout and retry settings 4. Adding custom metadata to hook calls ## Troubleshooting If hooks aren't working: 1. Ensure Claude Code Tracker server is running 2. Check that curl is installed 3. Verify the API endpoints are accessible 4. Check Claude Code logs for hook execution errors 5. Test individual hooks manually with curl For more help, see the documentation at `/dashboard/docs/hook-setup`. """ with open("README.md", "w") as f: f.write(readme_content) print("Generated README.md with configuration guide") print(f"\\nGenerated {len(configs)} hook configurations:") for name in configs.keys(): print(f" - claude-hooks-{name}.json") if __name__ == "__main__": main()