Skip to content

Universal SEO skill for Claude Code. 26 sub-skills + 19 sub-agents covering technical SEO, E-E-A-T, schema, GEO/AEO, agent readiness (Lighthouse Agentic Browsing, WebMCP, llms.txt), backlinks, local SEO, e-commerce, international SEO, Google APIs, and PDF/Excel reporting. 9 optional extensions for live SEO data.

fix(hooks): skip the Python probe for files that cannot hold JSON-LD

AdityaWagh06a3f0e3c9b814
diff --git a/hooks/run-python-hook.js b/hooks/run-python-hook.js
index f71d3dc..67e7dff 100644
--- a/hooks/run-python-hook.js
+++ b/hooks/run-python-hook.js
@@ -3,6 +3,19 @@
const { spawnSync } = require("child_process");
+// Same list as valid_extensions in validate-schema.py. The hook fires on every
+// Edit and Write, so skip the Python probe for files that cannot hold JSON-LD.
+const SCHEMA_FILE_EXTENSIONS = [".html", ".htm", ".jsx", ".tsx", ".vue", ".svelte", ".php", ".ejs"];
+
+function cannotHoldSchema(filePath) {
+ // An unsubstituted "${tool_input.file_path}" leaves the path to the stdin event.
+ if (!filePath || filePath.includes("${")) {
+ return false;
+ }
+ const lower = filePath.toLowerCase();
+ return !SCHEMA_FILE_EXTENSIONS.some((ext) => lower.endsWith(ext));
+}
+
function stripWrappingQuotes(value) {
return value.replace(/^["']|["']$/g, "");
}
@@ -39,7 +52,7 @@ function probe(candidate) {
function main() {
const [, , hookScript, ...hookArgs] = process.argv;
- if (!hookScript) {
+ if (!hookScript || cannotHoldSchema(hookArgs[0])) {
process.exit(0);
}
diff --git a/hooks/validate-schema.py b/hooks/validate-schema.py
index 9b3bb0f..70f983c 100755
--- a/hooks/validate-schema.py
+++ b/hooks/validate-schema.py
@@ -33,8 +33,10 @@ Hook configuration in ~/.claude/settings.json:
}
}
-Note: matcher filters by tool name only (Edit, Write). The script itself
-checks if the file contains schema markup before validating.
+Note: matcher filters by tool name only (Edit, Write). run-python-hook.js
+exits before starting Python when the edited file's extension is not in
+valid_extensions below, and the script itself checks if the file contains
+schema markup before validating.
"""
import json
diff --git a/tests/test_cross_platform_hooks.py b/tests/test_cross_platform_hooks.py
index 51ba968..ac1d08e 100644
--- a/tests/test_cross_platform_hooks.py
+++ b/tests/test_cross_platform_hooks.py
@@ -4,6 +4,7 @@ from __future__ import annotations
import json
import os
+import re
import shutil
import subprocess
import sys
@@ -54,7 +55,7 @@ def test_hook_launcher_preserves_blocking_exit_code_two(tmp_path: Path) -> None:
script = tmp_path / "block.py"
script.write_text(
"import sys\n"
- "assert sys.argv[1] == 'payload'\n"
+ "assert sys.argv[1] == 'page.html'\n"
"sys.exit(2)\n",
encoding="utf-8",
)
@@ -62,7 +63,7 @@ def test_hook_launcher_preserves_blocking_exit_code_two(tmp_path: Path) -> None:
env["CLAUDE_SEO_PYTHON"] = sys.executable
proc = subprocess.run(
- [node, str(HOOK_LAUNCHER), str(script), "payload"],
+ [node, str(HOOK_LAUNCHER), str(script), "page.html"],
env=env,
capture_output=True,
text=True,
@@ -72,6 +73,42 @@ def test_hook_launcher_preserves_blocking_exit_code_two(tmp_path: Path) -> None:
assert proc.returncode == 2
+def test_hook_launcher_skips_files_that_cannot_hold_schema(tmp_path: Path) -> None:
+ node = shutil.which("node")
+ if not node:
+ pytest.skip("node is not available in this test environment")
+
+ script = tmp_path / "block.py"
+ script.write_text("import sys\nsys.exit(2)\n", encoding="utf-8")
+ env = os.environ.copy()
+ env["CLAUDE_SEO_PYTHON"] = sys.executable
+
+ def run(path_arg: str) -> int:
+ return subprocess.run(
+ [node, str(HOOK_LAUNCHER), str(script), path_arg],
+ env=env,
+ capture_output=True,
+ text=True,
+ timeout=15,
+ ).returncode
+
+ # Python never starts for files the validator would ignore anyway.
+ assert run("notes.md") == 0
+ assert run("app/main.py") == 0
+ # Schema-bearing files, and an unsubstituted placeholder, still reach Python.
+ assert run("Page.HTML") == 2
+ assert run("${tool_input.file_path}") == 2
+
+
+def test_hook_launcher_extensions_match_validator() -> None:
+ launcher = HOOK_LAUNCHER.read_text(encoding="utf-8")
+ validator = (REPO_ROOT / "hooks" / "validate-schema.py").read_text(encoding="utf-8")
+ js_list = re.search(r"SCHEMA_FILE_EXTENSIONS = \[([^\]]*)\]", launcher).group(1)
+ py_list = re.search(r"valid_extensions = \(([^)]*)\)", validator).group(1)
+
+ assert re.findall(r'"([^"]+)"', js_list) == re.findall(r'"([^"]+)"', py_list)
+
+
def test_windows_installer_prefers_py_launcher_and_rejects_store_stubs() -> None:
text = INSTALL_PS1.read_text(encoding="utf-8")
py_pos = text.index("Exe = 'py'; Args = @('-3')")