From 7a2966367d21fec79057d69cee41bac213688848 Mon Sep 17 00:00:00 2001 From: lmiranda Date: Fri, 23 Jan 2026 12:46:18 -0500 Subject: [PATCH] feat(claude-config-maintainer): auto-enforce mandatory behavior rules SessionStart hook checks if CLAUDE.md has mandatory rules. If missing, adds them automatically. Rules enforced: - Check everything when user asks - Believe user when they say something's wrong - Never say "done" without verification - Show exactly what user asks for Co-Authored-By: Claude Opus 4.5 --- .../hooks/enforce-rules.sh | 68 +++++++++++++++++++ .../claude-config-maintainer/hooks/hooks.json | 10 +++ 2 files changed, 78 insertions(+) create mode 100755 plugins/claude-config-maintainer/hooks/enforce-rules.sh create mode 100644 plugins/claude-config-maintainer/hooks/hooks.json diff --git a/plugins/claude-config-maintainer/hooks/enforce-rules.sh b/plugins/claude-config-maintainer/hooks/enforce-rules.sh new file mode 100755 index 0000000..a451a1a --- /dev/null +++ b/plugins/claude-config-maintainer/hooks/enforce-rules.sh @@ -0,0 +1,68 @@ +#!/bin/bash +# claude-config-maintainer: enforce mandatory behavior rules +# Checks if CLAUDE.md has the rules, adds them if missing + +PREFIX="[claude-config-maintainer]" + +# Find CLAUDE.md in current directory or parent +CLAUDE_MD="" +if [ -f "./CLAUDE.md" ]; then + CLAUDE_MD="./CLAUDE.md" +elif [ -f "../CLAUDE.md" ]; then + CLAUDE_MD="../CLAUDE.md" +fi + +# If no CLAUDE.md found, exit silently +if [ -z "$CLAUDE_MD" ]; then + exit 0 +fi + +# Check if mandatory rules exist +if grep -q "MANDATORY BEHAVIOR RULES" "$CLAUDE_MD" 2>/dev/null; then + # Rules exist, all good + exit 0 +fi + +# Rules missing - add them +RULES='## ⛔ MANDATORY BEHAVIOR RULES - READ FIRST + +**These rules are NON-NEGOTIABLE. Violating them wastes the user'\''s time and money.** + +### 1. WHEN USER ASKS YOU TO CHECK SOMETHING - CHECK EVERYTHING +- Search ALL locations, not just where you think it is +- Check cache directories: `~/.claude/plugins/cache/` +- Check installed: `~/.claude/plugins/marketplaces/` +- Check source directories +- **NEVER say "no" or "that'\''s not the issue" without exhaustive verification** + +### 2. WHEN USER SAYS SOMETHING IS WRONG - BELIEVE THEM +- The user knows their system better than you +- Investigate thoroughly before disagreeing +- **Your confidence is often wrong. User'\''s instincts are often right.** + +### 3. NEVER SAY "DONE" WITHOUT VERIFICATION +- Run the actual command/script to verify +- Show the output to the user +- **"Done" means VERIFIED WORKING, not "I made changes"** + +### 4. SHOW EXACTLY WHAT USER ASKS FOR +- If user asks for messages, show the MESSAGES +- If user asks for code, show the CODE +- **Do not interpret or summarize unless asked** + +**FAILURE TO FOLLOW THESE RULES = WASTED USER TIME = UNACCEPTABLE** + +--- + +' + +# Create temp file with rules + existing content +{ + head -1 "$CLAUDE_MD" + echo "" + echo "$RULES" + tail -n +2 "$CLAUDE_MD" +} > "${CLAUDE_MD}.tmp" + +mv "${CLAUDE_MD}.tmp" "$CLAUDE_MD" +echo "$PREFIX Added mandatory behavior rules to CLAUDE.md" diff --git a/plugins/claude-config-maintainer/hooks/hooks.json b/plugins/claude-config-maintainer/hooks/hooks.json new file mode 100644 index 0000000..d80c531 --- /dev/null +++ b/plugins/claude-config-maintainer/hooks/hooks.json @@ -0,0 +1,10 @@ +{ + "hooks": { + "SessionStart": [ + { + "type": "command", + "command": "${CLAUDE_PLUGIN_ROOT}/hooks/enforce-rules.sh" + } + ] + } +}