A command-line interface for interacting with Claude, Anthropic's AI assistant. Ask questions, process files, pipe command outputs directly to Claude, and execute natural language commands from your terminal.
- Python 3.7 or higher
- An Anthropic API key (get one here)
- Clone or download this repository:
git clone <repository-url>
cd claude-cli
- Run the installation script:
chmod +x install.sh
./install.sh
- Source your shell configuration:
source ~/.bashrc # or source ~/.zshrc for Zsh
- Set up your API key:
export ANTHROPIC_API_KEY='your-key-here'
Add this to your .bashrc
or .zshrc
to make it permanent.
The installation script will:
- Create a virtual environment
- Install all dependencies
- Set up the CLI command in your PATH
- Configure your shell environment
Ask Claude questions directly:
ai "what is the capital of France?"
ai "how do I list all Python files in a directory?"
Execute terminal commands using natural language:
ai -c "list all files recursively in this folder"
ai -c "show disk usage for all drives"
ai -c "find all python files modified in the last week"
ai -c "create a new directory called projects"
The -c
or --command
flag tells Claude to:
- Convert your natural language request into a shell command
- Show you the command it's about to execute
- Run the command and display its output
Process file contents:
cat document.txt | ai summarize
cat code.py | ai "explain this code"
Process the output of other commands:
ls -la | ai "explain these files"
ps aux | ai "which processes are using the most CPU?"
# Get coding help
ai "write a python function to calculate fibonacci numbers"
# Execute system commands in natural language
ai -c "compress all jpg files in current directory"
ai -c "show memory usage"
ai -c "find large files over 1GB"
# Analyze logs
tail -n 50 /var/log/system.log | ai "find any error patterns"
# Explain commands
man grep | ai "explain grep's most useful options"
# Summarize documents
cat meeting_notes.txt | ai "create a bullet-point summary"
When using the -c/--command
flag:
- The tool will always show you the command it plans to execute before running it
- Review the command to ensure it matches your intentions
- Be cautious with destructive operations (delete, remove, etc.)
- The tool executes commands with your current user permissions
ANTHROPIC_API_KEY
: Your Anthropic API key (required)
- Uses Python virtual environment for isolated dependencies
- Installed in
~/bin
with automatic PATH configuration - Dependencies managed through
requirements.txt
- Maximum response length: 1000 tokens
- Uses Claude 3.5 Sonnet model
- Natural language command conversion using Claude
- Safe command execution with subprocess module
The script will:
- Check for the presence of the API key
- Provide clear error messages if the API call fails
- Show command execution errors if they occur
- Exit with appropriate status codes
- Maximum response length is set to 1000 tokens
- Requires active internet connection
- API usage is subject to Anthropic's rate limits and pricing
- Command execution is limited to your user permissions
- Complex multi-step commands may need to be broken down
claude-cli/
├── README.md
├── requirements.txt
├── install.sh
├── main.py
└── .venv/ # Created during installation
If you encounter any issues:
- Ensure Python 3.7+ is installed:
python3 --version
- Verify the API key is set:
echo $ANTHROPIC_API_KEY
- Check that
~/bin
is in your PATH:echo $PATH
- Try reinstalling:
./install.sh
- For command execution issues, try running the command directly in terminal
Feel free to open issues or submit pull requests for improvements.
MIT License - See LICENSE file for details.