SPB Git

Repository Public

quickstart.md 5.0 KB 156 lines markdown

1---2title: CLI quickstart3url: https://platform.claude.com/docs/en/cli-sdks-libraries/cli/quickstart4description: Install the ant command-line tool, authenticate, and send your first request to the Claude API.5---67The `ant` CLI provides access to the Claude API from your terminal. Every API resource is exposed as a subcommand, with output formatting, response filtering, and YAML or JSON file input.89<Frame caption="The ant CLI in action.">10  [](https://platform.claude.com/docs/videos/ant-cli-demo.webm)11</Frame>1213Compared to `curl`, `ant` builds request bodies from typed flags or piped YAML instead of hand-written JSON, and inlines file contents into string fields with an `@path` reference. It extracts response fields with a built-in `--transform` query, so you don't need a separate tool such as `jq`, and it paginates list endpoints automatically.1415<Info>16  For endpoint-specific parameters and response schemas, see the [API reference](https://platform.claude.com/docs/en/api/cli/messages/create). This page gets you to a working command. For everything else the CLI does, see [Using the CLI](https://platform.claude.com/docs/en/cli-sdks-libraries/cli/using) and [CLI scripting and automation](https://platform.claude.com/docs/en/cli-sdks-libraries/cli/scripting).17</Info>1819## Installation2021<Tabs>22  <Tab title="Homebrew (macOS)">23    ```bash24    brew install anthropics/tap/ant25    ```26  </Tab>2728  <Tab title="curl (Linux/WSL)">29    For Linux environments, download the release binary directly.3031    ```bash32    VERSION=1.33.033    OS=$(uname -s | tr '[:upper:]' '[:lower:]')34    case $(uname -m) in35      x86_64) ARCH=amd64 ;;36      aarch64) ARCH=arm64 ;;37    esac38    curl -fsSL "https://github.com/anthropics/anthropic-cli/releases/download/v${VERSION}/ant_${VERSION}_${OS}_${ARCH}.tar.gz" \39      | sudo tar -xz -C /usr/local/bin ant40    ```4142    You can find all releases on the [GitHub releases page](https://github.com/anthropics/anthropic-cli/releases).43  </Tab>4445  <Tab title="Go">46    You can also install the CLI from source using `go install`. Requires Go 1.25 or later.4748    ```bash49    go install github.com/anthropics/anthropic-cli/cmd/ant@latest50    ```5152    The binary is placed in `$(go env GOPATH)/bin`. Add it to your `PATH` if it isn't already:5354    ```bash55    export PATH="$PATH:$(go env GOPATH)/bin"56    ```57  </Tab>58</Tabs>5960Check the installation:6162```bash63ant --version64```6566## Authentication6768`ant auth login` opens a browser-based OAuth flow against the Claude Console and stores the resulting credentials locally, so you can call the API without creating or managing an API key.6970```bash CLI71ant auth login72```7374<Note>75  For other ways to authenticate (API key environment variable, headless hosts, multiple workspaces, named profiles, and Workload Identity Federation), see [CLI authentication options](https://platform.claude.com/docs/en/cli-sdks-libraries/cli/authentication).76</Note>7778## Send your first request7980With the binary installed and authenticated, call the [Messages API](https://platform.claude.com/docs/en/api/cli/messages/create):8182```bash83ant messages create \84  --model claude-opus-5 \85  --max-tokens 1024 \86  --message '{role: user, content: "Hello, Claude"}'87```8889```text Output wrap90{91  "model": "claude-opus-5",92  "id": "msg_01YMmR5XodC5nTqMxLZMKaq6",93  "type": "message",94  "role": "assistant",95  "content": [96    {97      "type": "text",98      "text": "Hello! How are you doing today? Is there something I can help you with?"99    }100  ],101  "stop_reason": "end_turn",102  "usage": { "input_tokens": 27, "output_tokens": 20 /*, ... */ }103}104```105106The response is the full API object, pretty-printed because stdout is a terminal.107108## Shell completion109110The CLI ships completion scripts for bash, zsh, fish, and PowerShell. Generate and install one for your shell:111112<Tabs>113  <Tab title="zsh">114    ```bash115    ant @completion zsh > "${fpath[1]}/_ant"116    # Restart your shell or run: autoload -U compinit && compinit117    ```118  </Tab>119120  <Tab title="bash">121    ```bash122    ant @completion bash > /etc/bash_completion.d/ant123    ```124  </Tab>125126  <Tab title="fish">127    ```bash128    ant @completion fish > ~/.config/fish/completions/ant.fish129    ```130  </Tab>131132  <Tab title="PowerShell">133    ```powershell134    ant @completion powershell | Out-String | Invoke-Expression135    # To persist across sessions:136    # ant @completion powershell >> $PROFILE137    ```138  </Tab>139</Tabs>140141## Next steps142143<CardGroup cols={3}>144  <Card title="CLI authentication options" icon="lock" href="https://platform.claude.com/docs/en/cli-sdks-libraries/cli/authentication">145    API keys, headless hosts, multiple workspaces, and named profiles146  </Card>147148  <Card title="Using the CLI" icon="terminal" href="https://platform.claude.com/docs/en/cli-sdks-libraries/cli/using">149    Command structure, output formats, GJSON transforms, and request bodies150  </Card>151152  <Card title="CLI scripting and automation" icon="code" href="https://platform.claude.com/docs/en/cli-sdks-libraries/cli/scripting">153    Version-control API resources, scripting patterns, and use from Claude Code154  </Card>155</CardGroup>156
Files main
Menu

Theme