Skip to content

Commit 5b88965

Browse files
feat: add RuleCatch Stop hook — runs automatically every turn
rulecatch-check.sh runs when Claude finishes a turn, reporting any rule violations. Guaranteed to run (like verify-no-secrets.sh). Skips silently if RuleCatch isn't installed — zero overhead for new users. Added to project settings.json, global settings.json, GitHub Pages hooks section, project structure, and install-global references. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b98f773 commit 5b88965

5 files changed

Lines changed: 65 additions & 5 deletions

File tree

.claude/hooks/rulecatch-check.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
# RuleCatch Check Hook — Stop
3+
# Runs when Claude finishes a turn — reports any rule violations detected.
4+
# Guaranteed to run (stronger than CLAUDE.md command instructions).
5+
#
6+
# Based on Claude Code Mastery Guides V3-V5 by TheDecipherist
7+
8+
# Check if RuleCatch CLI is available
9+
if ! command -v npx &>/dev/null; then
10+
exit 0
11+
fi
12+
13+
# Check if @rulecatch/ai-pooler is available (quick check)
14+
# If not installed, skip silently — don't block the user
15+
if ! npx @rulecatch/ai-pooler@latest check --help &>/dev/null 2>&1; then
16+
exit 0
17+
fi
18+
19+
# Run RuleCatch violation check for the current session
20+
# --quiet: only output if violations found
21+
# --format: short summary suitable for hook output
22+
RESULT=$(npx @rulecatch/ai-pooler@latest check --quiet --format summary 2>/dev/null)
23+
24+
if [ -n "$RESULT" ] && [ "$RESULT" != "0 violations" ]; then
25+
echo "" >&2
26+
echo "📋 RuleCatch: $RESULT" >&2
27+
echo " Run 'pnpm ai:monitor' for details or check your dashboard." >&2
28+
# Exit 0 = inform but don't block (violations are warnings, not blockers)
29+
exit 0
30+
fi
31+
32+
exit 0

.claude/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
{
2929
"type": "command",
3030
"command": "bash .claude/hooks/verify-no-secrets.sh"
31+
},
32+
{
33+
"type": "command",
34+
"command": "bash .claude/hooks/rulecatch-check.sh"
3135
}
3236
]
3337
}

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ project/
461461
│ ├── commands/ # Slash commands (/review, /refactor, /worktree, /new-project, etc.)
462462
│ ├── skills/ # Triggered expertise & scaffolding templates
463463
│ ├── agents/ # Custom subagents
464-
│ └── hooks/ # Deterministic enforcement scripts
464+
│ └── hooks/ # Enforcement scripts (block-secrets, verify-no-secrets, rulecatch-check)
465465
├── project-docs/
466466
│ ├── ARCHITECTURE.md # System overview & data flow
467467
│ ├── INFRASTRUCTURE.md # Deployment & environment details

docs/index.html

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ <h3>Set Up Global Config (One Time)</h3>
281281
# Copy hooks for global enforcement
282282
mkdir -p ~/.claude/hooks
283283
cp .claude/hooks/block-secrets.py ~/.claude/hooks/
284-
cp .claude/hooks/verify-no-secrets.sh ~/.claude/hooks/</code></pre>
284+
cp .claude/hooks/verify-no-secrets.sh ~/.claude/hooks/
285+
cp .claude/hooks/rulecatch-check.sh ~/.claude/hooks/</code></pre>
285286
</div>
286287
</div>
287288

@@ -342,7 +343,8 @@ <h2>Project Structure</h2>
342343
│ └── hooks/
343344
│ ├── block-secrets.py # PreToolUse: block sensitive files
344345
│ ├── lint-on-save.sh # PostToolUse: lint after writes
345-
│ └── verify-no-secrets.sh # Stop: check for secrets
346+
│ ├── verify-no-secrets.sh # Stop: check for secrets
347+
│ └── rulecatch-check.sh # Stop: report RuleCatch violations
346348
├── project-docs/
347349
│ ├── ARCHITECTURE.md # System overview (authoritative)
348350
│ ├── INFRASTRUCTURE.md # Deployment details
@@ -659,6 +661,21 @@ <h3>verify-no-secrets.sh</h3>
659661
# Check for AWS keys
660662
if grep -qE 'AKIA[0-9A-Z]{16}' "$file"; then
661663
VIOLATIONS="${VIOLATIONS}\n - AWS ACCESS KEY in $file"
664+
fi</code></pre>
665+
</div>
666+
667+
<div class="hook-stage">
668+
<div class="hook-stage-header">
669+
<span class="hook-stage-tag hook-stop">Stop</span>
670+
<h3>rulecatch-check.sh</h3>
671+
</div>
672+
<p>Runs when Claude <strong>finishes a turn</strong>. Checks RuleCatch for any rule violations detected during the session. Skips silently if RuleCatch isn't installed &mdash; zero overhead for users who haven't set it up yet.</p>
673+
<pre class="language-bash"><code class="language-bash"># Run RuleCatch violation check
674+
RESULT=$(npx @rulecatch/ai-pooler@latest check --quiet --format summary 2>/dev/null)
675+
676+
if [ -n "$RESULT" ] && [ "$RESULT" != "0 violations" ]; then
677+
echo "📋 RuleCatch: $RESULT" >&2
678+
echo " Run 'pnpm ai:monitor' for details." >&2
662679
fi</code></pre>
663680
</div>
664681
</div>
@@ -676,7 +693,10 @@ <h3>Hook Configuration</h3>
676693
"hooks": [{ "type": "command", "command": "bash .claude/hooks/lint-on-save.sh" }]
677694
}],
678695
"Stop": [{
679-
"hooks": [{ "type": "command", "command": "bash .claude/hooks/verify-no-secrets.sh" }]
696+
"hooks": [
697+
{ "type": "command", "command": "bash .claude/hooks/verify-no-secrets.sh" },
698+
{ "type": "command", "command": "bash .claude/hooks/rulecatch-check.sh" }
699+
]
680700
}]
681701
}
682702
}</code></pre>
@@ -707,7 +727,7 @@ <h3><code>/install-global</code></h3>
707727
<ul>
708728
<li><strong>Smart merge</strong> &mdash; if you already have a global <code>CLAUDE.md</code>, it appends missing sections without overwriting yours</li>
709729
<li><strong>settings.json</strong> &mdash; merges deny rules and hooks (never removes existing ones)</li>
710-
<li><strong>Hooks</strong> &mdash; copies <code>block-secrets.py</code> and <code>verify-no-secrets.sh</code> to <code>~/.claude/hooks/</code></li>
730+
<li><strong>Hooks</strong> &mdash; copies <code>block-secrets.py</code>, <code>verify-no-secrets.sh</code>, and <code>rulecatch-check.sh</code> to <code>~/.claude/hooks/</code></li>
711731
</ul>
712732
<p>Reports exactly what was added, skipped, and merged. Your existing config is never overwritten.</p>
713733
</div>

global-claude-md/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
{
2828
"type": "command",
2929
"command": "bash ~/.claude/hooks/verify-no-secrets.sh"
30+
},
31+
{
32+
"type": "command",
33+
"command": "bash ~/.claude/hooks/rulecatch-check.sh"
3034
}
3135
]
3236
}

0 commit comments

Comments
 (0)