Hooks¶
Shell hooks let wtf integrate deeply with your terminal. When enabled, wtf can automatically capture errors and suggest fixes without you typing anything.
What Are Hooks?¶
Hooks are functions added to your shell config (~/.zshrc, ~/.bashrc, etc.) that run:
- After every command (error hook)
- When a command isn't found (command-not-found hook)
This lets wtf detect problems automatically and offer help.
Available Hooks¶
Error Hook¶
Suggests running wtf when commands fail:
$ npm run biuld
npm error Missing script: "biuld"
💥 Command failed with exit code 1
Run 'wtf' to analyze what went wrong
Then you just type wtf and it already knows the context.
Command Not Found Hook¶
Suggests using wtf when you mistype commands:
Installing Hooks¶
Automatic Setup¶
Run the setup commands:
# Install error hook
$ wtf --setup-error-hook
✓ Error hook installed for zsh
Restart your shell or run: source ~/.zshrc
# Install command-not-found hook
$ wtf --setup-not-found-hook
✓ Command-not-found hook installed for zsh
Restart your shell or run: source ~/.zshrc
Then restart your shell:
Natural Language¶
You can also ask naturally:
$ wtf install shell hooks
✓ Installed both hooks (error + command-not-found)
Restart your shell to activate
What Gets Added to Your Shell Config¶
The hooks add small functions to your shell config:
Error Hook (~/.zshrc):
# wtf error hook
precmd() {
local exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "💥 Command failed with exit code $exit_code"
echo " Run 'wtf' to analyze what went wrong"
fi
}
Command Not Found Hook (~/.zshrc):
# wtf command-not-found hook
command_not_found_handler() {
echo "❌ Command not found: $1"
echo " Try: wtf how do I $1"
return 127
}
These are non-invasive - they just print suggestions, they don't run anything automatically.
Removing Hooks¶
Remove all hooks:
Or remove manually:
# Edit your shell config
$ vim ~/.zshrc
# Delete the wtf hook sections
# (marked with "# wtf error hook" and "# wtf command-not-found hook")
# Restart shell
$ exec zsh
Supported Shells¶
- ✓ zsh - Full support
- ✓ bash - Full support
- ✓ fish - Full support
- ⚠️ Windows (PowerShell/CMD) - Not supported yet
How Hooks Help¶
Without Hooks¶
$ npm run biuld
npm error Missing script: "biuld"
$ wtf
What's your question?
$ what was wrong with my last command?
Let me check...
With Hooks¶
$ npm run biuld
npm error Missing script: "biuld"
💥 Command failed with exit code 1
Run 'wtf' to analyze what went wrong
$ wtf
I see you tried 'npm run biuld'. You meant 'npm run build'.
╭────────────────────────────────╮
│ $ npm run build │
╰────────────────────────────────╯
Run this? [Y/n]
The difference: wtf already knows what went wrong because the hook captured it.
Privacy & Performance¶
Do hooks slow down my terminal? No. They're tiny functions that only run when needed (command fails or isn't found).
What data do hooks collect? Nothing. They just print messages. They don't send data anywhere.
Can I customize the messages? Yes! Edit the hook functions in your shell config to change the text.
Checking if Hooks Are Installed¶
Or check manually:
Troubleshooting¶
Hooks not working after install¶
Make sure you restarted your shell:
Hooks installed but not triggering¶
Check if your shell config sources correctly:
Conflicts with other tools¶
Some tools also use precmd or command_not_found_handler. If you have conflicts:
- Check what else is using those functions
- Combine them manually in your shell config
- Or disable wtf hooks and use
wtfmanually
Removing old hook versions¶
If you upgraded wtf and hooks behave oddly:
This removes old hooks and installs fresh ones.
Tips¶
Start with just error hook:
The error hook is the most useful. Try that first:
Customize the messages:
Edit ~/.zshrc to change what the hooks say:
# Instead of:
echo "💥 Command failed"
# Change to:
echo "Oops! Something broke. Type 'wtf' for help."
Disable temporarily:
Comment out the hooks in your shell config:
Then reload: source ~/.zshrc
Should You Use Hooks?¶
Use hooks if: - ✓ You want automatic error detection - ✓ You often forget what command failed - ✓ You want seamless wtf integration
Skip hooks if: - ✗ You prefer explicit invocation - ✗ You have conflicts with other tools - ✗ You want minimal shell config
Hooks are optional. wtf works great without them.
Next Steps¶
- Memories - Teach wtf your preferences
- Personality - Customize how wtf talks
- Keys - Switch AI providers