Skip to content

Commit 459a7fd

Browse files
pfranktestingclaude
andcommitted
Add check-links.sh script for session-start URL verification
Checks all help resource URLs in checkApaFormatting.js in parallel and reports any dead links via a systemMessage. Used by the local SessionStart hook in .claude/settings.local.json (gitignored). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 899eed6 commit 459a7fd

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

scripts/check-links.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
# Check all help resource URLs in checkApaFormatting.js
3+
# Used by the SessionStart hook. Outputs JSON with systemMessage if any links fail.
4+
5+
REPO_DIR="$(cd "$(dirname "$0")/.." && pwd)"
6+
JS_FILE="$REPO_DIR/src/checks/checkApaFormatting.js"
7+
8+
[ -f "$JS_FILE" ] || exit 0
9+
10+
# Extract https:// URLs from url: lines
11+
mapfile -t urls < <(grep -oP "url:\s*['\"]?\K(https://[^'\"]+)" "$JS_FILE" | sort -u)
12+
13+
tmpdir=$(mktemp -d)
14+
15+
for url in "${urls[@]}"; do
16+
(
17+
code=$(curl -s --head --connect-timeout 5 --max-time 8 -o /dev/null -w "%{http_code}" -L "$url" 2>/dev/null)
18+
echo "$code $url" > "$tmpdir/$(echo -n "$url" | md5sum | cut -d' ' -f1).txt"
19+
) &
20+
done
21+
22+
wait
23+
24+
failed=()
25+
while IFS= read -r result_file; do
26+
read -r code url < "$result_file"
27+
# 200 OK, 301/302/303 redirects, 403 bot protection (Scribbr) = treat as live
28+
if [[ ! "$code" =~ ^(200|301|302|303|403)$ ]]; then
29+
failed+=("HTTP $code$url")
30+
fi
31+
done < <(find "$tmpdir" -name "*.txt")
32+
33+
rm -rf "$tmpdir"
34+
35+
if [ ${#failed[@]} -gt 0 ]; then
36+
joined=$(printf '%s\\n' "${failed[@]}")
37+
printf '{"systemMessage": "⚠️ APA Coach URL check: %d link(s) may be dead:\\n%s"}\n' "${#failed[@]}" "$joined"
38+
fi

0 commit comments

Comments
 (0)