# rule2hook

rule2hook translates plain language instructions from memory files into automated Claude Code hook definitions inside hooks.json.

- command · `type=command` · Claude Code, Codex, GitHub Copilot, Gemini CLI · ★ 1357 repo stars
- Author: qdhenry
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/qdhenry/Claude-Command-Suite/tree/HEAD/.claude/commands/dev/rule2hook.md
- Updated: 2026-03-01
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/commands/rule2hook

## What it does

The command parses natural language guidelines and generates matching hook entries. When run without arguments, it scans `./CLAUDE.md`, `./CLAUDE.local.md`, or the global `~/.claude/CLAUDE.md`. You can also pass custom instructions directly as command arguments.

Each rule maps to a lifecycle stage such as `PreToolUse`, `PostToolUse`, `Stop`, or `Notification`. The generator targets specific tools like `Edit`, `Write`, or `Bash` with exact matches or regular expressions. Generated blocks merge into `~/.claude/hooks.json` without wiping previously defined configurations.

Configured commands run with user-level privileges. A failing check can halt execution, so background steps should discard non-zero exit codes using `|| true`.

## Install

### Claude Code (native platform)

**Manually: put the files in place**
- File: `.claude/commands/rule2hook.md` — Call it with /rule2hook. For all projects use ~/.claude/commands/

### Codex

**Manually: put the files in place**
- File: `~/.codex/prompts/rule2hook.md` — Call it with /prompts:rule2hook. Codex marks this format deprecated in favour of skills

### GitHub Copilot

**Manually: put the files in place**
- File: `.github/prompts/rule2hook.prompt.md`

### Gemini CLI

**Manually: put the files in place**
- File: `.gemini/commands/rule2hook.toml` — Gemini stores commands as TOML: the prompt text goes into the prompt field

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/qdhenry/Claude-Command-Suite/tree/HEAD/.claude/commands/dev/rule2hook.md

## When to use it
- convert rules in `CLAUDE.md` into valid `hooks.json` syntax
- trigger formatters automatically following file modifications
- block secret leaks prior to file creation or editing
- run test suites or git checks when Claude finishes a task

## Example prompts
- /rule2hook
- /rule2hook Format python scripts with black after editing
- /rule2hook Scan for hardcoded credentials before saving files

## Similar
- [workflow-automation](https://affpapa.org/en/nevibecode/skills/hubspot-workflow-automation.md) — skill · 1900 installs
- [install-hook](https://affpapa.org/en/nevibecode/commands/install-hook.md) — command · ★ 907 repo stars
- [corezoid-alias-manager](https://affpapa.org/en/nevibecode/skills/corezoid-alias-manager.md) — skill · ★ 74 repo stars
- [automation-sandbox-post-copy-config-generate](https://affpapa.org/en/nevibecode/skills/automation-sandbox-post-copy-config-generate.md) — skill · 2400 installs
- [awesome-tools](https://affpapa.org/en/nevibecode/skills/awesome-tools.md) — skill · 428 installs
- [workflows-as-code](https://affpapa.org/en/nevibecode/skills/workflows-as-code.md) — skill · ★ 81 repo stars

From the same set: [qdhenry/claude-command-suite](https://affpapa.org/en/nevibecode/by/qdhenry/claude-command-suite.md) — 112 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
