A command-line tool that generates shell commands from natural language descriptions using OpenAI's API.
- ๐ค Natural language to shell command conversion
- ๐ Concurrent API calls for better performance
- ๐ก๏ธ Safety-first approach with read-only preferences
- ๐ Verbose mode with detailed API response information
- ๐ฏ Interactive command selection
- ๐ง Cross-platform support (Linux, macOS, windows etc)
- Go 1.24.6 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"ai "find biggest file here"
Select a command:
1) find . -type f -exec ls -la {} + | sort -k5 -nr | head -1
2) du -ah . | sort -rh | head -1
3) ls -lah | sort -k5 -nr | head -1
Enter number: 1ai "search for TODO in all files"
Select a command:
1) grep -r "TODO" .
2) find . -name "*.go" -exec grep -l "TODO" {} +
3) grep -rn "TODO" .
Enter number: 1ai "show files modified in last 24 hours"
Select a command:
1) find . -type f -mtime -1
2) ls -lt | head -10
3) find . -type f -newermt "1 day ago"
Enter number: 1ai bpftrace trace all page faults, show pid, application name
Select a command:
1) sudo bpftrace -e 'tracepoint:exceptions:page_fault_user { printf("%d %s\n", pid, comm); }'
2) sudo bpftrace -e 'tracepoint:exceptions:page_fault_user { printf("%d %s %s\n", pid, comm, str(args->address)); }'
3) sudo bpftrace -e 'tracepoint:exceptions:page_fault_user { printf("%d %s %s\n", pid, comm, args->message ? args->message : ""); }'ai "count lines in all go files"
Select a command:
1) find . -name "*.go" -exec wc -l {} +
2) cloc .
3) find . -name "*.go" | xargs wc -l
Enter number: 1ai "find all TODO comments in source code"
Select a command:
1) grep -r "TODO" .
2) find . -name "*.go" -exec grep -n "TODO" {} +
3) grep -rn "TODO" .
Enter number: 1ai "replace tabs with spaces in all files"
Select a command:
1) find . -name "*.go" -exec sed -i 's/\t/ /g' {} +
2) find . -type f -name "*.go" -exec expand -t 4 {} \; -exec mv {}.exp {} \;
3) sed -i 's/\t/ /g' *.go
Enter number: 1ai "check if port 8080 is open"
Select a command:
1) netstat -tuln | grep 8080
2) lsof -i :8080
3) ss -tuln | grep 8080
Enter number: 1Use the -v flag to see detailed information about API calls and generated commands:
Use the -n flag to specify how many commands to generate (default: 3):
# Generate 5 command options
ai -n 5 "find large files"
# Combine with verbose mode
ai -v -n 2 "show disk usage"Verbose mode displays:
- Number of commands generated
- API request timing information
- All generated command options
- Raw API responses (pretty-printed JSON)
When multiple commands are generated, you'll be prompted to select one:
ai -n 5 "find large files"
Select a command:
1) find . -type f -size +100M
2) du -ah . | sort -rh | head -10
3) find . -type f -exec ls -lh {} + | awk '$5 ~ /[0-9]+M/'
4) ls -lah | sort -k5 -hr | head -10
5) find . -type f -size +50M -exec ls -lh {} +
Enter number: 1
- 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
- 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 commands 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, generated commands, and raw API responses to help diagnose issues.