A deterministic, auditable, local-first AI policy engine for Claude Code.
Agent RuleZ provides a robust hook system that replaces fragile JSON configurations with readable YAML, enabling developers to enforce coding standards, inject context dynamically, and block dangerous operations with sub-10ms latency.
- Overview
- Why Use Agent RuleZ?
- Architecture
- Installation
- Quick Start
- Configuration Guide
- The Mastering Hooks Skill
- Governance & Policy
- Development
- CLI User Guide
- Agent Skill User Guide
Claude Code's native hook system relies on raw JSON configuration and shell commands, which can be opaque, hard to maintain, and lack conditional logic.
Agent RuleZ solves this by introducing a two-part system:
- The RuleZ Binary: A high-performance Rust executable that acts as the runtime hook handler.
- The Mastering Hooks Skill: An intelligent assistant that analyzes your project and generates configurations automatically.
Core Philosophy: LLMs do not enforce policy; they are subject to policy. Agent RuleZ is the policy authority.
| Problem with Native Hooks | Agent RuleZ Solution |
|---|---|
| Poor Readability | Human-friendly YAML configuration with comments. |
| No Conditionals | Match rules by file extension, directory, tool, or regex. |
| Safety Risks | Block operations like force push or edits to production. |
| Manual Setup | Intelligent skill that scans CLAUDE.md to auto-generate rules. |
| Opaque Decisions | Deterministic logging and "explainable" policy modes. |
- Role: Deterministic runtime engine.
- Language: Rust.
- Performance: <10ms execution time (cold start <5ms).
- Function: Intercepts Claude Code events (e.g.,
PreToolUse,PermissionRequest), evaluates YAML rules, and returns actions (inject context, block, or run scripts).
- Role: Configuration assistant.
- Function: Bridges the gap between the binary and the user. It discovers project skills, parses
CLAUDE.mdfor rules (MUST/MUST NOT), and generates thehooks.yamlfile.
Download the appropriate artifact for your platform (macOS, Linux, Windows) from the releases page.
cargo install --git https://github.com/SpillwaveSolutions/agent_rulezIf you have the Mastering Hooks skill enabled, simply ask Claude:
"Install RuleZ" The skill will detect your OS and handle the installation and verification.
-
Initialize Configuration Scaffold a new configuration with example templates:
rulez init
This creates
.claude/hooks.yaml. -
Install to Claude Code Register Agent RuleZ as the handler in Claude Code's settings:
rulez install --project
Note: Use
--userfor global installation. -
Verify Ensure your configuration is valid:
rulez validate
Configuration is stored in .claude/hooks.yaml. It supports event-based triggers and additive matching.
version: "1"
# Event: Before a tool is executed
PreToolUse:
# Rule: Enforce CDK guidelines
- match:
tools: ["Edit", "Write"]
directories: ["infra/**", "cdk/**"]
action:
inject: "docs/cdk-guidelines.md"
# Rule: Prevent committing "WIP" code
- match:
tools: ["Bash"]
command_match: "git commit.*WIP"
action:
block: true
message: "Commits with 'WIP' are forbidden on this branch."
# Rule: Run custom Python validator
- match:
extensions: [".py"]
action:
run: ".claude/validators/security-check.py"SessionStart/SessionEndPreToolUse/PostToolUsePermissionRequest(Force Claude to explain commands)UserPromptSubmit
inject: Add Markdown context to the conversation.block: Stop the operation immediately.run: Execute a script (Python, Bun, Bash) for custom logic.
The Mastering Hooks skill allows you to configure hooks using natural language.
Triggers:
- "Set up hooks for this project"
- "Enforce the 'no console.log' rule with a hook"
- "Why isn't my hook blocking WIP commits?"
Capabilities:
- Project Analysis: Scans
.claude/skillsandCLAUDE.mdto suggest relevant hooks. - Conflict Detection: Identifies contradicting rules.
- Audit Trail: Keeps a record of installations.
Agent RuleZ acts as a policy engine with advanced governance features.
Rules can be set to different enforcement levels:
enforce(Default): Blocks operations if conditions are met.warn: Injects a warning context but allows the operation.audit: Logs the event without blocking or injecting (useful for silent monitoring).
Every rule can track its origin for auditability:
metadata:
author: "mastering-hooks-skill"
reason: "Enforce infrastructure coding standards"
ticket: "PLAT-3421"
confidence: "high"Logs are stored in ~/.claude/logs/rulez.log in JSON Lines format, supporting "Explainable Policy" auditing.
- Rust (Cargo)
- Python 3 (for testing validators)
- Bun (for testing TypeScript validators).
cargo build --releaseAgent RuleZ includes unit, integration, and end-to-end tests.
cargo testMIT License.