hookify

Easily create custom hooks to prevent unwanted behaviors by analyzing conversation patterns or from explicit instructions. Define rules via simple markdown files.

View on GitHub
Author Anthropic
Namespace @anthropics/claude-plugins-official
Category productivity
Version 1.0.0
Stars 5,333
Downloads 5
self.md verified
Table of content

Easily create custom hooks to prevent unwanted behaviors by analyzing conversation patterns or from explicit instructions. Define rules via simple markdown files.

Installation

npx claude-plugins install @anthropics/claude-plugins-official/hookify

Contents

Folders: agents, commands, core, examples, hooks, matchers, skills, utils

Files: README.md

Documentation

Easily create custom hooks to prevent unwanted behaviors by analyzing conversation patterns or from explicit instructions.

Overview

The hookify plugin makes it simple to create hooks without editing complex hooks.json files. Instead, you create lightweight markdown configuration files that define patterns to watch for and messages to show when those patterns match.

Key features:

Quick Start

1. Create Your First Rule

/hookify Warn me when I use rm -rf commands

This analyzes your request and creates .claude/hookify.warn-rm.local.md.

2. Test It Immediately

No restart needed! Rules take effect on the very next tool use.

Ask Claude to run a command that should trigger the rule:

Run rm -rf /tmp/test

You should see the warning message immediately!

Usage

Main Command: /hookify

With arguments:

/hookify Don't use console.log in TypeScript files

Creates a rule from your explicit instructions.

Without arguments:

/hookify

Analyzes recent conversation to find behaviors you’ve corrected or been frustrated by.

Helper Commands

List all rules:

/hookify:list

Configure rules interactively:

/hookify:configure

Enable/disable existing rules through an interactive interface.

Get help:

/hookify:help

Rule Configuration Format

Simple Rule (Single Pattern)

.claude/hookify.dangerous-rm.local.md:

---
name: block-dangerous-rm
enabled: true
event: bash
pattern: rm\s+-rf
action: block
---

โš ๏ธ **Dangerous rm command detected!**

This command could delete important files. Please:
- Verify the path is correct
- Consider using a safer approach
- Make sure you have backups

Action field:

Advanced Rule (Multiple Conditions)

.claude/hookify.sensitive-files.local.md:

---
name: warn-sensitive-files
enabled: true
event: file
action: warn
conditions:
  - field: file_path
    operator: regex_match
    pattern: \.env$|credentials|secrets
  - field: new_text
    operator: contains
    pattern: KEY
---

๐Ÿ” **Sensitive file edit detected!**

Ensure credentials are not hardcoded and file is in .gitignore.

All conditions must match for the rule to trigger.

Event Types

Pattern Syntax

Use Python regex syntax:

PatternMatchesExample
rm\s+-rfrm -rfrm -rf /tmp
console\.log\(console.log(console.log(“test”)
(eval|exec)\(eval( or exec(eval(“code”)
\.env$files ending in .env.env, .env.local
chmod\s+777chmod 777chmod 777 file.txt

Tips:

Examples

Example 1: Block Dangerous Commands

---
name: block-destructive-ops
enabled: true
event: bash
pattern: rm\s+-rf|dd\s+if=|mkfs|format
action: block
---

๐Ÿ›‘ **Destructive operation detected!**

This command can cause data loss. Operation blocked for safety.
Please verify the exact path and use a safer approach.

This rule blocks the operation - Claude will not be allowed to execute these commands.

Example 2: Warn About Debug Code

---
name: warn-debug-code
enabled: true
event: file
pattern: console\.log\(|debugger;|print\(
action: warn
---

๐Ÿ› **Debug code detected**

Remember to remove debugging statements before committing.

This rule warns but allows - Claude sees the message but can still proceed.

Example 3: Require Tests Before Stopping

---
name: require-tests-run
enabled: false
event: stop
action: block
conditions:
  - field: transcript
    operator: not_contains
    pattern: npm test|pytest|cargo test
---

**Tests not detected in transcript!**

Before stopping, please run tests to verify your changes work correctly.

This blocks Claude from stopping if no test commands appear in the session transcript. Enable only when you want strict enforcement.

Advanced Usage

Multiple Conditions

Check multiple fields simultaneously:

---
name: api-key-in-typescript
enabled: true
event: file
conditions:
  - field: file_path
    o

...(truncated)

## Included Skills

This plugin includes 1 skill definition:

### writing-rules

> This skill should be used when the user asks to "create a hookify rule", "write a hook rule", "configure hookify", "add a hookify rule", or needs guidance on hookify rule syntax and patterns.

<details>
<summary>View skill definition</summary>

# Writing Hookify Rules

## Overview

Hookify rules are markdown files with YAML frontmatter that define patterns to watch for and messages to show when those patterns match. Rules are stored in `.claude/hookify.{rule-name}.local.md` files.

## Rule File Format

### Basic Structure

```markdown
---
name: rule-identifier
enabled: true
event: bash|file|stop|prompt|all
pattern: regex-pattern-here
---

Message to show Claude when this rule triggers.
Can include markdown formatting, warnings, suggestions, etc.

Frontmatter Fields

name (required): Unique identifier for the rule

enabled (required): Boolean to activate/deactivate

event (required): Which hook event to trigger on

action (optional): What to do when rule matches

pattern (simple format): Regex pattern to match

…(truncated)

Source

View on GitHub

Tags: productivity