From b09fdebdbf31d0dd5ca1adec187d4173265b9172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20=C5=BBuraw?= <9116238+krzysztofzuraw@users.noreply.github.com> Date: Wed, 8 Oct 2025 13:41:28 +0200 Subject: [PATCH 1/2] Optimize Claude Code hooks to only run on src/ changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updated three Claude Code hooks to skip validation when changes are outside the src/ directory: - check-as-any-pre.py: Exit early if file is not in src/ - graphql-check.py: Filter to only check src/ files - validation-check.sh: Skip type checking and linting if no src/ changes This optimization reduces unnecessary hook execution time when working on documentation, configuration, or other non-source files. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .claude/hooks/check-as-any-pre.py | 4 ++++ .claude/hooks/graphql-check.py | 5 +++++ .claude/hooks/validation-check.sh | 8 +++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.claude/hooks/check-as-any-pre.py b/.claude/hooks/check-as-any-pre.py index 8359bff4f94..1d4765e1715 100755 --- a/.claude/hooks/check-as-any-pre.py +++ b/.claude/hooks/check-as-any-pre.py @@ -30,6 +30,10 @@ def main(): if not file_path: sys.exit(0) + # Only check files in src/ directory + if not file_path.startswith("src/") and "/src/" not in file_path: + sys.exit(0) + # Convert to Path object for easier handling path = Path(file_path) diff --git a/.claude/hooks/graphql-check.py b/.claude/hooks/graphql-check.py index 931d1601a0e..aea5a12dfe6 100755 --- a/.claude/hooks/graphql-check.py +++ b/.claude/hooks/graphql-check.py @@ -29,6 +29,11 @@ if file_path: files_to_check.append(file_path) + # Only proceed if files are in src/ directory + src_files = [f for f in files_to_check if f.startswith("src/") or "/src/" in f] + if not src_files: + sys.exit(0) + # Check if any of the files are GraphQL query/mutation files graphql_files_modified = any( file_path.endswith("mutations.ts") or file_path.endswith("queries.ts") diff --git a/.claude/hooks/validation-check.sh b/.claude/hooks/validation-check.sh index a7fecacc210..4f30c76c453 100755 --- a/.claude/hooks/validation-check.sh +++ b/.claude/hooks/validation-check.sh @@ -1,5 +1,11 @@ #!/bin/bash +# Check if there are any changes in src/ directory +if ! git diff --name-only HEAD | grep -q '^src/'; then + echo 'â„šī¸ No changes in src/ directory, skipping validation' >&2 + exit 0 +fi + echo '🔍 Running final validation...' >&2 # Run type checking @@ -10,7 +16,7 @@ fi # Run linting if ! npm run lint; then - echo '❌ ESLint validation failed - please fix linting errors before completing the task' >&2 + echo '❌ ESLint validation failed - please fix linting errors before completing the task' >&2 exit 2 fi From 799452f122a1cfc67e4972470fbc4b186e0d0d82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20=C5=BBuraw?= <9116238+krzysztofzuraw@users.noreply.github.com> Date: Wed, 8 Oct 2025 13:44:50 +0200 Subject: [PATCH 2/2] Fix path matching in Claude Code hooks for better robustness MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addressed Copilot review feedback: - Use Path.parts for more precise path matching instead of string operations - Prevents false positives from paths like 'docs/src_files/' or 'test/mysrc/' - Fix graphql-check.py to use filtered src_files list consistently 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .claude/hooks/check-as-any-pre.py | 8 ++++---- .claude/hooks/graphql-check.py | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.claude/hooks/check-as-any-pre.py b/.claude/hooks/check-as-any-pre.py index 1d4765e1715..028c4269462 100755 --- a/.claude/hooks/check-as-any-pre.py +++ b/.claude/hooks/check-as-any-pre.py @@ -30,13 +30,13 @@ def main(): if not file_path: sys.exit(0) - # Only check files in src/ directory - if not file_path.startswith("src/") and "/src/" not in file_path: - sys.exit(0) - # Convert to Path object for easier handling path = Path(file_path) + # Only check files in src/ directory + if not path.parts or path.parts[0] != "src": + sys.exit(0) + # Check if it's a TypeScript file if path.suffix not in [".ts", ".tsx"]: sys.exit(0) diff --git a/.claude/hooks/graphql-check.py b/.claude/hooks/graphql-check.py index aea5a12dfe6..40dbb7969e0 100755 --- a/.claude/hooks/graphql-check.py +++ b/.claude/hooks/graphql-check.py @@ -6,6 +6,7 @@ import json import sys import os +from pathlib import Path try: data = json.load(sys.stdin) @@ -30,14 +31,14 @@ files_to_check.append(file_path) # Only proceed if files are in src/ directory - src_files = [f for f in files_to_check if f.startswith("src/") or "/src/" in f] + src_files = [f for f in files_to_check if Path(f).parts and Path(f).parts[0] == "src"] if not src_files: sys.exit(0) # Check if any of the files are GraphQL query/mutation files graphql_files_modified = any( file_path.endswith("mutations.ts") or file_path.endswith("queries.ts") - for file_path in files_to_check + for file_path in src_files ) if graphql_files_modified: