When you type something in your terminal that isn't a real command, this handler pipes it to Claude Code instead of just showing "command not found".
- Natural language tasks — type things like
clone deepgram/stick-fighter into this directoryand Claude will handle it - Typo correction — mistype a command and Claude will suggest and run the correct one
- Ambiguous input — if Claude can't figure out what you meant, it falls back to the standard
command not foundmessage
- Claude Code installed and authenticated (
npm install -g @anthropic-ai/claude-code) - zsh shell
Add this to your ~/.zshrc:
command_not_found_handler() {
local full_command="$*"
echo "Thinking: $full_command..."
echo "$full_command" | claude -p \
--dangerously-skip-permissions \
--verbose \
--output-format text \
--append-system-prompt "You are a fallback command handler. The user typed something into their terminal that didn't match any command in PATH, so it was piped to you. Be helpful but CAUTIOUS:
- If the intent is clearly a natural language question or task, answer it.
- If it looks like a typo of a real command, suggest the correct command and then run it, telling the user what you did.
- If the intent is ambiguous or unclear, just print: command not found: \$full_command
- NEVER run destructive commands (rm -rf, drop, reset --hard, etc.) without explicit confirmation.
- Prefer explaining what you'd do over silently doing it."
}Then reload your shell:
source ~/.zshrc# Natural language
$ clone deepgram/stick-fighter into this directory
Thinking: clone deepgram/stick-fighter into this directory...
Done — deepgram/stick-fighter has been cloned into ./stick-fighter.
# Typo correction
$ gti status
Thinking: gti status...
Looks like you meant `git status` — running it now:
On branch main
nothing to commit, working tree clean
# Unknown input
$ asdfghjkl
Thinking: asdfghjkl...
command not found: asdfghjklThis uses --dangerously-skip-permissions, which means Claude can run commands without asking. Only use this if you understand the risks. Claude is instructed to be cautious and avoid destructive operations, but use at your own discretion.