# zsh-claude ๐Ÿค– AI-powered command suggestions and explanations for Zsh using Claude AI. Get intelligent shell command help with simple keybindings. Transform natural language into executable shell commands, or get detailed explanations of complex commands - all directly in your terminal with Claude AI integration. ## โœจ Features - **๐Ÿง  Smart Suggestions**: Type natural language, get executable commands - **๐Ÿ“– Command Explanations**: Understand what complex commands do - **โšก Interactive**: Simple keybindings for instant access - **๐Ÿ”’ Standalone**: No GitHub CLI dependencies required - **๐ŸŽฏ Multiple AI Models**: Choose from Claude 3.5 Haiku to Opus 4.1 - **๐Ÿ”ง Easy Setup**: One-command configuration - **๐Ÿ“ฆ Plugin Manager Support**: Works with oh-my-zsh, zinit, antigen, zplug ## ๐Ÿš€ Quick Start ### Prerequisites 1. **Claude API Key**: Get one from [console.anthropic.com/settings/keys](https://console.anthropic.com/settings/keys) 2. **curl**: For API requests (usually pre-installed) 3. **jq**: For JSON parsing ```bash # macOS brew install jq # Ubuntu/Debian sudo apt install jq # CentOS/RHEL sudo yum install jq ``` ## ๐Ÿ“ฆ Installation ### Method 1: Oh My Zsh (Recommended) ```bash # Clone the plugin git clone https://github.com/HundredAcreStudio/zsh-claude ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-claude # Add to your ~/.zshrc plugins list plugins=(... zsh-claude) # Reload your shell source ~/.zshrc ``` ### Method 2: Zinit ```bash # Add to ~/.zshrc zinit load HundredAcreStudio/zsh-claude # Reload shell source ~/.zshrc ``` ### Method 3: Manual Installation ```bash # Clone the repository git clone https://github.com/HundredAcreStudio/zsh-claude ~/.zsh-claude # Add to ~/.zshrc echo 'source ~/.zsh-claude/zsh-claude.plugin.zsh' >> ~/.zshrc # Reload shell source ~/.zshrc ``` ### Other Plugin Managers
Click to expand **Antigen:** ```bash antigen bundle HundredAcreStudio/zsh-claude ``` **Zplug:** ```bash zplug "HundredAcreStudio/zsh-claude" ```
## โš™๏ธ Configuration After installation, run the setup command: ```bash claude-setup ``` This interactive setup will: 1. Prompt for your Claude API key 2. Optional: Configure LiteLLM proxy support 3. Let you choose your preferred AI model 4. Save configuration securely to `~/.config/zsh-claude/config` **Available Models:** - **Claude 3.5 Haiku** (fast, cost-effective) - Recommended - **Claude 3.7 Sonnet** (balanced performance) - **Claude Sonnet 4** (high performance, higher cost) - **Claude Sonnet 4.5** (latest model) - **Claude Opus 4.1** (premium, highest cost) ## ๐ŸŽฏ Usage ### Keybindings | Platform | Suggest Command | Explain Command | |----------|----------------|-----------------| | **macOS** | `Option + \` (`ยซ`) | `Option + Shift + \` (`ยป`) | | **Linux/Windows** | `Alt + \` | `Alt + Shift + \` | > **macOS Note:** The actual characters produced are `ยซ` for suggestions and `ยป` for explanations ### ๐Ÿ’ก Command Suggestions Transform natural language into executable commands: 1. **Type your request:** ``` find all python files modified in the last week ``` 2. **Press the suggestion key** (Option+\\ on macOS, Alt+\\ on Linux/Windows) 3. **Command appears:** ``` find . -name "*.py" -mtime -7 ``` **More Examples:** ```bash # What you type โ†’ What you get compress all jpg files โ†’ tar -czf images.tar.gz *.jpg delete all node_modules โ†’ find . -name "node_modules" -type d -exec rm -rf {} + show disk usage by directory โ†’ du -sh */ | sort -hr ``` ### ๐Ÿ“š Command Explanations Understand complex commands instantly: 1. **Type or paste a command:** ``` find . -type f -name "*.log" -exec grep -l "ERROR" {} \; ``` 2. **Press the explanation key** (Option+Shift+\\ on macOS, Alt+Shift+\\ on Linux/Windows) 3. **Get detailed breakdown:** ``` Explanation: This command searches for all files with .log extension and finds those containing "ERROR": - find . -type f: searches for files starting from current directory - -name "*.log": matches files ending with .log - -exec grep -l "ERROR" {} \;: runs grep on each file, showing only filenames that contain "ERROR" ``` ### ๐Ÿ”ง Manual Commands Use directly from command line: ```bash # Generate suggestions claude-suggest "compress all jpg files" # Explain commands claude-explain "tar -czf archive.tar.gz *.jpg" # Reconfigure settings claude-setup ``` ## ๐ŸŽจ Customization ### Custom Keybindings The plugin includes default keybindings, but you can customize them in your `~/.zshrc`: ```bash # Default keybindings (automatically set by plugin) bindkey 'ยป' zsh_claude_explain # Option+Shift+\ on macOS bindkey 'ยซ' zsh_claude_suggest # Option+\ on macOS # Custom alternatives bindkey "^[s" zsh_claude_suggest # Alt+s bindkey "^[e" zsh_claude_explain # Alt+e bindkey "^@" zsh_claude_suggest # Ctrl+space ``` > **macOS Users:** The actual characters `ยซ` and `ยป` are produced by Option+\\ and Option+Shift+\\ respectively ### Available Widgets - `zsh_claude_suggest`: Generate command suggestions - `zsh_claude_explain`: Explain current command ### Configuration File Advanced users can edit `~/.config/zsh-claude/config`: ```bash ZSH_CLAUDE_API_KEY="your-api-key" ZSH_CLAUDE_MODEL="claude-3-5-haiku-20241022" ZSH_CLAUDE_API_URL="https://api.anthropic.com/v1/messages" ZSH_CLAUDE_MAX_TOKENS="1000" ZSH_CLAUDE_USE_LITELLM="false" ``` ### LiteLLM Proxy Support zsh-claude supports [LiteLLM proxy](https://github.com/BerriAI/litellm) for using alternative LLM providers or custom endpoints: ```bash # Run claude-setup and select LiteLLM proxy option claude-setup # Or manually configure in ~/.config/zsh-claude/config: ZSH_CLAUDE_USE_LITELLM="true" ZSH_CLAUDE_API_URL="http://localhost:4000/v1/messages" ZSH_CLAUDE_API_KEY="your-litellm-key" ``` When LiteLLM mode is enabled, the plugin automatically uses OpenAI-compatible authentication (`Authorization: Bearer`) instead of Anthropic's native format. ### Environment Variables ```bash # Show loading messages even with Powerlevel10k instant prompt export ZSH_CLAUDE_VERBOSE=1 # Add to ~/.zshrc before loading the plugin ``` ## ๐Ÿ”ง Troubleshooting ### Installation Issues
Powerlevel10k instant prompt warning **Problem:** Warning about console output during zsh initialization **Solution:** This is normal behavior. The plugin automatically suppresses loading messages when Powerlevel10k instant prompt is detected. To see loading messages anyway: ```bash # Add to ~/.zshrc before loading the plugin export ZSH_CLAUDE_VERBOSE=1 ``` Or suppress the warning by adding to `~/.zshrc`: ```bash typeset -g POWERLEVEL9K_INSTANT_PROMPT=quiet ```
Missing dependencies **Problem:** "Missing required dependencies" error **Solution:** Install missing tools: ```bash # macOS brew install curl jq # Ubuntu/Debian sudo apt install curl jq # CentOS/RHEL sudo yum install curl jq ```
API key issues **Problem:** "No API key found" error **Solution:** Run setup: ```bash claude-setup ``` **Problem:** "API Error: invalid api key" **Solution:** 1. Get a valid API key from [console.anthropic.com/settings/keys](https://console.anthropic.com/settings/keys) 2. Run `claude-setup` to update your key
### Usage Issues
Keybindings not working **Problem:** Keys don't trigger suggestions **Solutions:** 1. Check terminal compatibility 2. Try custom keybindings (see Customization section) 3. Test with manual commands: `claude-suggest "test"`
No suggestions/explanations **Problem:** Commands return no results **Checklist:** - โœ… Internet connection working - โœ… API key is valid (`claude-setup`) - โœ… API credits available - โœ… Model name is correct - โœ… Test with: `claude-suggest "list files"`
Performance issues **Problem:** Slow responses **Solutions:** 1. Switch to faster model (Claude 3.5 Haiku) 2. Check internet connection 3. Reduce `ZSH_CLAUDE_MAX_TOKENS` in config
## ๐Ÿค Contributing Contributions are welcome! Please feel free to submit a Pull Request. ## ๐Ÿ“„ License This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. ## ๐Ÿ™ Inspiration This plugin is inspired by: - [zsh-github-copilot](https://github.com/loiccoyle/zsh-github-copilot) by loiccoyle - [GitHub Copilot CLI](https://github.com/github/gh-copilot) ## ๐Ÿ“‹ Changelog ### v1.0.0 - โœจ Standalone Claude AI integration - ๐Ÿš€ Command suggestion functionality - ๐Ÿ“– Command explanation functionality - ๐Ÿ“ฆ Support for multiple plugin managers - โŒจ๏ธ Cross-platform keybindings - ๐Ÿ”’ Secure API key management - ๐ŸŽฏ Multiple AI model support