# AI Shell Command Generator
[](https://badge.fury.io/py/ai-shell-command-generator)
[](https://www.python.org/downloads/)
[](https://opensource.org/licenses/MIT)
Generate shell commands from natural language using AI. Supports OpenAI GPT-5, Anthropic Claude, and local Ollama models. Features intelligent risk assessment, teaching mode for learning, and cross-platform support (Windows/macOS/Linux).
## ๐ Table of Contents
- [Features](#-features)
- [Quick Start](#-quick-start)
- [Installation](#-installation)
- [API Key Setup](#-api-key-setup)
- [Usage](#-usage)
- [Interactive Mode](#interactive-mode)
- [Non-Interactive Mode](#non-interactive-mode)
- [Teaching Mode](#-teaching-mode)
- [Shell Support](#-shell-support)
- [Examples](#-examples)
- [Screenshots](#-screenshots)
- [Advanced Usage](#-advanced-usage)
- [Contributing](#-contributing)
- [License](#-license)
## โจ Features
### ๐ค Multi-Provider AI Support
- **OpenAI GPT-5 Family** - Latest GPT-5, GPT-5 Mini, and GPT-5 Nano models
- **Anthropic Claude** - Claude 4.1+, Sonnet 4.5, and Haiku 3.5
- **Ollama (Local AI)** - Privacy-focused, offline, free - use gpt-oss, Qwen, DeepSeek, Mistral, and more
- **Automatic model selection** - Or choose specific models for your needs
### ๐ Teaching Mode (NEW!)
- **Learn while you generate** - Understand commands before running them
- **Command breakdown** - Detailed explanation of each part
- **OS-specific notes** - BSD vs GNU differences, platform gotchas
- **Safer alternatives** - Preview steps before destructive operations
- **Interactive Q&A** - Ask clarifying questions, see examples
- **What-if scenarios** - Explore variations and alternatives
### ๐ฅ๏ธ Cross-Platform Support
- **Windows** - PowerShell and CMD support with native syntax
- **macOS** - BSD-compatible commands, zsh/bash support
- **Linux** - GNU tools with full feature support
- **WSL** - Works seamlessly in Windows Subsystem for Linux
- **Auto-detection** - Detects your shell and OS automatically
### โ ๏ธ Intelligent Risk Assessment
- **AI-powered safety analysis** - Every command checked for risks
- **Color-coded warnings** - HIGH/MEDIUM/LOW risk levels
- **Detailed explanations** - Understand what makes a command risky
- **Safer alternatives** - Suggested preview steps
- **Optional bypass** - Can disable with `--no-risk-check` for automation
### ๐ป Flexible Usage Modes
- **Interactive Mode** - Guided experience with shell detection and confirmations
- **Teaching Mode** - Learn shell commands while generating them
- **Non-Interactive Mode** - Perfect for scripts, CI/CD, and automation
- **Auto-Copy** - Commands copied to clipboard automatically
## โก Quick Start
```bash
# Install with uv (recommended - fast, cross-platform, automatic PATH setup)
uv tool install ai-shell-command-generator
# Use with free local AI (no API key needed)
ai-shell -p ollama -q "find large files"
# Or use with cloud AI (interactive setup on first run)
ai-shell -p openai -q "find large files"
# Learn while you generate
ai-shell --teach -p ollama -q "backup my documents"
```
## ๐ Installation
### Option 1: Using `uv` (โญ Recommended)
[uv](https://github.com/astral-sh/uv) is the fastest, most reliable way to install Python CLI tools. It handles PATH setup automatically on all platforms.
```bash
# Install uv (one-time setup)
# macOS/Linux:
curl -LsSf https://astral.sh/uv/install.sh | sh
# Windows (PowerShell):
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
# Then install ai-shell (works immediately, no PATH configuration needed!)
uv tool install ai-shell-command-generator
# Update to latest version
uv tool upgrade ai-shell-command-generator
# Uninstall cleanly
uv tool uninstall ai-shell-command-generator
```
**Why uv?**
- โ
**10-100x faster** than pip (written in Rust)
- โ
**Automatic PATH setup** - works immediately on Windows/Mac/Linux
- โ
**Isolated environments** - doesn't pollute your Python installation
- โ
**Simple updates** - `uv tool upgrade` keeps you current
- โ
**Clean uninstall** - removes everything cleanly
### Option 2: Using `pipx` (Alternative)
```bash
# Install pipx (if not already installed)
pip install pipx
pipx ensurepath # Add to PATH (may need to restart shell)
# Install ai-shell
pipx install ai-shell-command-generator
# Update
pipx upgrade ai-shell-command-generator
# Uninstall
pipx uninstall ai-shell-command-generator
```
### Option 3: Using `pip` (Traditional)
```bash
# Install globally (may require PATH configuration on Windows)
pip install ai-shell-command-generator
# Or with --user flag
pip install --user ai-shell-command-generator
```
โ ๏ธ **Note:** With pip, Windows users may need to [add Python Scripts to PATH manually](https://realpython.com/add-python-to-path/#how-to-add-python-to-path-on-windows).
### From Source (Development)
```bash
git clone https://github.com/codingthefuturewithai/ai-shell-command-generator.git
cd ai-shell-command-generator
# Using uv (recommended)
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv pip install -e .
# Or using traditional pip
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
pip install -e .
```
**Requirements:** Python 3.10 or higher
### Development Setup
```bash
# Install all dependencies including test tools
pip install -r requirements.txt
# Run tests
python -m pytest tests/ -v
# Run specific test file
python -m pytest tests/unit/test_main.py -v
```
## ๐ API Key Setup
### Option 1: Automatic Setup (Easiest for Beginners)
Just run the tool! When you select OpenAI or Anthropic for the first time:
```bash
ai-shell -p openai -q "your query"
```
You'll be prompted:
```
๐ OpenAI API Key Required
What would you like to do?
1. Enter my OpenAI API key now (I'll save it for you)
2. I'll set it manually via environment variable
3. Use Ollama instead (free, no API key needed)
```
**Select option 1**, paste your key, and it's saved to `~/.ai-shell-env` forever!
### Option 2: Manual Setup
#### Environment Variables (All Platforms)
```bash
# Linux/macOS
export OPENAI_API_KEY="your-key-here"
export ANTHROPIC_API_KEY="your-key-here"
# Windows PowerShell
$env:OPENAI_API_KEY="your-key-here"
$env:ANTHROPIC_API_KEY="your-key-here"
```
#### Project-Specific (.env file)
```bash
# Create .env in your project directory
echo "OPENAI_API_KEY=your-key-here" > .env
echo "ANTHROPIC_API_KEY=your-key-here" >> .env
```
#### Global Config (Persistent)
```bash
# Create ~/.ai-shell-env in your home directory
cat > ~/.ai-shell-env << EOF
OPENAI_API_KEY=your-key-here
ANTHROPIC_API_KEY=your-key-here
EOF
```
### Option 3: Ollama (No API Key Needed!)
```bash
# Install Ollama
curl -fsSL https://ollama.com/install.sh | sh
# Pull a model
ollama pull gpt-oss:latest
# Use immediately
ai-shell -p ollama -q "find large files"
```
**Recommended models:**
- `gpt-oss:latest` - OpenAI's GPT-OSS model
- `qwen2.5-coder:7b` - Excellent for coding tasks
- `deepseek-r1:8b` - Good reasoning capabilities
- `mistral-nemo:12b` - Balanced performance
### Where AI Shell Looks for API Keys
**Priority order:**
1. Environment variables (you set with `export`)
2. `./.env` file in current directory
3. `~/.ai-shell-env` file in your home directory
4. Prompts you to enter and saves to `~/.ai-shell-env`
**Simple and predictable!**
## ๐ Usage
### Interactive Mode
```bash
ai-shell
# or use the short alias
aisc
```
**Interactive flow:**
1. **Select AI Provider** - OpenAI GPT-5, Anthropic Claude, or Ollama
2. **Select Model** - Choose from available models with cost/feature info
3. **Confirm Shell** - Auto-detects your shell (bash/PowerShell/cmd), asks confirmation
4. **Enter Query** - Describe what you want in natural language
5. **Review Command** - See generated command with risk assessment
6. **Choose Action** - Use it, explain how it works, or try different approach
**Example session:**
```
Select AI Provider:
1. OpenAI GPT-5 - GPT-5 models
2. Anthropic Claude - Claude 4.1+ and 3.5 Haiku
3. Ollama (Local) - Privacy-focused, offline, free
Select your preferred AI provider: 3
Discovering available Ollama models...
1. gpt-oss:latest
2. qwen2.5-coder:7b
Select your preferred Ollama model: 1
๐ Detected shell: bash (detected from $SHELL)
Is this correct?
1. Yes, use bash
2. No, let me choose
Select option [1]: 1
Enter your command query (or 'quit' to exit): find large files
Generated command:
find . -type f -size +100M
What would you like to do?
1. Use this command
2. Explain how it works
3. Try a different approach
Select option [1]:
```
### Non-Interactive Mode
**Perfect for scripts and automation:**
```bash
# Basic usage (shell required for safety)
ai-shell -p ollama -s bash -q "find all Python files modified today"
# With OpenAI
ai-shell -p openai -m gpt-5-nano -s bash -q "compress directory"
# With Anthropic
ai-shell -p anthropic -m claude-3-5-haiku-20241022 -s bash -q "backup documents"
# Auto-copy to clipboard
ai-shell -p ollama -s bash -q "show disk usage" --copy
# Disable risk check (for trusted automation)
ai-shell -p ollama -s bash -q "clean temp files" --no-risk-check
# Windows PowerShell
ai-shell -p ollama -s powershell -q "find large files"
# Windows CMD
ai-shell -p ollama -s cmd -q "list files"
```
**โ ๏ธ Note:** Shell (`-s`) is required in non-interactive mode for safety. This prevents wrong commands in CI/CD pipelines.
### ๐ Teaching Mode
**Learn shell commands while generating them:**
```bash
# Start in teaching mode
ai-shell --teach -p ollama -q "find files modified in last 24 hours"
```
**What you get:**
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ TEACHING MODE
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
COMMAND:
find . -type f -mtime -1
BREAKDOWN:
find . - search from current directory
-type f - only files (not directories)
-mtime -1 - modified in last 24 hours
OS NOTES:
macOS uses BSD find (no -printf option)
-mtime uses 24-hour periods
Use -mmin for minute-level precision
SAFER APPROACH:
find . -type f -mtime -1 -ls
(preview files before any action)
WHAT YOU LEARNED:
โ find searches recursively by default
โ -mtime uses days, -mmin uses minutes
โ Negative numbers mean "less than"
โ Always preview before destructive operations
```
**Interactive teaching features:**
- **Ask questions** - "What does -mtime mean?"
- **See examples** - Variations with different options
- **What-if scenarios** - "What if I only want .txt files?"
- **Alternative approaches** - Different ways to solve the same problem
### Command Line Options
```bash
Options:
-p, --provider [openai|anthropic|ollama]
AI provider to use
-s, --shell [cmd|powershell|bash]
Shell environment (required in non-interactive)
-q, --query TEXT Command query (enables non-interactive mode)
-m, --model TEXT Specific model to use
--no-risk-check Disable risk assessment
-c, --copy Auto-copy command to clipboard
-t, --teach Enable teaching mode with explanations
--list-models [openai|anthropic|ollama]
List available models for provider
--help Show help message
```
## ๐ Shell Support
### Supported Shells
| Shell | Platforms | Command Syntax |
|-------|-----------|----------------|
| **bash** | macOS, Linux, WSL, Git Bash | Unix commands (`ls`, `find`, `grep`) |
| **powershell** | Windows, macOS, Linux | PowerShell cmdlets (`Get-ChildItem`, `Copy-Item`) |
| **cmd** | Windows | DOS commands (`dir`, `copy`, `del`) |
### Shell Detection
**Interactive mode:** Auto-detects your shell from `$SHELL` and asks for confirmation
**Non-interactive mode:** Shell must be specified with `-s` flag for safety
```bash
# Explicit shell selection (required for non-interactive)
ai-shell -s bash -q "your query"
ai-shell -s powershell -q "your query"
ai-shell -s cmd -q "your query"
```
### Platform Examples
```bash
# macOS (BSD commands)
ai-shell -s bash -q "find files"
# โ find . -name "*.txt" (no -printf, BSD-compatible)
# Linux (GNU commands)
ai-shell -s bash -q "find files with details"
# โ find . -name "*.txt" -printf "%p %s\n" (GNU-specific)
# Windows PowerShell
ai-shell -s powershell -q "find files"
# โ Get-ChildItem -Recurse -Filter "*.txt"
# Windows CMD
ai-shell -s cmd -q "list files"
# โ dir /s *.txt
```
## ๐ฏ Examples
### Basic Commands
```bash
# List files
ai-shell -p ollama -s bash -q "list files in current directory"
# โ ls -la
# Find files
ai-shell -p ollama -s bash -q "find PDF files larger than 10MB"
# โ find . -name "*.pdf" -size +10M
# Disk usage
ai-shell -p ollama -s bash -q "show disk usage sorted by size"
# โ du -sh * | sort -h
```
### Risky Commands (with warnings)
```bash
ai-shell -p ollama -s bash -q "delete all .log files"
# Output:
find . -type f -name "*.log" -delete
# WARNING: HIGH risk - Recursively deletes all log files without confirmation
```
### Teaching Mode Examples
```bash
# Learn about file operations
ai-shell --teach -p ollama -s bash -q "copy all PDFs to backup folder"
# Understand complex piping
ai-shell --teach -p anthropic -s bash -q "find largest 10 files"
# Learn PowerShell
ai-shell --teach -p ollama -s powershell -q "list running services"
```
### Cross-Platform Examples
```bash
# Same query, different shells
ai-shell -p ollama -s bash -q "find large files"
# โ find . -type f -size +100M
ai-shell -p ollama -s powershell -q "find large files"
# โ Get-ChildItem -Recurse | Where-Object {$_.Length -gt 100MB}
ai-shell -p ollama -s cmd -q "find large files"
# โ forfiles /S /M *.* /C "cmd /c if @fsize GTR 104857600 echo @path"
```
### Advanced Examples
```bash
# Complex text processing
ai-shell -p openai -m gpt-5 -s bash -q "search all JavaScript files for TODO comments, show file and line number"
# System monitoring
ai-shell -p anthropic -s bash -q "show processes using more than 500MB RAM, sorted by memory usage"
# Backup with compression
ai-shell -p ollama -s bash -q "create dated backup archive of documents folder"
```
## ๐ผ๏ธ Screenshots
### Interactive Mode with Risk Assessment

### Interactive Ollama Model Selection

*Interactive mode with Ollama model discovery and selection - users can choose from all available models*
### Non-Interactive Mode

### Ollama Integration with Auto-Copy

## ๐ง Advanced Usage
### List Available Models
```bash
# See OpenAI models with costs
ai-shell --list-models openai
# Output:
# โข GPT-5 Nano (Oct 2025)
# Ultra cost-effective GPT-5 variant
# Cost: $0.05/$0.05 per 1M tokens
# Best for: quick, simple
#
# โข GPT-5 Mini (Oct 2025)
# Cost-effective GPT-5 variant
# Cost: $0.25/$0.25 per 1M tokens
# Best for: general, teaching
#
# โข GPT-5 (Oct 2025)
# Flagship GPT-5 model
# Cost: $1.25/$1.25 per 1M tokens
# Best for: complex, teaching, critical
# See Anthropic models
ai-shell --list-models anthropic
# See your local Ollama models
ai-shell --list-models ollama
```
### Supported Models
**OpenAI:**
- `gpt-5` - Flagship model with advanced capabilities
- `gpt-5-mini` - Balanced performance and cost (default)
- `gpt-5-nano` - Ultra cost-effective for simple tasks
**Anthropic:**
- `claude-sonnet-4-5-20250929` - Latest balanced model (default)
- `claude-opus-4-1-20250805` - Most powerful for complex reasoning
- `claude-3-5-haiku-20241022` - Fast and cost-effective
**Ollama (dynamically detected):**
- `gpt-oss:latest` - OpenAI's open-source GPT-OSS
- `qwen2.5-coder:7b` - Excellent for coding tasks
- `deepseek-r1:8b` - Good reasoning capabilities
- `mistral-nemo:12b` - Balanced performance
- Any model you have pulled locally
### CI/CD and Automation
**For reliable automation, always specify shell:**
```bash
# In scripts or CI/CD pipelines
COMMAND=$(ai-shell -s bash -p ollama -q "cleanup old logs" --no-risk-check)
echo "Generated: $COMMAND"
eval "$COMMAND"
# With error handling
if COMMAND=$(ai-shell -s bash -p ollama -q "backup data" 2>/dev/null); then
echo "Running: $COMMAND"
eval "$COMMAND"
else
echo "Failed to generate command"
exit 1
fi
```
### Environment Variables
```bash
# API Keys (automatic or manual)
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
# Ollama (optional)
OLLAMA_HOST=localhost:11434 # Custom Ollama host
```
## ๐๏ธ How It Works
1. **Shell Detection** - Auto-detects your shell and OS
2. **Query Analysis** - Understands your natural language request
3. **AI Generation** - Creates platform-specific command
4. **Risk Assessment** - Analyzes for potential dangers
5. **Teaching (Optional)** - Explains how the command works
6. **User Confirmation** - Review before execution
7. **Clipboard Copy** - Ready to paste and run
### Risk Assessment
Commands are analyzed for:
- **Data deletion** (`rm`, `dd`, destructive operations)
- **Permission changes** (`chmod`, `chown`, security risks)
- **System modifications** (network, system files)
- **Recursive operations** (widespread changes)
- **Network exposure** (security vulnerabilities)
## ๐งช Development
```bash
# Clone and setup
git clone https://github.com/codingthefuturewithai/ai-shell-command-generator.git
cd ai-shell-command-generator
python -m venv venv
source venv/bin/activate
pip install -e .
# Run tests
python -m pytest tests/ -v
# Install dev dependencies
pip install -e ".[dev]"
```
## ๐ค Contributing
1. Fork the repository
2. Create a feature branch: `git checkout -b feature-name`
3. Make your changes and add tests
4. Commit your changes: `git commit -am 'Add feature'`
5. Push to the branch: `git push origin feature-name`
6. Submit a pull request
## ๐ License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## ๐ Troubleshooting
### API Key Issues
**"API key not found" error:**
- Check `~/.ai-shell-env` exists and has your key
- Or run interactively and let the tool prompt you
- Or set environment variable: `export OPENAI_API_KEY="..."`
**Can't save API key:**
- Check home directory is writable
- Manually create: `echo "OPENAI_API_KEY=your-key" > ~/.ai-shell-env`
### Ollama Issues
**"Could not connect to Ollama":**
```bash
# Start Ollama
ollama serve
# Pull a model if you don't have one
ollama pull gpt-oss:latest
```
**"No models found":**
```bash
# List available models
ollama list
# Pull a model
ollama pull gpt-oss:latest
```
### Shell Issues
**Wrong command syntax generated:**
- Make sure you specified the correct shell with `-s`
- In non-interactive mode, shell is REQUIRED
- Check: `ai-shell -s powershell -q "query"` for PowerShell
- Check: `ai-shell -s cmd -q "query"` for Windows CMD
**Shell not detected correctly:**
- Override in interactive mode when prompted
- Or specify explicitly with `-s bash` or `-s powershell`
### Platform-Specific
**Windows:**
- PowerShell and CMD both supported
- Git Bash works with `-s bash`
- WSL works with `-s bash`
**macOS:**
- Uses BSD-compatible commands automatically
- Both bash and zsh supported (zsh uses bash mode)
**Linux:**
- Full GNU tool support
- bash is default and recommended
## ๐ Acknowledgments
- [OpenAI](https://openai.com/) for GPT-5 models and GPT-OSS
- [Anthropic](https://www.anthropic.com/) for Claude AI
- [Ollama](https://ollama.com/) for local AI infrastructure
- [Click](https://click.palletsprojects.com/) for CLI framework
---
**Made with โค๏ธ for everyone learning to master the command line.**
Raw data
{
"_id": null,
"home_page": null,
"name": "ai-shell-command-generator",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "ai, shell, command, generator, anthropic, ollama, claude, gpt-oss, cli",
"author": null,
"author_email": "Tim Kitchens <your-email@example.com>",
"download_url": "https://files.pythonhosted.org/packages/4e/a0/75d11d998fe697bb65441f6969ae4ed98722062743cf7c9a94ecba91135e/ai_shell_command_generator-2.0.2.tar.gz",
"platform": null,
"description": "# AI Shell Command Generator\n\n[](https://badge.fury.io/py/ai-shell-command-generator)\n[](https://www.python.org/downloads/)\n[](https://opensource.org/licenses/MIT)\n\nGenerate shell commands from natural language using AI. Supports OpenAI GPT-5, Anthropic Claude, and local Ollama models. Features intelligent risk assessment, teaching mode for learning, and cross-platform support (Windows/macOS/Linux).\n\n## \ud83d\udcd1 Table of Contents\n\n- [Features](#-features)\n- [Quick Start](#-quick-start)\n- [Installation](#-installation)\n- [API Key Setup](#-api-key-setup)\n- [Usage](#-usage)\n - [Interactive Mode](#interactive-mode)\n - [Non-Interactive Mode](#non-interactive-mode)\n - [Teaching Mode](#-teaching-mode)\n- [Shell Support](#-shell-support)\n- [Examples](#-examples)\n- [Screenshots](#-screenshots)\n- [Advanced Usage](#-advanced-usage)\n- [Contributing](#-contributing)\n- [License](#-license)\n\n## \u2728 Features\n\n### \ud83e\udd16 Multi-Provider AI Support\n- **OpenAI GPT-5 Family** - Latest GPT-5, GPT-5 Mini, and GPT-5 Nano models\n- **Anthropic Claude** - Claude 4.1+, Sonnet 4.5, and Haiku 3.5\n- **Ollama (Local AI)** - Privacy-focused, offline, free - use gpt-oss, Qwen, DeepSeek, Mistral, and more\n- **Automatic model selection** - Or choose specific models for your needs\n\n### \ud83d\udcda Teaching Mode (NEW!)\n- **Learn while you generate** - Understand commands before running them\n- **Command breakdown** - Detailed explanation of each part\n- **OS-specific notes** - BSD vs GNU differences, platform gotchas\n- **Safer alternatives** - Preview steps before destructive operations\n- **Interactive Q&A** - Ask clarifying questions, see examples\n- **What-if scenarios** - Explore variations and alternatives\n\n### \ud83d\udda5\ufe0f Cross-Platform Support\n- **Windows** - PowerShell and CMD support with native syntax\n- **macOS** - BSD-compatible commands, zsh/bash support\n- **Linux** - GNU tools with full feature support\n- **WSL** - Works seamlessly in Windows Subsystem for Linux\n- **Auto-detection** - Detects your shell and OS automatically\n\n### \u26a0\ufe0f Intelligent Risk Assessment\n- **AI-powered safety analysis** - Every command checked for risks\n- **Color-coded warnings** - HIGH/MEDIUM/LOW risk levels\n- **Detailed explanations** - Understand what makes a command risky\n- **Safer alternatives** - Suggested preview steps\n- **Optional bypass** - Can disable with `--no-risk-check` for automation\n\n### \ud83d\udcbb Flexible Usage Modes\n- **Interactive Mode** - Guided experience with shell detection and confirmations\n- **Teaching Mode** - Learn shell commands while generating them\n- **Non-Interactive Mode** - Perfect for scripts, CI/CD, and automation\n- **Auto-Copy** - Commands copied to clipboard automatically\n\n## \u26a1 Quick Start\n\n```bash\n# Install with uv (recommended - fast, cross-platform, automatic PATH setup)\nuv tool install ai-shell-command-generator\n\n# Use with free local AI (no API key needed)\nai-shell -p ollama -q \"find large files\"\n\n# Or use with cloud AI (interactive setup on first run)\nai-shell -p openai -q \"find large files\"\n\n# Learn while you generate\nai-shell --teach -p ollama -q \"backup my documents\"\n```\n\n## \ud83d\ude80 Installation\n\n### Option 1: Using `uv` (\u2b50 Recommended)\n\n[uv](https://github.com/astral-sh/uv) is the fastest, most reliable way to install Python CLI tools. It handles PATH setup automatically on all platforms.\n\n```bash\n# Install uv (one-time setup)\n# macOS/Linux:\ncurl -LsSf https://astral.sh/uv/install.sh | sh\n\n# Windows (PowerShell):\npowershell -ExecutionPolicy ByPass -c \"irm https://astral.sh/uv/install.ps1 | iex\"\n\n# Then install ai-shell (works immediately, no PATH configuration needed!)\nuv tool install ai-shell-command-generator\n\n# Update to latest version\nuv tool upgrade ai-shell-command-generator\n\n# Uninstall cleanly\nuv tool uninstall ai-shell-command-generator\n```\n\n**Why uv?**\n- \u2705 **10-100x faster** than pip (written in Rust)\n- \u2705 **Automatic PATH setup** - works immediately on Windows/Mac/Linux\n- \u2705 **Isolated environments** - doesn't pollute your Python installation\n- \u2705 **Simple updates** - `uv tool upgrade` keeps you current\n- \u2705 **Clean uninstall** - removes everything cleanly\n\n### Option 2: Using `pipx` (Alternative)\n\n```bash\n# Install pipx (if not already installed)\npip install pipx\npipx ensurepath # Add to PATH (may need to restart shell)\n\n# Install ai-shell\npipx install ai-shell-command-generator\n\n# Update\npipx upgrade ai-shell-command-generator\n\n# Uninstall\npipx uninstall ai-shell-command-generator\n```\n\n### Option 3: Using `pip` (Traditional)\n\n```bash\n# Install globally (may require PATH configuration on Windows)\npip install ai-shell-command-generator\n\n# Or with --user flag\npip install --user ai-shell-command-generator\n```\n\n\u26a0\ufe0f **Note:** With pip, Windows users may need to [add Python Scripts to PATH manually](https://realpython.com/add-python-to-path/#how-to-add-python-to-path-on-windows).\n\n### From Source (Development)\n\n```bash\ngit clone https://github.com/codingthefuturewithai/ai-shell-command-generator.git\ncd ai-shell-command-generator\n\n# Using uv (recommended)\nuv venv\nsource .venv/bin/activate # On Windows: .venv\\Scripts\\activate\nuv pip install -e .\n\n# Or using traditional pip\npython -m venv venv\nsource venv/bin/activate # On Windows: venv\\Scripts\\activate\npip install -r requirements.txt\npip install -e .\n```\n\n**Requirements:** Python 3.10 or higher\n\n### Development Setup\n```bash\n# Install all dependencies including test tools\npip install -r requirements.txt\n\n# Run tests\npython -m pytest tests/ -v\n\n# Run specific test file\npython -m pytest tests/unit/test_main.py -v\n```\n\n## \ud83d\udd11 API Key Setup\n\n### Option 1: Automatic Setup (Easiest for Beginners)\n\nJust run the tool! When you select OpenAI or Anthropic for the first time:\n\n```bash\nai-shell -p openai -q \"your query\"\n```\n\nYou'll be prompted:\n```\n\ud83d\udd11 OpenAI API Key Required\n\nWhat would you like to do?\n1. Enter my OpenAI API key now (I'll save it for you)\n2. I'll set it manually via environment variable\n3. Use Ollama instead (free, no API key needed)\n```\n\n**Select option 1**, paste your key, and it's saved to `~/.ai-shell-env` forever!\n\n### Option 2: Manual Setup\n\n#### Environment Variables (All Platforms)\n```bash\n# Linux/macOS\nexport OPENAI_API_KEY=\"your-key-here\"\nexport ANTHROPIC_API_KEY=\"your-key-here\"\n\n# Windows PowerShell\n$env:OPENAI_API_KEY=\"your-key-here\"\n$env:ANTHROPIC_API_KEY=\"your-key-here\"\n```\n\n#### Project-Specific (.env file)\n```bash\n# Create .env in your project directory\necho \"OPENAI_API_KEY=your-key-here\" > .env\necho \"ANTHROPIC_API_KEY=your-key-here\" >> .env\n```\n\n#### Global Config (Persistent)\n```bash\n# Create ~/.ai-shell-env in your home directory\ncat > ~/.ai-shell-env << EOF\nOPENAI_API_KEY=your-key-here\nANTHROPIC_API_KEY=your-key-here\nEOF\n```\n\n### Option 3: Ollama (No API Key Needed!)\n\n```bash\n# Install Ollama\ncurl -fsSL https://ollama.com/install.sh | sh\n\n# Pull a model\nollama pull gpt-oss:latest\n\n# Use immediately\nai-shell -p ollama -q \"find large files\"\n```\n\n**Recommended models:**\n- `gpt-oss:latest` - OpenAI's GPT-OSS model\n- `qwen2.5-coder:7b` - Excellent for coding tasks\n- `deepseek-r1:8b` - Good reasoning capabilities\n- `mistral-nemo:12b` - Balanced performance\n\n### Where AI Shell Looks for API Keys\n\n**Priority order:**\n1. Environment variables (you set with `export`)\n2. `./.env` file in current directory\n3. `~/.ai-shell-env` file in your home directory\n4. Prompts you to enter and saves to `~/.ai-shell-env`\n\n**Simple and predictable!**\n\n## \ud83d\udcd6 Usage\n\n### Interactive Mode\n\n```bash\nai-shell\n# or use the short alias\naisc\n```\n\n**Interactive flow:**\n1. **Select AI Provider** - OpenAI GPT-5, Anthropic Claude, or Ollama\n2. **Select Model** - Choose from available models with cost/feature info\n3. **Confirm Shell** - Auto-detects your shell (bash/PowerShell/cmd), asks confirmation\n4. **Enter Query** - Describe what you want in natural language\n5. **Review Command** - See generated command with risk assessment\n6. **Choose Action** - Use it, explain how it works, or try different approach\n\n**Example session:**\n```\nSelect AI Provider:\n1. OpenAI GPT-5 - GPT-5 models\n2. Anthropic Claude - Claude 4.1+ and 3.5 Haiku\n3. Ollama (Local) - Privacy-focused, offline, free\nSelect your preferred AI provider: 3\n\nDiscovering available Ollama models...\n1. gpt-oss:latest\n2. qwen2.5-coder:7b\nSelect your preferred Ollama model: 1\n\n\ud83d\udd0d Detected shell: bash (detected from $SHELL)\nIs this correct?\n1. Yes, use bash\n2. No, let me choose\nSelect option [1]: 1\n\nEnter your command query (or 'quit' to exit): find large files\n\nGenerated command:\nfind . -type f -size +100M\n\nWhat would you like to do?\n1. Use this command\n2. Explain how it works\n3. Try a different approach\nSelect option [1]:\n```\n\n### Non-Interactive Mode\n\n**Perfect for scripts and automation:**\n\n```bash\n# Basic usage (shell required for safety)\nai-shell -p ollama -s bash -q \"find all Python files modified today\"\n\n# With OpenAI\nai-shell -p openai -m gpt-5-nano -s bash -q \"compress directory\"\n\n# With Anthropic\nai-shell -p anthropic -m claude-3-5-haiku-20241022 -s bash -q \"backup documents\"\n\n# Auto-copy to clipboard\nai-shell -p ollama -s bash -q \"show disk usage\" --copy\n\n# Disable risk check (for trusted automation)\nai-shell -p ollama -s bash -q \"clean temp files\" --no-risk-check\n\n# Windows PowerShell\nai-shell -p ollama -s powershell -q \"find large files\"\n\n# Windows CMD\nai-shell -p ollama -s cmd -q \"list files\"\n```\n\n**\u26a0\ufe0f Note:** Shell (`-s`) is required in non-interactive mode for safety. This prevents wrong commands in CI/CD pipelines.\n\n### \ud83d\udcda Teaching Mode\n\n**Learn shell commands while generating them:**\n\n```bash\n# Start in teaching mode\nai-shell --teach -p ollama -q \"find files modified in last 24 hours\"\n```\n\n**What you get:**\n```\n\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n\ud83d\udcda TEACHING MODE\n\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n\nCOMMAND:\n find . -type f -mtime -1\n\nBREAKDOWN:\n find . - search from current directory\n -type f - only files (not directories)\n -mtime -1 - modified in last 24 hours\n\nOS NOTES:\n macOS uses BSD find (no -printf option)\n -mtime uses 24-hour periods\n Use -mmin for minute-level precision\n\nSAFER APPROACH:\n find . -type f -mtime -1 -ls\n (preview files before any action)\n\nWHAT YOU LEARNED:\n \u2713 find searches recursively by default\n \u2713 -mtime uses days, -mmin uses minutes\n \u2713 Negative numbers mean \"less than\"\n \u2713 Always preview before destructive operations\n```\n\n**Interactive teaching features:**\n- **Ask questions** - \"What does -mtime mean?\"\n- **See examples** - Variations with different options\n- **What-if scenarios** - \"What if I only want .txt files?\"\n- **Alternative approaches** - Different ways to solve the same problem\n\n### Command Line Options\n\n```bash\nOptions:\n -p, --provider [openai|anthropic|ollama]\n AI provider to use\n -s, --shell [cmd|powershell|bash]\n Shell environment (required in non-interactive)\n -q, --query TEXT Command query (enables non-interactive mode)\n -m, --model TEXT Specific model to use\n --no-risk-check Disable risk assessment\n -c, --copy Auto-copy command to clipboard\n -t, --teach Enable teaching mode with explanations\n --list-models [openai|anthropic|ollama]\n List available models for provider\n --help Show help message\n```\n\n## \ud83d\udc1a Shell Support\n\n### Supported Shells\n\n| Shell | Platforms | Command Syntax |\n|-------|-----------|----------------|\n| **bash** | macOS, Linux, WSL, Git Bash | Unix commands (`ls`, `find`, `grep`) |\n| **powershell** | Windows, macOS, Linux | PowerShell cmdlets (`Get-ChildItem`, `Copy-Item`) |\n| **cmd** | Windows | DOS commands (`dir`, `copy`, `del`) |\n\n### Shell Detection\n\n**Interactive mode:** Auto-detects your shell from `$SHELL` and asks for confirmation\n\n**Non-interactive mode:** Shell must be specified with `-s` flag for safety\n\n```bash\n# Explicit shell selection (required for non-interactive)\nai-shell -s bash -q \"your query\"\nai-shell -s powershell -q \"your query\"\nai-shell -s cmd -q \"your query\"\n```\n\n### Platform Examples\n\n```bash\n# macOS (BSD commands)\nai-shell -s bash -q \"find files\" \n# \u2192 find . -name \"*.txt\" (no -printf, BSD-compatible)\n\n# Linux (GNU commands)\nai-shell -s bash -q \"find files with details\"\n# \u2192 find . -name \"*.txt\" -printf \"%p %s\\n\" (GNU-specific)\n\n# Windows PowerShell\nai-shell -s powershell -q \"find files\"\n# \u2192 Get-ChildItem -Recurse -Filter \"*.txt\"\n\n# Windows CMD\nai-shell -s cmd -q \"list files\"\n# \u2192 dir /s *.txt\n```\n\n## \ud83c\udfaf Examples\n\n### Basic Commands\n```bash\n# List files\nai-shell -p ollama -s bash -q \"list files in current directory\"\n# \u2192 ls -la\n\n# Find files\nai-shell -p ollama -s bash -q \"find PDF files larger than 10MB\"\n# \u2192 find . -name \"*.pdf\" -size +10M\n\n# Disk usage\nai-shell -p ollama -s bash -q \"show disk usage sorted by size\"\n# \u2192 du -sh * | sort -h\n```\n\n### Risky Commands (with warnings)\n```bash\nai-shell -p ollama -s bash -q \"delete all .log files\"\n\n# Output:\nfind . -type f -name \"*.log\" -delete\n\n# WARNING: HIGH risk - Recursively deletes all log files without confirmation\n```\n\n### Teaching Mode Examples\n```bash\n# Learn about file operations\nai-shell --teach -p ollama -s bash -q \"copy all PDFs to backup folder\"\n\n# Understand complex piping\nai-shell --teach -p anthropic -s bash -q \"find largest 10 files\"\n\n# Learn PowerShell\nai-shell --teach -p ollama -s powershell -q \"list running services\"\n```\n\n### Cross-Platform Examples\n```bash\n# Same query, different shells\nai-shell -p ollama -s bash -q \"find large files\"\n# \u2192 find . -type f -size +100M\n\nai-shell -p ollama -s powershell -q \"find large files\"\n# \u2192 Get-ChildItem -Recurse | Where-Object {$_.Length -gt 100MB}\n\nai-shell -p ollama -s cmd -q \"find large files\"\n# \u2192 forfiles /S /M *.* /C \"cmd /c if @fsize GTR 104857600 echo @path\"\n```\n\n### Advanced Examples\n```bash\n# Complex text processing\nai-shell -p openai -m gpt-5 -s bash -q \"search all JavaScript files for TODO comments, show file and line number\"\n\n# System monitoring\nai-shell -p anthropic -s bash -q \"show processes using more than 500MB RAM, sorted by memory usage\"\n\n# Backup with compression\nai-shell -p ollama -s bash -q \"create dated backup archive of documents folder\"\n```\n\n## \ud83d\uddbc\ufe0f Screenshots\n\n### Interactive Mode with Risk Assessment\n\n\n### Interactive Ollama Model Selection\n\n*Interactive mode with Ollama model discovery and selection - users can choose from all available models*\n\n### Non-Interactive Mode\n\n\n### Ollama Integration with Auto-Copy\n\n\n## \ud83d\udd27 Advanced Usage\n\n### List Available Models\n\n```bash\n# See OpenAI models with costs\nai-shell --list-models openai\n\n# Output:\n# \u2022 GPT-5 Nano (Oct 2025)\n# Ultra cost-effective GPT-5 variant\n# Cost: $0.05/$0.05 per 1M tokens\n# Best for: quick, simple\n#\n# \u2022 GPT-5 Mini (Oct 2025)\n# Cost-effective GPT-5 variant \n# Cost: $0.25/$0.25 per 1M tokens\n# Best for: general, teaching\n#\n# \u2022 GPT-5 (Oct 2025)\n# Flagship GPT-5 model\n# Cost: $1.25/$1.25 per 1M tokens\n# Best for: complex, teaching, critical\n\n# See Anthropic models\nai-shell --list-models anthropic\n\n# See your local Ollama models\nai-shell --list-models ollama\n```\n\n### Supported Models\n\n**OpenAI:**\n- `gpt-5` - Flagship model with advanced capabilities\n- `gpt-5-mini` - Balanced performance and cost (default)\n- `gpt-5-nano` - Ultra cost-effective for simple tasks\n\n**Anthropic:**\n- `claude-sonnet-4-5-20250929` - Latest balanced model (default)\n- `claude-opus-4-1-20250805` - Most powerful for complex reasoning\n- `claude-3-5-haiku-20241022` - Fast and cost-effective\n\n**Ollama (dynamically detected):**\n- `gpt-oss:latest` - OpenAI's open-source GPT-OSS\n- `qwen2.5-coder:7b` - Excellent for coding tasks\n- `deepseek-r1:8b` - Good reasoning capabilities\n- `mistral-nemo:12b` - Balanced performance\n- Any model you have pulled locally\n\n### CI/CD and Automation\n\n**For reliable automation, always specify shell:**\n\n```bash\n# In scripts or CI/CD pipelines\nCOMMAND=$(ai-shell -s bash -p ollama -q \"cleanup old logs\" --no-risk-check)\necho \"Generated: $COMMAND\"\neval \"$COMMAND\"\n\n# With error handling\nif COMMAND=$(ai-shell -s bash -p ollama -q \"backup data\" 2>/dev/null); then\n echo \"Running: $COMMAND\"\n eval \"$COMMAND\"\nelse\n echo \"Failed to generate command\"\n exit 1\nfi\n```\n\n### Environment Variables\n\n```bash\n# API Keys (automatic or manual)\nOPENAI_API_KEY=sk-...\nANTHROPIC_API_KEY=sk-ant-...\n\n# Ollama (optional)\nOLLAMA_HOST=localhost:11434 # Custom Ollama host\n```\n\n## \ud83c\udfd7\ufe0f How It Works\n\n1. **Shell Detection** - Auto-detects your shell and OS\n2. **Query Analysis** - Understands your natural language request\n3. **AI Generation** - Creates platform-specific command\n4. **Risk Assessment** - Analyzes for potential dangers\n5. **Teaching (Optional)** - Explains how the command works\n6. **User Confirmation** - Review before execution\n7. **Clipboard Copy** - Ready to paste and run\n\n### Risk Assessment\n\nCommands are analyzed for:\n- **Data deletion** (`rm`, `dd`, destructive operations)\n- **Permission changes** (`chmod`, `chown`, security risks)\n- **System modifications** (network, system files)\n- **Recursive operations** (widespread changes)\n- **Network exposure** (security vulnerabilities)\n\n## \ud83e\uddea Development\n\n```bash\n# Clone and setup\ngit clone https://github.com/codingthefuturewithai/ai-shell-command-generator.git\ncd ai-shell-command-generator\npython -m venv venv\nsource venv/bin/activate\npip install -e .\n\n# Run tests\npython -m pytest tests/ -v\n\n# Install dev dependencies\npip install -e \".[dev]\"\n```\n\n## \ud83e\udd1d Contributing\n\n1. Fork the repository\n2. Create a feature branch: `git checkout -b feature-name`\n3. Make your changes and add tests\n4. Commit your changes: `git commit -am 'Add feature'`\n5. Push to the branch: `git push origin feature-name`\n6. Submit a pull request\n\n## \ud83d\udcdd License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## \ud83d\udd0d Troubleshooting\n\n### API Key Issues\n\n**\"API key not found\" error:**\n- Check `~/.ai-shell-env` exists and has your key\n- Or run interactively and let the tool prompt you\n- Or set environment variable: `export OPENAI_API_KEY=\"...\"`\n\n**Can't save API key:**\n- Check home directory is writable\n- Manually create: `echo \"OPENAI_API_KEY=your-key\" > ~/.ai-shell-env`\n\n### Ollama Issues\n\n**\"Could not connect to Ollama\":**\n```bash\n# Start Ollama\nollama serve\n\n# Pull a model if you don't have one\nollama pull gpt-oss:latest\n```\n\n**\"No models found\":**\n```bash\n# List available models\nollama list\n\n# Pull a model\nollama pull gpt-oss:latest\n```\n\n### Shell Issues\n\n**Wrong command syntax generated:**\n- Make sure you specified the correct shell with `-s`\n- In non-interactive mode, shell is REQUIRED\n- Check: `ai-shell -s powershell -q \"query\"` for PowerShell\n- Check: `ai-shell -s cmd -q \"query\"` for Windows CMD\n\n**Shell not detected correctly:**\n- Override in interactive mode when prompted\n- Or specify explicitly with `-s bash` or `-s powershell`\n\n### Platform-Specific\n\n**Windows:**\n- PowerShell and CMD both supported\n- Git Bash works with `-s bash`\n- WSL works with `-s bash`\n\n**macOS:**\n- Uses BSD-compatible commands automatically\n- Both bash and zsh supported (zsh uses bash mode)\n\n**Linux:**\n- Full GNU tool support\n- bash is default and recommended\n\n## \ud83d\ude4f Acknowledgments\n\n- [OpenAI](https://openai.com/) for GPT-5 models and GPT-OSS\n- [Anthropic](https://www.anthropic.com/) for Claude AI\n- [Ollama](https://ollama.com/) for local AI infrastructure\n- [Click](https://click.palletsprojects.com/) for CLI framework\n\n---\n\n**Made with \u2764\ufe0f for everyone learning to master the command line.**\n",
"bugtrack_url": null,
"license": null,
"summary": "AI-powered shell command generator with dual provider support and safety features",
"version": "2.0.2",
"project_urls": {
"Documentation": "https://github.com/codingthefuturewithai/ai-shell-command-generator#readme",
"Homepage": "https://github.com/codingthefuturewithai/ai-shell-command-generator",
"Issues": "https://github.com/codingthefuturewithai/ai-shell-command-generator/issues",
"Repository": "https://github.com/codingthefuturewithai/ai-shell-command-generator"
},
"split_keywords": [
"ai",
" shell",
" command",
" generator",
" anthropic",
" ollama",
" claude",
" gpt-oss",
" cli"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "d193e70cd8e546d70b20ed21e8dcfb3e271b2a09c447ccb8f3a2c063ce20312e",
"md5": "fe6b12b6931f5f530045ae4737f722b4",
"sha256": "5fd6b3657a23c097f89cbfee050297ccd8af62d0792b5e66338d279c463a9e5b"
},
"downloads": -1,
"filename": "ai_shell_command_generator-2.0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "fe6b12b6931f5f530045ae4737f722b4",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 42692,
"upload_time": "2025-10-09T03:48:19",
"upload_time_iso_8601": "2025-10-09T03:48:19.795200Z",
"url": "https://files.pythonhosted.org/packages/d1/93/e70cd8e546d70b20ed21e8dcfb3e271b2a09c447ccb8f3a2c063ce20312e/ai_shell_command_generator-2.0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "4ea075d11d998fe697bb65441f6969ae4ed98722062743cf7c9a94ecba91135e",
"md5": "96709fd044a332a980fea40621a8dc5f",
"sha256": "d377b4a1367bcfc0f843147a6239b934ffed1b76173d9dde14be275baf14d4d5"
},
"downloads": -1,
"filename": "ai_shell_command_generator-2.0.2.tar.gz",
"has_sig": false,
"md5_digest": "96709fd044a332a980fea40621a8dc5f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 609515,
"upload_time": "2025-10-09T03:48:21",
"upload_time_iso_8601": "2025-10-09T03:48:21.427205Z",
"url": "https://files.pythonhosted.org/packages/4e/a0/75d11d998fe697bb65441f6969ae4ed98722062743cf7c9a94ecba91135e/ai_shell_command_generator-2.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-10-09 03:48:21",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "codingthefuturewithai",
"github_project": "ai-shell-command-generator#readme",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "anthropic",
"specs": [
[
"==",
"0.69.0"
]
]
},
{
"name": "openai",
"specs": [
[
">=",
"1.0.0"
]
]
},
{
"name": "python-dotenv",
"specs": [
[
"==",
"1.1.1"
]
]
},
{
"name": "click",
"specs": [
[
"==",
"8.3.0"
]
]
},
{
"name": "pyperclip",
"specs": [
[
"==",
"1.11.0"
]
]
},
{
"name": "ollama",
"specs": [
[
"==",
"0.6.0"
]
]
},
{
"name": "pytest",
"specs": [
[
">=",
"7.0.0"
]
]
}
],
"lcname": "ai-shell-command-generator"
}