Skip to main content
command CX Codex

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

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/commands/rule2hook.md
Open on GitHub

What 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.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 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.md

Call it with /rule2hook. For all projects use ~/.claude/commands/

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.

Similar slash commands

All slash commands for Agent setup: memory, context, orchestration →

From the same set112

The whole set →
svelte-storybook svelte-storybook documents SvelteKit components in Storybook and writes the story files with Svelte CSF. Handy when a single component needs checking away from the running app. CX Codex ★ 1,357repo stars data-scientist data-scientist analyzes metrics, constructs advanced SQL workflows, and optimizes BigQuery queries to control data scanning costs. CX Codex ★ 1,357repo stars ux-designer The ux-designer subagent shapes interfaces around user tasks, accessibility, and ease of use. It fits research, interaction design, testing, and handoff work. CX Codex ★ 1,357repo stars product-manager A product-manager subagent that turns one goal into epics, task specs with acceptance criteria, and an ordered queue other agents can pick up. CX Codex ★ 1,357repo stars handoff This command saves the work so far as a Markdown handoff for a later session. Run it before changing tasks or when the context window is nearly full. CX Codex +1 ★ 1,357repo stars mobile-developer mobile-developer — a Claude subagent for React Native and Flutter apps. It designs the architecture, hooks up native modules and handles offline sync, push and store releases. CX Codex ★ 1,357repo stars security-auditor security-auditor is a Claude Code subagent that finds application vulnerabilities and reviews security controls. It can assess source code, authentication flows, or a running application. CX Codex ★ 1,357repo stars migration-assistant migration-assistant — a Claude Code command that migrates issues, PRs and projects between GitHub and Linear. Works via GitHub CLI and Linear MCP server, preserves relationships and creates rollback points. CX Codex +1 ★ 1,357repo stars

Project sponsors

Companies that keep this analytics open