A command-line tool that generates shell commands from natural language descriptions using OpenAI's API.
- 🤖 Natural language to shell command conversion
- 🛡️ Safety-first approach with read-only preferences
- 📊 Verbose mode with detailed API response information
- 🎯 One suggestion at a time: confirm, retry, or abort with a single keypress
- 🔧 Cross-platform support (Linux, macOS, windows etc)
- Go 1.26 or later
- OpenAI API token
go install github.com/brainexe/ai@latest# Clone the repository
git clone https://github.com/brainexe/ai.git
cd ai-cli
make build- Set your OpenAI API token:
export OPENAI_TOKEN="your-openai-token-here"The tool suggests exactly one command and waits for a single keypress:
- Enter — execute the command
- Esc — reject it and fetch a new suggestion (rejected commands are not suggested again)
- Ctrl-C — abort without executing anything
ai "find biggest file here"
find . -type f -exec ls -la {} + | sort -k5 -nr | head -1
[Enter] run [Esc] retry [Ctrl-C] abortai "search for TODO in all files"
grep -rn "TODO" .
[Enter] run [Esc] retry [Ctrl-C] abortai "show files modified in last 24 hours"
find . -type f -mtime -1
[Enter] run [Esc] retry [Ctrl-C] abortai bpftrace trace all page faults, show pid, application name
sudo bpftrace -e 'tracepoint:exceptions:page_fault_user { printf("%d %s\n", pid, comm); }'
[Enter] run [Esc] retry [Ctrl-C] abortUse the -v flag to see detailed information about the API call and generated command:
ai -v "show disk usage"Verbose mode displays:
- API request timing information
- Raw API response (pretty-printed JSON)
- Read-only preference: Prioritizes non-destructive commands
- Destructive action warnings: Avoids
rm -rf,chmod -R,sudounless explicitly requested - Single command output: Ensures only one safe command per response
- Explicit confirmation: Nothing runs until you press Enter
- Path safety: Properly quotes paths containing spaces
- Command sanitization: Removes code blocks and extra formatting
# build the "ai" binary
make build
# Run linter
make lint# File operations
ai "show files modified in last 24 hours"
ai "count lines in all go files"
# System information
ai "show memory usage"
ai "list running processes"
# Text processing
ai "find all TODO comments in source code"
ai "replace tabs with spaces in all files"
# Network operations
ai "check if port 8080 is open"
ai "show network connections"The tool uses the following environment variables:
OPENAI_TOKEN: Your OpenAI API token in env vars (required)
This project is licensed under MIT License, see the LICENSE file.
"OPENAI_TOKEN not set" error
- Ensure you've exported your OpenAI API token as an environment variable
"No command generated" error
- Try rephrasing your request more clearly
- Check your internet connection
- Verify your OpenAI API token is valid
Command not found
- Make sure the binary is in your PATH or use the full path
ai - Verify the binary has execute permissions
Use the -v flag to see detailed information about what's happening:
ai -v "your command description"This will show API response times, the generated command, and the raw API response to help diagnose issues.