claude-hook-advisor 0.2.1

A Claude Code hook that provides intelligent command suggestions and semantic directory aliasing for enhanced AI-assisted development workflows
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
---
title: "Configuration Guide"
description: "Complete reference for configuring Claude Hook Advisor"
tags: ["configuration", "toml", "commands", "mapping", "setup"]
---

# Configuration Guide

Claude Hook Advisor uses TOML configuration files to define command mappings and semantic directory aliases. This guide covers all configuration options and patterns for both command intelligence and directory aliasing features.

## 📁 Configuration File Location

The tool searches for configuration files in this order:

1. **Custom path** specified with `-c/--config` flag
2. **`.claude-hook-advisor.toml`** in current directory
3. **No configuration** (allows all commands)

```bash
# Use custom config file
claude-hook-advisor --config /path/to/config.toml --hook

# Use default location
claude-hook-advisor --hook  # Looks for .claude-hook-advisor.toml
```

## 🔧 Complete Configuration Format

### Full Configuration Structure
```toml
# Command mappings for intelligent replacement
[commands]
npm = "bun"
yarn = "bun"
curl = "wget --verbose"

# Semantic directory aliases for natural language references
[semantic_directories]
"central docs" = "~/Documents/Documentation"
"project docs" = "~/Documents/Documentation/my-project"
"claude docs" = "~/Documents/Documentation/claude"
```

### Simple Command Mapping
```toml
[commands]
# Replace 'npm' with 'bun'
npm = "bun"

# Replace 'yarn' with 'bun'
yarn = "bun"

# Replace 'curl' with 'wget --verbose'
curl = "wget --verbose"
```

### Exact Command Matching
```toml
[commands]
# Only replace exact 'pip install' command
"pip install" = "uv add"

# Only replace exact 'npm start' command
"npm start" = "bun dev"

# Replace 'git commit' with signed commits
"git commit" = "git commit -S"
```

## 🎯 Pattern Matching Rules

### Word Boundary Matching
Claude Hook Advisor uses word-boundary regex matching:

```toml
[commands]
npm = "bun"
```

**Matches:**
- `npm install``bun install`
- `npm run build``bun run build`
- `npm --version``bun --version`

**Does NOT match:**
- `npm-check` (no word boundary)
- `my-npm-tool` (npm is not at word boundary)

### Exact String Matching
For precise control, use quoted strings:

```toml
[commands]
"npm install" = "bun add"
"npm uninstall" = "bun remove"
"npm run" = "bun run"
```

**Matches:**
- `npm install package``bun add package`
- `npm install``bun add`

**Does NOT match:**
- `npm install-something` (not exact match)
- `npm` alone (doesn't include "install")

## 📁 Directory Aliasing Configuration

### Basic Directory Aliases
```toml
[semantic_directories]
# Simple directory aliases
"central docs" = "~/Documents/Documentation"
notes = "~/Documents/Notes"
projects = "~/Projects"
```

### Static Path Mapping
```toml
[semantic_directories]
# Direct alias-to-path mapping (no variable substitution)
project_docs = "~/Documents/Documentation/my-awesome-project"
project_notes = "~/Notes/my-awesome-project"
user_config = "~/.config/my-project"
```

### Natural Language Aliases (Space-Separated)
```toml
[semantic_directories]
# Use quoted keys for multi-word, natural language aliases
"project docs" = "~/Documents/Documentation/my-awesome-project"
"project notes" = "~/Notes/my-awesome-project"
"user config" = "~/.config/my-project"
"claude docs" = "~/Documents/Documentation/claude"
```

**Advantage:** Space-separated aliases feel more natural in conversation:
- *"Check the project docs directory"* → matches `"project docs"`
- *"Look in user config folder"* → matches `"user config"`

### Alias Precedence and Conflicts
```toml
[semantic_directories]
# ⚠️ Problematic: overlapping aliases
docs = "~/Documents/Documentation"           # Shorter alias
"project docs" = "~/Documents/Documentation/project"  # Contains "docs"

# ✅ Better: avoid overlapping aliases
"central docs" = "~/Documents/Documentation"
"project docs" = "~/Documents/Documentation/project"
```

**Important:** When multiple aliases could match the same text, shorter/simpler aliases take precedence. Avoid configuring both `docs` and `"project docs"` if you want `"project docs"` to match phrases like "check project docs directory".

**Note:** In v0.2.0, directory paths are static. No variable substitution is supported.

### Common Directory Patterns
```toml
[semantic_directories]
# Documentation locations
"central docs" = "~/Documents/Documentation"
"project docs" = "~/Documents/Documentation/my-project"
"claude docs" = "~/Documents/Documentation/claude"

# Development directories
src = "./src"
lib = "./lib"
tests = "./tests"
build = "./build"
dist = "./dist"

# Configuration directories
config = "~/.config"
local_config = "./.config"
project_config = "~/.config/my-project"

# Temporary and cache directories
tmp = "/tmp"
cache = "~/.cache"
project_cache = "~/.cache/my-project"
```

### Directory Configuration via TOML File Only
```bash
# Edit configuration file directly
echo '[semantic_directories]
"central docs" = "~/Documents/Documentation"
"project docs" = "~/Documents/Documentation/my-project"' > .claude-hook-advisor.toml

# Test directory resolution via hook
echo '{"session_id":"test","hook_event_name":"UserPromptSubmit","prompt":"check docs"}' | claude-hook-advisor --hook
```

**Note:** No CLI commands for directory alias management in v0.2.0. Use TOML configuration only.

### Path Expansion (v0.2.0)
The tool supports basic path expansion:

1. **Tilde Expansion**: 
   - `~` is automatically expanded to user home directory
   - Example: `~/Documents` becomes `/Users/username/Documents`
   
2. **Static Paths Only**:
   - No variable substitution or dynamic path generation
   - Each alias maps directly to a fixed path

3. **Path Canonicalization**:
   - All paths are resolved to canonical absolute paths
   - Provides security against directory traversal attacks

## 📚 Configuration Categories

### Package Managers

#### Node.js Ecosystem
```toml
[commands]
# Bun as primary package manager
npm = "bun"
yarn = "bun"
pnpm = "bun"
npx = "bunx"

# Specific command mappings
"npm install" = "bun add"
"npm uninstall" = "bun remove"
"npm run" = "bun run"
"npm start" = "bun dev"
"npm test" = "bun test"
```

#### Python Ecosystem
```toml
[commands]
# UV for faster Python package management
pip = "uv pip"
"pip install" = "uv add"
"pip uninstall" = "uv remove"
"pip freeze" = "uv pip freeze"
python = "uv run python"
pytest = "uv run pytest"
```

#### Other Languages
```toml
[commands]
# Ruby
gem = "bundle exec gem"
"gem install" = "bundle add"

# Go
"go get" = "go mod tidy && go get"
"go run" = "go run -race"

# Rust
"cargo install" = "cargo binstall"
```

### Modern CLI Tools

#### File Operations
```toml
[commands]
# Better file listing and viewing
ls = "eza"
cat = "bat"
less = "bat --paging=always"

# Safer file operations
rm = "trash"
cp = "cp -i"
mv = "mv -i"

# Better file search
find = "fd"
locate = "fd"
```

#### Text Processing
```toml
[commands]
# Modern text tools
grep = "rg"
awk = "rg --replace"
sed = "sd"

# Better diff tools
diff = "delta"
```

#### System Monitoring
```toml
[commands]
# Process and system monitoring
top = "htop"
ps = "procs"
du = "dust"
df = "duf"

# Network tools
ping = "gping"
netstat = "ss"
```

### Development Tools

#### Version Control
```toml
[commands]
# Git best practices
"git push" = "git push --set-upstream origin HEAD"
"git commit" = "git commit -S"
"git pull" = "git pull --rebase"
"git merge" = "git merge --no-ff"

# Git shortcuts
"git status" = "git status --short --branch"
"git log" = "git log --oneline --graph"
```

#### Build Tools
```toml
[commands]
# Modern build systems
make = "just"
cmake = "meson"
autotools = "meson"

# Container tools
docker = "podman"
"docker-compose" = "podman-compose"
```

#### Editors and IDEs
```toml
[commands]
# Modern editors
vim = "nvim"
nano = "micro"
emacs = "doom emacs"
```

### Security and Safety

#### Dangerous Command Prevention
```toml
[commands]
# Prevent destructive operations
"rm -rf" = "echo 'Use trash command instead of rm -rf for safety'"
"sudo rm" = "echo 'Consider using trash or be very careful with sudo rm'"
"chmod 777" = "echo 'chmod 777 is dangerous, consider more restrictive permissions'"
"chown -R" = "echo 'Recursive chown can be dangerous, consider specific paths'"

# Encourage secure practices
ssh = "ssh -o VerifyHostKeyDNS=yes"
scp = "rsync -avz --progress"
```

#### Network Security
```toml
[commands]
# Secure HTTP tools
curl = "curl --fail --location --show-error"
wget = "wget --secure-protocol=TLSv1_2"

# VPN and tunneling
ssh = "ssh -C -o Compression=yes"
```

## 🔄 Advanced Configuration Patterns

### Environment-Specific Commands
```toml
[commands]
# Development vs Production
"npm start" = "bun dev"
"npm run build" = "bun run build:prod"

# Different tools for different contexts
kubectl = "k9s"
terraform = "tofu"
aws = "aws --cli-auto-prompt"
```

### Complex Command Transformations
```toml
[commands]
# Add safety flags
"python -m http.server" = "python -m http.server --bind 127.0.0.1"
"php -S" = "php -S 127.0.0.1:8000"

# Add useful options
"git diff" = "git diff --color-words"
"grep -r" = "rg --hidden"
```

### Project-Specific Shortcuts
```toml
[commands]
# Custom project commands
"npm test" = "bun test --watch"
"npm lint" = "bun run lint:fix"
"npm format" = "bun run format:write"

# Database shortcuts
"psql" = "psql -h localhost -U postgres"
"mysql" = "mysql -h localhost -u root -p"
```

## 🎨 Configuration Templates

### Frontend Development
```toml
[commands]
# Package management
npm = "bun"
yarn = "bun"
npx = "bunx"

# Development servers
"npm start" = "bun dev"
"npm run dev" = "bun dev"

# Build and deployment
"npm run build" = "bun run build:prod"
"npm run preview" = "bun run preview"

# Testing
"npm test" = "bun test --watch"
"npm run test:ci" = "bun test --coverage"
```

### Backend Development
```toml
[commands]
# Python tools
pip = "uv pip"
python = "uv run python"
pytest = "uv run pytest"

# Database tools
psql = "psql -h localhost -U postgres"
redis-cli = "redis-cli -h localhost"

# Container tools
docker = "podman"
"docker-compose" = "podman-compose"
```

### DevOps/Infrastructure
```toml
[commands]
# Cloud tools
aws = "aws --cli-auto-prompt"
gcloud = "gcloud --verbosity=info"
az = "az --output table"

# Kubernetes
kubectl = "k9s"
helm = "helm --debug"

# Infrastructure as Code
terraform = "tofu"
ansible = "ansible --diff"
```

## ✅ Configuration Validation

### Testing Your Configuration
```bash
# Test specific command mapping
echo '{"session_id":"test","transcript_path":"","cwd":"","hook_event_name":"PreToolUse","tool_name":"Bash","tool_input":{"command":"npm install"}}' | claude-hook-advisor --hook

# Expected output for npm -> bun mapping:
# {"decision":"block","reason":"Command 'npm' is mapped to use 'bun' instead. Try: bun install"}
```

### Common Configuration Errors

#### Invalid TOML Syntax
```toml
# ❌ Wrong: Missing quotes for keys with spaces
[commands]
git commit = "git commit -S"  # Error: space in key

# ✅ Correct: Quote keys with spaces
[commands]
"git commit" = "git commit -S"
```

#### Circular Mappings
```toml
# ❌ Wrong: Creates infinite loop
[commands]
npm = "yarn"
yarn = "npm"

# ✅ Correct: Map to final tool
[commands]
npm = "bun"
yarn = "bun"
```

## 🔧 Configuration Management

### Multiple Configuration Files
```bash
# Project-specific config
.claude-hook-advisor.toml

# Team-shared config
team.claude-hook-advisor.toml

# Personal overrides
personal.claude-hook-advisor.toml
```

### Configuration Inheritance
While not built-in, you can manage multiple configs:

```bash
# Use team config as base
cp team.claude-hook-advisor.toml .claude-hook-advisor.toml

# Add personal customizations
echo '
[commands]
# Personal preferences
vim = "nvim"
' >> .claude-hook-advisor.toml
```

### Version Control
```bash
# Include in version control for team sharing
git add .claude-hook-advisor.toml

# Or keep personal configs out of version control
echo '.claude-hook-advisor.toml' >> .gitignore
```

## 🎯 Best Practices

1. **Start Simple**: Begin with basic mappings and add complexity gradually
2. **Test Thoroughly**: Verify each mapping works as expected
3. **Document Choices**: Comment your configuration for team members
4. **Use Consistent Patterns**: Establish team conventions for mappings
5. **Regular Updates**: Review and update configurations as tools evolve

---

**Next Steps:**
- [Explore example configurations]examples.md
- [Learn best practices]best-practices.md
- [Set up Claude Code integration]claude-integration.md

#configuration #toml #commands #mapping #setup