Claude Hook Advisor
A Rust CLI tool that advises Claude Code on better command alternatives based on project preferences. Similar to hashtag-search, this tool allows you to create per-project configurations that automatically suggest preferred commands when Claude Code tries to run specific commands.
Features
- Per-project configuration: Each project can have its own
.claude-hook-advisor.tomlfile - Flexible command mapping: Map any command to any replacement with regex support
- Claude Code integration: Works seamlessly as a PreToolUse hook
- Fast and lightweight: Built in Rust for performance
Installation
From crates.io (Recommended)
Install directly from crates.io using cargo:
This installs the binary to ~/.cargo/bin/claude-hook-advisor (make sure ~/.cargo/bin is in your PATH).
From Source
Configuration
Create a .claude-hook-advisor.toml file in your project root:
[]
= "bun"
= "bun"
= "bunx"
= "wget --verbose"
Example Configurations
Node.js project (prefer bun):
[]
= "bun"
= "bun"
= "bunx"
Python project (prefer uv):
[]
= "uv pip"
= "uv add"
General preferences:
[]
= "wget --verbose"
= "bat"
= "eza"
Claude Code Integration
Option 1: Using the /hooks command
- Run
/hooksin Claude Code - Select
PreToolUse - Add matcher:
Bash - Add hook command:
/path/to/claude-hook-advisor --hook - Save to project settings
Option 2: Manual settings configuration
Add to your .claude/settings.json:
Option 3: Using absolute path after installation
If you've installed via make install:
How It Works
- Command Detection: When Claude Code tries to run a Bash command, the hook receives JSON input
- Configuration Loading: The tool loads
.claude-hook-advisor.tomlfrom the current directory - Pattern Matching: Uses word-boundary regex to match commands (e.g.,
npmmatchesnpm installbut notnpm-check) - Suggestion Generation: If a match is found, returns a blocking response with the suggested replacement
- Claude Integration: Claude receives the suggestion and automatically retries with the correct command
Example Output
When Claude tries to run npm install, the tool outputs:
Claude then sees this feedback and automatically runs bun install instead.
Development
Available Make Targets
Testing
# Run unit tests
# Test with example npm command
# Manual testing
|
Configuration File Lookup
The tool looks for configuration files in this order:
- Custom path specified with
-c/--configflag .claude-hook-advisor.tomlin current directory- If no config found, allows all commands (no mappings)
Use Cases
- Package Manager Consistency: Enforce use of
buninstead ofnpm/yarn - Tool Preferences: Replace
curlwithwget,catwithbat, etc. - Project Standards: Ensure consistent tooling across team members
- Legacy Migration: Gradually move from old tools to new ones
- Security Policies: Block dangerous commands or redirect to safer alternatives
Similar Tools
This tool is inspired by and similar to:
hashtag-search(sibling Rust tool in this project)- Shell aliases (but works at the Claude Code level)
- Git hooks (but for command execution)
Support
If you find this tool useful, consider supporting its development: