Claude Hook Advisor
A Rust CLI tool that integrates with Claude Code using hooks to provide intelligent command suggestions, semantic directory aliasing, command history tracking, and security pattern detection.
Features
- 🎯 Command Intelligence - Automatically map commands to your preferred alternatives (npm → bun, curl → wget)
- 📁 Directory Aliasing - Use natural language like "docs" or "project_docs" instead of typing full paths
- 📊 Command History - Track all commands Claude runs in a SQLite database with session tracking
- 🔒 Security Patterns - 27 built-in patterns detect dangerous code across 10+ languages
- ⚡ Fast & Lightweight - Rust-based with ~1-5ms hook response time
Quick Example
You: "What files are in my docs?"
Claude: "I'll check your docs directory at /Users/you/Documents/Documentation"
Claude tries: npm install
Tool suggests: bun install
Claude runs: bun install automatically
Claude tries to write: eval(userInput)
Tool warns: Security risk detected
Claude: Finds a safer alternative
Installation
Option 1: Plugin Marketplace (Recommended)
/plugin marketplace add sirmews/claude-hook-advisor
/plugin install claude-hook-advisor@sirmews
Includes automatic hook setup and slash commands (/history, /history-failures, /history-search).
Option 2: From crates.io
cargo install claude-hook-advisor
claude-hook-advisor --install-hooks
Option 3: From Source
git clone https://github.com/sirmews/claude-hook-advisor.git
cd claude-hook-advisor
make install
Quick Start
- Install via plugin marketplace (recommended) or cargo
- Create
.claude-hook-advisor.toml in your project root:
# Command mappings - map any command to your preferred tool
[commands]
npm = "bun"
yarn = "bun"
curl = "wget --verbose"
# Directory aliases - use natural language in conversations
[semantic_directories]
"project docs" = "~/Documents/my-project/docs"
"test data" = "~/Documents/test-data"
That's it! Start a Claude Code conversation and the hooks work automatically. Security patterns are enabled by default with no configuration needed.
📝 Optional: Enable Command History Tracking
Add to your .claude-hook-advisor.toml:
[command_history]
enabled = true
log_file = "~/.claude-hook-advisor/bash-history.db"
View history:
claude-hook-advisor --history # Recent commands
claude-hook-advisor --history --failures # Only failed commands
claude-hook-advisor --history --pattern git # Filter by pattern
🔒 Optional: Disable Noisy Security Patterns
Security patterns are enabled by default. To disable specific patterns:
[security_pattern_overrides]
swift_force_unwrap = false # Common in Swift code
eval_injection = false # If working on a REPL
rust_unsafe_block = false # For systems programming
Configuration
Run claude-hook-advisor --install-hooks to automatically configure hooks, or manually add to .claude/settings.json:
{
"hooks": {
"PreToolUse": { "Bash": "claude-hook-advisor --hook" },
"UserPromptSubmit": { ".*": "claude-hook-advisor --hook" },
"PostToolUse": { "Bash": "claude-hook-advisor --hook" }
}
}
📚 Documentation
How It Works
Triple-Hook Architecture
Three hooks work together to provide comprehensive functionality:
1. PreToolUse Hook - Command Intelligence 🚦
The Flow:
- Command Detection: When Claude Code tries to run a Bash command, the hook receives JSON input
- Configuration Loading: The tool loads
.claude-hook-advisor.toml from the current directory
- Pattern Matching: Matches only the primary command at the start of the line
- 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
Smart Matching:
- Start-of-line matching ensures only primary commands are replaced
npm install → bun install ✅
npx npm stays unchanged (npm is not the primary command) ✅
npm-check stays unchanged (different command) ✅
- Preserves command arguments:
npm install --save → bun install --save ✅
2. UserPromptSubmit Hook - Directory Aliasing 📁
The Flow:
- Text Analysis: Scans user prompts for semantic directory references (e.g., "docs", "project_docs")
- Pattern Recognition: Uses regex to detect directory aliases in natural language
- Path Expansion: Expands tilde (~) to user home directory
- Path Resolution: Converts semantic references to canonical filesystem paths
- Security Validation: Performs path canonicalization to prevent traversal attacks