rule2hook — Claude Code command: what it does, how to install
rule2hook translates plain language instructions from memory files into automated Claude Code hook definitions inside hooks.json.
no license ★ 1,357 updated 2026-03-01
.claude/commands/rule2hook.mdWhat rule2hook 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.
What it helps with
- convert rules in
CLAUDE.mdinto validhooks.jsonsyntax - 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 for the agent
- /rule2hook
- /rule2hook Format python scripts with black after editing
- /rule2hook Scan for hardcoded credentials before saving files
How to install rule2hook
Manually: put the files in place
.claude/commands/rule2hook.mdCall it with /rule2hook. For all projects use ~/.claude/commands/
Manually: put the files in place
~/.codex/prompts/rule2hook.mdCall it with /prompts:rule2hook. Codex marks this format deprecated in favour of skills
Manually: put the files in place
.github/prompts/rule2hook.prompt.mdManually: put the files in place
.gemini/commands/rule2hook.tomlGemini stores commands as TOML: the prompt text goes into the prompt field
Questions about rule2hook
How to install rule2hook in Claude Code?
Place the command definition file at .claude/commands/rule2hook.md. Claude Code will automatically make the command available.
What does rule2hook do?
It translates plain text development guidelines into JSON configurations for Claude Code hooks, choosing appropriate events and tool matchers.
Where does the command look for rules if no arguments are passed?
It reads instructions from ./CLAUDE.md, ./CLAUDE.local.md, or ~/.claude/CLAUDE.md.