mastering-hooks

Master RuleZ, the high-performance AI policy engine for development workflows. Use when asked to "install rulez", "create hooks", "debug hooks", "hook not firing", "configure context injection", "validate hooks.yaml", "PreToolUse", "PostToolUse", "block dangerous commands", "multi-platform hooks", "Gemini CLI hooks", "Copilot hooks", "OpenCode hooks", "dual-fire events", or "cross-platform rules". Covers installation, rule creation, multi-platform adapters, troubleshooting, and optimization.

16 stars

Best use case

mastering-hooks is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Master RuleZ, the high-performance AI policy engine for development workflows. Use when asked to "install rulez", "create hooks", "debug hooks", "hook not firing", "configure context injection", "validate hooks.yaml", "PreToolUse", "PostToolUse", "block dangerous commands", "multi-platform hooks", "Gemini CLI hooks", "Copilot hooks", "OpenCode hooks", "dual-fire events", or "cross-platform rules". Covers installation, rule creation, multi-platform adapters, troubleshooting, and optimization.

Teams using mastering-hooks should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/mastering-hooks/SKILL.md --create-dirs "https://raw.githubusercontent.com/diegosouzapw/awesome-omni-skill/main/skills/tools/mastering-hooks/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/mastering-hooks/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How mastering-hooks Compares

Feature / Agentmastering-hooksStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Master RuleZ, the high-performance AI policy engine for development workflows. Use when asked to "install rulez", "create hooks", "debug hooks", "hook not firing", "configure context injection", "validate hooks.yaml", "PreToolUse", "PostToolUse", "block dangerous commands", "multi-platform hooks", "Gemini CLI hooks", "Copilot hooks", "OpenCode hooks", "dual-fire events", or "cross-platform rules". Covers installation, rule creation, multi-platform adapters, troubleshooting, and optimization.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# mastering-hooks

## Contents

- [Overview](#overview)
- [Decision Tree](#decision-tree)
- [Capabilities](#capabilities)
- [When NOT to Use](#when-not-to-use)
- [References](#references)

## Overview

RuleZ is a **high-performance AI policy engine** that intercepts AI coding assistant events and executes configured actions. It works across multiple platforms through adapter-based event translation.

```
User Prompt --> AI Assistant --> RuleZ Binary --> [Match Rules] --> Execute Actions
                    |                                 |
                    v                                 v
              PreToolUse                       inject/run/block
              PostToolUse                      context/validation
              BeforeAgent
              PermissionRequest
```

**Supported platforms**:
- **Claude Code** (native) - Full event support
- **Gemini CLI** - Via adapter with dual-fire events
- **GitHub Copilot** - Via adapter
- **OpenCode** - Via adapter with dual-fire events

**System components**:
- **RuleZ Binary** (Rust): Fast, deterministic hook execution at runtime
- **hooks.yaml**: Declarative configuration defining rules, matchers, and actions
- **Platform Adapters**: Translate platform-specific events to unified RuleZ event types
- **This Skill**: Intelligent assistant for setup, debugging, and optimization

## Decision Tree

```
What do you need?
|
+-- New to RuleZ? --> [1. Install & Initialize]
|
+-- Have hooks.yaml but hooks not working? --> [4. Troubleshoot]
|
+-- Need to add new behavior? --> [2. Create Rules]
|
+-- Want to understand existing config? --> [3. Explain Configuration]
|
+-- Performance or complexity issues? --> [5. Optimize]
|
+-- Setting up for Gemini/Copilot/OpenCode? --> [6. Multi-Platform Setup]
```

## Capabilities

### 1. Install & Initialize RuleZ

**Use when**: Setting up RuleZ for the first time in a project or user-wide.

**Checklist**:
1. Verify RuleZ binary is installed: `rulez --version --json`
2. Initialize configuration: `rulez init` (creates `.claude/hooks.yaml`)
3. Register with Claude Code: `rulez install --project` or `rulez install --user`
4. Validate configuration: `rulez validate`
5. Verify installation: Check `.claude/settings.json` for hook entries

**Expected output** from `rulez --version --json`:
```json
{"version": "1.8.0", "api_version": "1.8.0", "git_sha": "abc1234"}
```

**Reference**: [cli-commands.md](references/cli-commands.md)

---

### 2. Create Hook Rules

**Use when**: Adding new behaviors like context injection, command validation, or workflow automation.

**Checklist**:
1. Identify the event type (PreToolUse, PostToolUse, BeforeAgent, etc.)
2. Define matchers (tools, extensions, directories, patterns)
3. Choose action type (inject, run, block, require_fields)
4. Write the rule in hooks.yaml
5. Validate: `rulez validate`
6. Test with: `rulez debug <event> --tool <tool_name>`

**Rule anatomy**:
```yaml
hooks:
  - name: rule-name           # kebab-case identifier
    event: PreToolUse         # When to trigger
    match:
      tools: [Write, Edit]    # What to match
      extensions: [.py]       # Optional: file filters
    action:
      type: inject            # What to do
      source: file            # file | inline | command
      path: .claude/context/python-standards.md
```

**Reference**: [hooks-yaml-schema.md](references/hooks-yaml-schema.md) | [rule-patterns.md](references/rule-patterns.md)

---

### 3. Explain Configuration

**Use when**: Understanding what existing hooks do, why they exist, or how they interact.

**Checklist**:
1. Run `rulez explain rule <rule-name>` for specific rule analysis
2. Run `rulez explain config` for full configuration overview
3. Check rule precedence (first match wins within same event)
4. Identify potential conflicts or overlaps

**Example output** from `rulez explain rule python-standards`:
```
Rule: python-standards
Event: PreToolUse
Triggers when: Write or Edit tool used on .py files
Action: Injects content from .claude/context/python-standards.md
```

**Reference**: [cli-commands.md](references/cli-commands.md)

---

### 4. Troubleshoot Hook Issues

**Use when**: Hooks not firing, unexpected behavior, or error messages.

**Diagnostic checklist**:
1. **Validate config**: `rulez validate` - catches YAML/schema errors
2. **Check registration**: `cat .claude/settings.json | grep hooks`
3. **Enable debug logging**: `rulez debug PreToolUse --tool Write --verbose`
4. **Check logs**: `rulez logs --tail 20`
5. **Verify file paths**: Ensure all `path:` references exist

**Common issues**:

| Symptom | Likely Cause | Fix |
|---------|--------------|-----|
| Hook never fires | Event/matcher mismatch | Use `rulez debug` to trace matching |
| "file not found" | Invalid path in action | Check relative paths from project root |
| Context not injected | Script returns invalid JSON | Validate script output format |
| Permission denied | Script not executable | `chmod +x script.sh` |
| Event not firing on Gemini | Wrong event name | Check [platform-adapters.md](references/platform-adapters.md) for mappings |

**Reference**: [troubleshooting-guide.md](references/troubleshooting-guide.md)

---

### 5. Optimize Configuration

**Use when**: Too many rules, slow execution, or complex maintenance.

**Optimization checklist**:
1. Consolidate overlapping rules with broader matchers
2. Use `enabled_when` for conditional rules instead of duplicates
3. Move shared context to reusable markdown files
4. Order rules by frequency (most common first)
5. Use `block` early to short-circuit unnecessary processing

**Reference**: [rule-patterns.md](references/rule-patterns.md)

---

### 6. Multi-Platform Setup

**Use when**: Configuring RuleZ to work with Gemini CLI, GitHub Copilot, or OpenCode in addition to Claude Code.

**Key concepts**:
- RuleZ uses **platform adapters** to translate each platform's native events into unified RuleZ event types
- Write rules using RuleZ event types (e.g., `PreToolUse`) — adapters handle translation automatically
- Some platforms fire **dual events** (e.g., Gemini's `BeforeAgent` fires both `BeforeAgent` and `UserPromptSubmit`)

**Checklist**:
1. Install RuleZ: `rulez install --project`
2. Write rules using standard RuleZ event types
3. Test with `rulez debug <event>` to verify matching
4. Review [platform-adapters.md](references/platform-adapters.md) for platform-specific event mappings

**Reference**: [platform-adapters.md](references/platform-adapters.md)

---

## When NOT to Use This Skill

- **Simple Claude Code configuration**: Use `settings.json` directly for basic permissions
- **One-time context injection**: Just paste into your prompt
- **Dynamic runtime decisions**: RuleZ is deterministic; use MCP servers for complex logic

---

## References

| Document | Purpose |
|----------|---------|
| [quick-reference.md](references/quick-reference.md) | Events, matchers, actions, file locations |
| [hooks-yaml-schema.md](references/hooks-yaml-schema.md) | Complete YAML configuration reference |
| [cli-commands.md](references/cli-commands.md) | All CLI commands with examples |
| [rule-patterns.md](references/rule-patterns.md) | Common patterns and recipes |
| [troubleshooting-guide.md](references/troubleshooting-guide.md) | Diagnostic procedures |
| [platform-adapters.md](references/platform-adapters.md) | Multi-platform event mappings and dual-fire |

---

## Example: Complete hooks.yaml

```yaml
# .claude/hooks.yaml
version: "1"

hooks:
  # Inject Python standards before writing Python files
  - name: python-standards
    event: PreToolUse
    match:
      tools: [Write, Edit]
      extensions: [.py]
    action:
      type: inject
      source: file
      path: .claude/context/python-standards.md

  # Block dangerous git commands
  - name: block-force-push
    event: PreToolUse
    match:
      tools: [Bash]
      command_match: "git push.*--force"
    action:
      type: block
      reason: "Force push requires explicit approval."

  # Run security check before committing
  - name: pre-commit-security
    event: PreToolUse
    match:
      tools: [Bash]
      command_match: "git commit"
    action:
      type: run
      command: .claude/validators/check-secrets.sh
      timeout: 30

  # Track agent activity (works on Claude Code and Gemini)
  - name: log-agent-start
    event: BeforeAgent
    match: {}
    action:
      type: inject
      source: inline
      content: |
        **Agent Policy**: Follow project conventions in CLAUDE.md.
```

Related Skills

claude-hooks-reference-2026

16
from diegosouzapw/awesome-omni-skill

Complete reference for Claude Code hooks system (January 2026). Use when creating hooks, understanding hook events, matchers, exit codes, JSON output control, environment variables, plugin hooks, or implementing hook scripts.

asyncredux-flutter-hooks

16
from diegosouzapw/awesome-omni-skill

Integrate AsyncRedux with the flutter_hooks package. Covers adding flutter_hooks_async_redux, using the useSelector hook, and combining hooks with AsyncRedux state management.

ahooks

16
from diegosouzapw/awesome-omni-skill

Comprehensive ahooks React hooks library specialist. Expert in all 76+ ahooks hooks including state management, effects, data fetching, performance optimization, DOM utilities, and advanced patterns. Use when working with ahooks library, need React hooks utilities or want to learn best practices.

mastering-postgresql

16
from diegosouzapw/awesome-omni-skill

PostgreSQL development for Python with full-text search (tsvector, tsquery, BM25 via pg_search), vector similarity (pgvector with HNSW/IVFFlat), JSONB and array indexing, and production deployment. Use when creating search features, storing AI embeddings, querying vector similarity, optimizing PostgreSQL indexes, or deploying to AWS RDS/Aurora, GCP Cloud SQL/AlloyDB, or Azure. Covers psycopg2, psycopg3, asyncpg, SQLAlchemy integration, Docker development setup, and index selection strategies. Triggers: "PostgreSQL search", "pgvector", "BM25 postgres", "JSONB index", "psycopg", "asyncpg", "PostgreSQL Docker", "AlloyDB vector". Does NOT cover: DBA administration (backup, replication, users), MySQL/MongoDB/Redis, schema design theory, stored procedures.

mastering-aws-cdk

16
from diegosouzapw/awesome-omni-skill

Guides AWS CDK v2 infrastructure-as-code development in TypeScript with patterns, troubleshooting, and deployment workflows. Use when creating or refactoring CDK stacks, debugging CloudFormation or CDK deploy errors, setting up CI/CD with GitHub Actions OIDC, or integrating AWS services (Lambda, API Gateway, ECS/Fargate, S3, DynamoDB, EventBridge, Aurora, MSK).

bgo

16
from diegosouzapw/awesome-omni-skill

Automated Blender build-go workflow. Automatically builds, removes old version, installs, enables, and launches Blender with your extension/add-on. Use when you want to quickly test changes, execute complete build-to-launch cycle, or run custom packaging scripts with automatic Blender launch.

Coding & Development

maintenance

16
from diegosouzapw/awesome-omni-skill

Cleans up and organizes project files. Use when user mentions '整理', 'cleanup', 'アーカイブ', 'archive', '肥大化', 'Plans.md', 'session-log', or asks to clean up old tasks, archive completed items, or organize files. Do NOT load for: 実装作業, レビュー, 新機能開発, デプロイ.

hello-skill

16
from diegosouzapw/awesome-omni-skill

每次对话开始时,声明"[Skills✏️已加载]"

zylvie-automation

16
from diegosouzapw/awesome-omni-skill

Automate Zylvie tasks via Rube MCP (Composio). Always search tools first for current schemas.

zoominfo-automation

16
from diegosouzapw/awesome-omni-skill

Automate Zoominfo tasks via Rube MCP (Composio). Always search tools first for current schemas.

zoho-invoice-automation

16
from diegosouzapw/awesome-omni-skill

Automate Zoho Invoice tasks via Rube MCP (Composio): invoices, estimates, expenses, clients, and payment tracking. Always search tools first for current schemas.

zoho-inventory-automation

16
from diegosouzapw/awesome-omni-skill

Automate Zoho Inventory tasks via Rube MCP (Composio): items, orders, warehouses, shipments, and stock management. Always search tools first for current schemas.