Skip to content

liangtf/ai-shell

 
 

Repository files navigation

AI Shell

Fork Notice: This is a fork of BuilderIO/ai-shell with enhanced features:

  • Added Anthropic Claude API support alongside OpenAI
  • Changed default behavior to silent mode (no explanations by default)
  • Added -e/--explain flag for verbose mode with detailed explanations

A CLI that converts natural language to shell commands.

Inspired by the GitHub Copilot X CLI, but open source for everyone.

Setup

The minimum supported version of Node.js is v14

  1. Get your API key from either:

    Note: You'll need to create an account and set up billing with your chosen provider.

  2. Configure ai-shell with your API key and provider:

    # For OpenAI (default) ai config set AI_API_KEY=<your openai token> ai config set AI_PROVIDER=openai # For Anthropic Claude ai config set AI_API_KEY=<your anthropic token> ai config set AI_PROVIDER=anthropic

    This will create a .ai-shell file in your home directory.

Usage

ai <prompt>

For example:

ai list all log files

Then you will get an output like this, where you can choose to run the suggested command, revise the command via a prompt, or cancel:

◇ Your script: │ │ find . -name "*.log" │ ◆ Run this script? │ ● ✅ Yes (Lets go!) │ ○ 📝 Revise │ ○ ❌ Cancel └

To see detailed explanations, use the -e flag:

ai -e list all log files

This will show:

◇ Your script: │ │ find . -name "*.log" │ ◇ Explanation: │ │ 1. Searches for all files with the extension ".log" in the current directory and any subdirectories. │ ◆ Run this script? │ ● ✅ Yes (Lets go!) │ ○ 📝 Revise │ ○ ❌ Cancel └

Command flags

AI Shell supports several command-line flags:

  • -e, --explain: Show detailed explanations (verbose mode)
  • -p, --prompt <string>: Specify prompt directly as argument
  • --version: Show version information
  • --help: Show help information

Special characters

Note that some shells handle certain characters like the ? or * or things that look like file paths specially. If you are getting strange behaviors, you can wrap the prompt in quotes to avoid issues, like below:

ai 'what is my ip address'

Chat mode

ai chat

With this mode, you can engage in a conversation with the AI and receive helpful responses in a natural, conversational manner directly through the CLI:

┌ Starting new conversation │ ◇ You: │ how do I serve a redirect in express │ ◇ AI Shell: In Express, you can use the `redirect()` method to serve a redirect. The `redirect()` method takes one argument, which is the URL that you want to redirect to.  Here's an example:  \`\`\`js app.get('/oldurl', (req, res) => {  res.redirect('/newurl'); }); \`\`\`

Explanation mode (show detailed explanations)

By default, AI Shell runs in silent mode (shows only the generated command). You can enable detailed explanations using the -e or --explain flag:

ai -e list all log files

or save verbose mode as a preference using this command:

ai config set SILENT_MODE=false

Custom API endpoint

You can set a custom API endpoint (useful for proxies or alternative endpoints):

# For OpenAI (default: https://api.openai.com/v1) ai config set AI_API_ENDPOINT=<your proxy endpoint> # For Anthropic (default: https://api.anthropic.com) ai config set AI_API_ENDPOINT=<your proxy endpoint>

Set Language

The AI Shell's default language is English, but you can easily switch to your preferred language by using the corresponding language keys, as shown below:

Language Key
English en
Simplified Chinese zh-Hans
Traditional Chinese zh-Hant
Spanish es
Japanese jp
Korean ko
French fr
German de
Russian ru
Ukrainian uk
Vietnamese vi
Arabic ar
Portuguese pt
Turkish tr

For instance, if you want to switch to Simplified Chinese, you can do so by setting the LANGUAGE value to zh-Hans:

ai config set LANGUAGE=zh-Hans

This will set your language to Simplified Chinese.

Config UI

To use a more visual interface to view and set config options you can type:

ai config

To get an interactive UI like below:

◆ Set config: │ ○ AI API Key │ ○ AI Provider │ ○ AI API Endpoint │ ○ Silent Mode │ ● Model (gpt-4o-mini) │ ○ Language │ ○ Cancel └

Common Issues

429 error

Some users are reporting a 429 error from their AI provider. This is due to incorrect billing setup or excessive quota usage.

For OpenAI: Please follow this guide to fix it. You can activate billing at this link.

For Anthropic: Check your usage and billing at Anthropic Console.

Motivation

I am not a bash wizard, and am dying for access to the copilot CLI, and got impatient.

Contributing

If you want to help fix a bug or implement a feature in Issues (tip: look out for the help wanted label), checkout the Contribution Guide to learn how to setup the project.

Supported AI Providers

  • OpenAI: GPT-4, GPT-4o, GPT-4o-mini, and other OpenAI models
    • Default model: gpt-4o-mini
  • Anthropic: Claude 3.5 Sonnet, Claude 3 Haiku, Claude 3 Opus, Claude Sonnet 4
    • Default model: claude-sonnet-4-20250514

Credit

  • Thanks to GitHub Copilot for their amazing tools and the idea for this.
  • Thanks to Hassan and his work on aicommits, which inspired the workflow and some parts of the code and flows
  • Thanks to Anthropic for providing Claude AI capabilities

About

A CLI that converts natural language to shell commands.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 98.1%
  • JavaScript 1.9%