13-layer behavioral enforcement system for Claude Code CLI.
Claude Code gets progressively lazier during long sessions — skipping questions, jumping to conclusions, acting without explaining, anchoring to the first solution. This happens because of fundamental LLM architectural limitations (context rot, RLHF confidence bias, next-token prediction shortcuts) that prompt-only fixes can't reliably solve.
Claude-Control uses mechanical enforcement — hooks that block tool calls, inject reminders every turn, force self-critique, and track behavioral metrics — to fight the architecture, not just the symptoms.
| Layer | Mechanism | What It Catches |
|---|---|---|
| Compute | effortLevel: xhigh |
Shallow thinking, low-effort responses |
| Persistent rules | CLAUDE.md (12 rules + compact instructions) | Rule forgetting after context compaction |
| Destructive blocking | Hookify rule | rm -rf /, mkfs, dd, reboot, shutdown |
| System file protection | Hookify rule | Edits to /etc/fstab, GRUB, systemd, /boot/ |
| GRUB safety | Hookify rule | Using GRUB_CMDLINE_LINUX_DEFAULT (breaks recovery mode) |
| Log enforcement | Hookify rule | Session ending without updating the session log |
| Read-before-edit | PreToolUse hook | Editing files without reading them first |
| Explain-before-act | PreToolUse hook (transcript) | Running modifying commands with no explanation |
| Answer-before-act | PreToolUse hook (transcript) | Ignoring user questions to jump into tool calls |
| Context injection | SessionStart + UserPromptSubmit hooks | Rule reinforcement on every prompt |
| Self-critique | Stop hook | Incomplete work, glossed-over anomalies |
| Metrics | PostToolUse hook | Read:Edit ratio tracking for degradation detection |
| Structured diagnosis | /diagnose slash command |
Lazy investigation, skipping evidence |
git clone https://github.com/jeremiahbeasley/Claude-Control.git
cd Claude-Control
chmod +x install.sh
./install.shThe installer:
- Copies hook scripts, slash commands, and hookify rules
- Merges hook configuration into your existing
settings.json - Installs the
hookifyandclaude-md-managementplugins - Patches a hookify bug where "block" rules only warn instead of actually blocking
- Sets up CLAUDE.md and the memory system
- Is idempotent (safe to re-run)
If you prefer not to run the installer:
- Copy
hooks/*.pyto~/.claude/hooks/ - Copy
commands/*.mdto~/.claude/commands/ - Copy
hookify-rules/*.local.mdto~/.claude/ - Merge
templates/settings-hooks.jsoninto~/.claude/settings.json - Copy
templates/CLAUDE.mdto~/CLAUDE.md - Copy
templates/memory/*.mdto your project's memory directory - Run
claude plugin install hookify && claude plugin install claude-md-management - Apply the hookify patch (see Hookify Bug below)
read-before-edit.py (PreToolUse) — Tracks every file Read in /tmp/claude-reads-this-session.txt. If Edit or Write is attempted on a file not in the tracker, the hook emits permissionDecision: deny and the tool call is blocked. Write to new (non-existent) files is allowed.
transcript-check.py (PreToolUse) — Reads the conversation's JSONL transcript file (available via transcript_path in hook input). Checks two things before any modifying tool call: (1) did the user ask a question that hasn't been answered yet? (2) is there explanation text before this tool call? Fires warnings if either check fails. Read-only commands are exempt.
post-tool-metrics.py (PostToolUse) — Logs tool usage to /tmp/claude-tool-metrics.jsonl. Tracks tool name, timestamp, and file path or command. Use this to monitor the Read:Edit ratio — healthy sessions maintain 3:1 or better; degraded sessions collapse below 2:1.
SessionStart — Clears the read tracker, reminds Claude to update the session log.
UserPromptSubmit — Fires on every user message. Injects reminders: answer questions first, investigate before theorizing, present plans before executing, stay on topic.
Stop — Self-critique gate. Asks 5 questions: Did I answer everything? Did I do everything requested? Did I communicate before acting? Any anomaly I glossed over? Would this survive "are you sure?"
Hookify is an official Claude Code plugin that processes .local.md rule files. Rules pattern-match against tool inputs and can warn or block.
- block-destructive-ops — Blocks
rm -rf /,mkfs,dd if=, writes to/dev/sd*,shutdown,reboot - protect-system-files — Blocks edits to
/etc/fstab,/etc/default/grub,/etc/network, systemd services,/boot/ - grub-not-default — Blocks edits to GRUB config that use
GRUB_CMDLINE_LINUX_DEFAULT(doesn't apply to recovery mode) - require-log-update — Blocks session stop if the transcript doesn't contain
memory/log.md(forces log updates)
/diagnose <problem> — 7-phase structured investigation: clarify symptom, gather evidence, identify anomalies, determine root cause, generate options (minimum 2), recommend, verify. Prevents the lazy pattern of jumping to the first theory.
/status [all|services|storage|processes] — Generates an organized system status report with tables. Not raw CLI output — interpreted information with problems flagged.
The hookify plugin (as of 2026-04-25) has a bug where pretooluse.py and stop.py don't pass hook_event_name to the rule engine. Without this, "block" rules only show a warning message — they don't emit permissionDecision: deny, so the tool call proceeds anyway.
The installer patches this automatically. If you installed manually, add this line to ~/.claude/plugins/cache/claude-plugins-official/hookify/*/hooks/pretooluse.py before engine.evaluate_rules():
input_data['hook_event_name'] = 'PreToolUse'And in stop.py:
input_data['hook_event_name'] = 'Stop'LLMs degrade over long conversations. This isn't a prompting problem — it's architectural:
- Context rot: Accuracy drops 30%+ for information in the middle of long contexts (Chroma 2025)
- RLHF confidence bias: Training rewards confident-sounding answers over correct ones
- Next-token shortcuts: The most statistically likely response is often the shallowest
- Effort decay: Without explicit effort parameters, reasoning depth decreases as context grows
Prompt-only fixes ("try harder", "be thorough") have weak and inconsistent effects. Mechanical enforcement — hooks that block, inject, and track — fights the architecture directly.
This system was developed over 27 Claude Code sessions managing a Proxmox homelab, where every failure pattern was documented, analyzed, and addressed with a specific enforcement layer. It's been tested in real production use, not theoretical scenarios.
Create a .local.md file in ~/.claude/ with this format:
---
name: my-rule
enabled: true
event: bash
pattern: dangerous-command-regex
action: block
---
Message shown when the rule fires.event can be bash (command matching), file (edit matching), or stop. action can be block (deny tool call) or warn (show message, allow).
For file rules with multiple conditions:
---
name: my-file-rule
enabled: true
event: file
action: block
conditions:
- field: file_path
operator: regex_match
pattern: /path/to/protect
- field: new_text
operator: contains
pattern: dangerous-string
---Create a .md file in ~/.claude/commands/ with YAML frontmatter:
---
description: What this command does
argument-hint: <required-arg>
---
Instructions for Claude when this command is invoked.
Use $ARGUMENTS to reference what the user passed.- Remove hookify rules you don't need from
~/.claude/ - Edit the
UserPromptSubmithook insettings.jsonto change injected reminders - Change
effortLevelfromxhightohighif response speed matters more than depth
- Claude Code CLI
- Python 3.6+
- bash
MIT