Skip to content

Instantly share code, notes, and snippets.

@yy
Last active January 18, 2026 14:20
Show Gist options
  • Select an option

  • Save yy/ebe1851fcb7e4279614ae03131c41a9d to your computer and use it in GitHub Desktop.

Select an option

Save yy/ebe1851fcb7e4279614ae03131c41a9d to your computer and use it in GitHub Desktop.
howto: Natural language to shell commands using Claude Code
#!/bin/bash
set -euo pipefail
# howto - Natural language to shell command using Claude Code
MODEL="haiku"
while getopts "m:" opt; do
case $opt in
m) MODEL="$OPTARG" ;;
*) echo "Usage: howto [-m model] <description>" >&2; exit 1 ;;
esac
done
shift $((OPTIND-1))
[[ $# -eq 0 ]] && { echo "Usage: howto [-m model] <description>" >&2; exit 1; }
SYSTEM_PROMPT="Output ONLY the shell command. No markdown, no backticks, no explanation. Single line. Prefer modern tools (gh, fd, rg, eza) when appropriate."
CMD=$(claude -p --model "$MODEL" --tools "" --system-prompt "$SYSTEM_PROMPT" "$*" 2>/dev/null)
[[ -z "$CMD" ]] && { echo "Error: Failed to generate command" >&2; exit 1; }
echo "$CMD"

howto

Natural language to shell commands using Claude Code.

howto clone anthropics/claude-code with gh  # → gh repo clone anthropics/claude-code
howto find python files over 1mb            # → fd -e py -S +1m
howto -m opus complex k8s query             # use opus for harder tasks

Installation

1. Install Claude Code

npm install -g @anthropic-ai/claude-code

2. Download the script

curl -o ~/.local/bin/howto https://gist.githubusercontent.com/yy/ebe1851fcb7e4279614ae03131c41a9d/raw/howto
chmod +x ~/.local/bin/howto

3. Add shell function

The script outputs the command; this function handles display and execution. Add to ~/.zshrc:

howto() {
    local cmd
    cmd=$("$HOME/.local/bin/howto" "$@") || return 1
    echo "$cmd"
    echo -n "Execute? [Y/n/e] "
    read -r REPLY
    case "$REPLY" in
        [nN]) echo "Aborted." ;;
        [eE]) vared -p "Edit: " cmd && eval "$cmd" ;;
        *) eval "$cmd" ;;
    esac
}

For bash, replace vared -p "Edit: " cmd with read -e -i "$cmd" -p "Edit: " cmd.

Then reload: source ~/.zshrc

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