Skip to content

Instantly share code, notes, and snippets.

@lukeocodes
Last active March 19, 2026 12:00
Show Gist options
  • Select an option

  • Save lukeocodes/6172ae4cbbb2e7349558d3fed02fa454 to your computer and use it in GitHub Desktop.

Select an option

Save lukeocodes/6172ae4cbbb2e7349558d3fed02fa454 to your computer and use it in GitHub Desktop.
Use Claude Code as a zsh command_not_found_handler — type natural language in your terminal and let Claude figure it out

Claude Code command_not_found_handler for zsh

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".

What it does

  • Natural language tasks — type things like clone deepgram/stick-fighter into this directory and 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 found message

Prerequisites

  • Claude Code installed and authenticated (npm install -g @anthropic-ai/claude-code)
  • zsh shell

Install

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

Examples

# 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: asdfghjkl

⚠️ Caution

This 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment