An aesthetic way to use Anthropic claude api via the command line.
To create and run a release version of the CLI, you can use Cargo's release build and install commands. Here are the steps:
- Build a release version (optimized, without debug info):
cargo build --release
This creates an optimized binary in target/release/
- Install it to your system (usually to ~/.cargo/bin which should be in your PATH):
cargo install --path .
After installation, you can run it from anywhere by typing:
claude-cli
Alternative ways:
- Run the release version directly without installing:
./target/release/claude-cli
- Run release version directly through cargo:
cargo run --release
The release version will be significantly faster than the debug version (created by cargo build
or cargo run
without --release
).
Remember you'll need to set your API key first:
claude-cli setkey your-api-key-here
- You'll need a Claude API key from Anthropic to use this CLI tool
- Visit https://console.anthropic.com/ to obtain your API key
- Your API key should start with
sk-ant-
Set your API key using the setkey
command:
claude-cli setkey your-api-key-here
If you're running directly through cargo:
cargo run -- setkey your-api-key-here
Example:
claude-cli setkey sk-ant-api03xxxxxxxxxxxxx
Your API key is stored securely in a configuration file:
- macOS:
~/Library/Application Support/claude-cli/config.json
- Linux:
~/.config/claude-cli/config.json
- Windows:
C:\Users\<USERNAME>\AppData\Roaming\claude-cli\config.json
To verify your API key was saved correctly:
macOS:
cat ~/Library/Application\ Support/claude-cli/config.json
Linux:
cat ~/.config/claude-cli/config.json
Windows (PowerShell):
type $env:APPDATA\claude-cli\config.json
To update your API key, simply run the setkey
command again with your new key:
claude-cli setkey your-new-api-key
The config file containing your API key is stored with user-only read/write permissions. However, please ensure:
- Keep your API key confidential
- Don't share your config file or API key
- If you suspect your API key has been compromised, regenerate it in the Anthropic console immediately
If you get an error about missing API key:
- Verify the key was saved correctly by checking the config file location above
- Ensure the API key starts with
sk-ant-
- Try setting the key again using the
setkey
command - Check file permissions on the config directory and file