A fish shell function that leverages Claude AI to generate contextually accurate terminal commands for macOS and Linux systems. Simply describe what you want to do, and get the correct command for your specific OS and version.
- Generates commands specific to your OS (macOS/Linux) and version
- Provides correct syntax for fish shell
- Detects system details automatically (e.g., macOS version, Linux distribution)
- Interactive command placement in terminal
- Built-in error handling and validation
- Safe execution (commands are placed on prompt for review)
- fish shell installed and configured
- An Anthropic API key (Get one from Anthropic Console)
curl
andjq
installed on your system
- Add the following environment variables to your
~/.config/fish/config.fish
:
set -gx CLAUDE_MODEL "claude-3-sonnet-20240229"
set -gx CLAUDE_API_KEY "sk-ant-YOUR-API-KEY"
- Copy the
ask-claude.fish
function to your fish functions directory:
mkdir -p ~/.config/fish/functions
cp ask-claude.fish ~/.config/fish/functions/
Simply describe the command you need:
ask-claude "flush DNS cache"
ask-claude "create a new directory called projects"
ask-claude "find all PDF files modified in the last 24 hours"
The function will:
- Generate the appropriate command for your system
- Place it on your command line
- Let you review and edit before execution
macOS example:
> ask-claude "restart DNS"
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
Linux (Debian) example:
> ask-claude "install nginx"
sudo apt install nginx
The function:
- Detects your operating system and version
- On macOS: Identifies version (e.g., Sonoma, Ventura) and specific build
- On Linux: Identifies distribution and version
- Gets shell environment details
- Sends a structured prompt to Claude AI
- Receives and validates the response
- Places the command on your terminal prompt for review
- macOS (all recent versions including Sonoma, Ventura, Monterey, Big Sur)
- Linux (Debian-based distributions)
- Fish shell
- Bash/Zsh shells
- Windows (PowerShell)
- More Linux distributions
- Works only with fish shell currently
- Requires environment variables to be set
- Commands are OS-specific and may not work across different systems
- API key required from Anthropic
Contributions are welcome! Here's how you can help:
- Submit feature requests
- Report bugs
- Add support for more shells
- Improve documentation
- Add tests
- Add support for more Linux distributions
- Improve error handling
- Fork the repository
- Clone your fork
- Make your changes
- Submit a pull request
- API key is stored in fish environment variables
- Commands are reviewed before execution
- No automatic command execution
- All commands are displayed for user review
- Anthropic for the Claude AI API
- Fish Shell community
- All contributors to this project
If you encounter any issues or have questions:
- Check the Issues page
- Create a new issue if yours isn't already listed
- Provide detailed information about your system and the problem
- Basic command generation
- macOS and Linux support
- Fish shell integration
- System version detection
- Interactive command placement