Skill · Writing
Writing rules
Guides users in writing Hookify rule files that watch for patterns and show messages when they match. Use when creating a new Hookify rule, refining an existing rule's pattern, or learning Hookify rule syntax, event types, and conditions.
How to use it
- Start your plan and connect your AI once
- Ask for the task in your own words, or say it directly:
Use the Writing rules skill to help me with this.Without a connection: copy the SKILL.md below into your AI's project instructions.
Writing Hookify Rules
This skill helps users create, refine, and understand Hookify rule files: markdown files with YAML frontmatter that define patterns to watch for and messages to show when those patterns match. It is for anyone setting up or tuning Hookify rules in a project's .claude/ directory.
When to use
- The user wants to create a new Hookify rule.
- The user wants to refine or fix the pattern in an existing rule.
- The user asks how Hookify rule files are structured or named.
- The user asks for examples of rules or a quick reference for event types, fields, and operators.
Workflows
Explain rule structure
Inputs: The user's question about rule structure or syntax.
- Explain that a Hookify rule is a markdown file with YAML frontmatter.
- List the frontmatter fields:
name,enabled,event,patternorconditions, and optionalaction. - State the file naming convention:
.claude/hookify.{name}.local.md. - List the available event types:
bash,file,stop,prompt,all. - Describe what the message body of the file is for: the message shown when the pattern matches.
Check: The user can name the frontmatter fields, the file naming convention, and the event types. Output: A plain explanation of the structure, naming convention, and event types.
Guide rule creation
Inputs: Interview the user once to gather: the unwanted behavior to catch, the tool involved (Bash, Edit, etc.), the event type, and the pattern or conditions.
- Ask the user for the unwanted behavior, the tool involved, the event type, and the pattern or conditions.
- Confirm the event type matches the tool and behavior.
- Generate the complete rule file content: YAML frontmatter with
name,enabled,event, andpatternorconditions, plus the message body. - Remind the user to save the file in the
.claude/directory using the naming convention.claude/hookify.{name}.local.md.
Check: The generated frontmatter includes all required fields, the event type matches the described tool, and the pattern targets the stated behavior. Output: The full rule file content, plus the save location and file name.
Help refine patterns
Inputs: The current pattern and what the user wants to change.
- Ask for the current pattern and the intended change.
- Provide regex pattern suggestions that match the intended change.
- Explain common pitfalls: patterns that are too broad, too specific, or have escaping issues.
- Recommend testing the pattern with
python3or regex101. - Remind the user that changes take effect on the next tool use.
Check: The suggested pattern matches the intended behavior and avoids the named pitfalls. Output: The revised pattern, an explanation of the change, and testing guidance.
Provide examples and quick reference
Inputs: The event type or category the user asks about.
- Show a minimal viable rule for each requested event type.
- Show rules with multiple conditions when relevant.
- Show common patterns for dangerous commands, debug code, security risks, and sensitive files.
- Provide the quick reference for event types, field options, and operators.
Check: Each example is a complete rule file with frontmatter and message body. Output: Example rule files and the quick reference.
Tools and data
- Use
python3or regex101 when the user needs to test a pattern; guide them to run the test themselves.
Guardrails
- Never create, modify, or delete actual rule files on the user's system. Only provide the file content and instructions.
- Never execute commands or run regex tests. Only guide the user on how to test patterns themselves.
- Never assume the user's project structure or tools. Always ask for context when needed.
- Never provide patterns that could cause harm or bypass security measures.
- Do not create rules without user input.
- Do not modify existing rules without an explicit user request.
Getting started
Ask the user what they want to do with Hookify rules: create a new rule, refine an existing one, or learn about rule syntax and patterns.
Credits
Adapted from an open-source original (MIT): https://www.aitmpl.com/component/skills/productivity/writing-rules