AI-powered shell, helping you create correct command format and explain for all the errors. It's designed for terminal enthusiasts!
py-ai-shell transforms your natural language descriptions into shell commands, explains what they do, and helps you fix errors. It's like having a shell expert by your side, making command-line work more accessible and efficient, and quickly learn form a master.
pip install py-ai-shell
# need to set up for the first time. Minimum need to set up OPENAI_KEY
ai config set OPENAI_KEY=your_api_keySystem Requirements:
- Python 3.8 or higher
- OpenAI API key (Or any compatible LLM models)
py-ai-shell works on Linux, macOS, and Windows with support for bash, zsh, fish, and PowerShell.
# Start py-ai-shell interactive mode
ai
# Run with a initial request
ai "list all files in the current directory"
When you run a command, py-ai-shell will:
- Generate the appropriate shell command
- Show you what it's going to do
- Execute the command when you approve
- Provide explanations and error analysis if needed
- Natural Language Command Generation: Convert plain English to shell commands
- Command Explanations: Understand what commands do before running them
- Error Analysis: Get explanations and suggestions when commands fail
- Interactive Mode: Full interactive shell experience
- Configurable: Use models you specify
- Copy to Clipboard: Easily copy generated commands
py-ai-shell can be configured using the config command:
# Set your OpenAI API key
ai config set OPENAI_KEY=your_api_key
# Set the model to use (default: gpt-4.1-nano)
ai config set MODEL=gpt-4.1-nano
# Set API endpoint (useful for proxies or alternative providers)
ai config set OPENAI_API_ENDPOINT=https://api.openai.com/v1
Configuration is stored in ~/.config/py-ai-shell/config.ini and can be edited directly.
When a command fails, py-ai-shell can analyze the error and suggest fixes:
$ ai "find files modified in the last 24 hours"
# If the command fails, py-ai-shell will offer to analyze the error
Command failed. Would you like an explanation? (?/??/???)Enter ? for a brief explanation, ?? for a standard explanation, or ??? for a detailed analysis.
py-ai-shell maintains a history of your recent commands and their results, providing context for future commands. This helps the AI understand your environment and previous actions. You can refer the history using terms like "previous results, previous commands", etc.
After a command is proposed, you have options to:
a/A: Accept and run the commande/E: Edit the command before runningr/R: Revise (ask AI to generate a new command)c/C: Copy the command to clipboard onlys/S: Stick to your original commandq/Q: Quit/cancel
- It does not work well with interactive terminal applications that require a TTY, such as the vi editor. Screen display could be complicated.
- Control-C might not be able to terminate existing command execution.
- Support MCP, especially document lookup, internet searching, and file operations
- Using agent for more complex tasks, like dangerous command protection, error alerts, etc.
- Enhance once-off mode functionality
-
Clone the repository:
git clone https://github.com/cheney-yan/py-ai-shell.git cd py-ai-shell -
Install development dependencies:
make dev
-
Run locally (with hot loading):
./local_run.py
make help: Show available commandsmake clean: Remove all build, test, coverage and Python artifactsmake dist: Package for distributionmake dev: Install development dependenciesmake version: Create new package versionmake publish: Publish to PyPImake git_tag: Create github tag by package version
Contributions are welcome!
This project is licensed under the MIT License - see the LICENSE file for details.
- This project is inspired by AI Shell
- Built with OpenAI API
- Command-line interface powered by Click
- Terminal styling with Rich
