Repository Public
1---2title: CLI authentication options3url: https://platform.claude.com/docs/en/cli-sdks-libraries/cli/authentication4description: Authenticate the ant CLI with interactive login, API keys, named profiles, and Workload Identity Federation.5---67The `ant` CLI supports several credential sources. The [Quickstart](https://platform.claude.com/docs/en/cli-sdks-libraries/cli/quickstart#authentication) covers the one-command happy path (`ant auth login`). This page covers every option in full.89## Interactive login1011`ant auth login` lets you call the API without creating or managing an API key. It opens a browser-based OAuth flow against the Claude Console and stores the resulting credentials under `$ANTHROPIC_CONFIG_DIR` (see [Configuration directory](https://platform.claude.com/docs/en/manage-claude/wif-reference#configuration-directory) for the OS-specific default). On a remote host or in any environment without a local browser, pass `--no-browser` to print the authorize URL and paste the returned code back into the terminal.1213```bash CLI14ant auth login1516# On a remote host without a browser:17ant auth login --no-browser1819# Bind to a specific workspace and skip the browser picker:20ant auth login --workspace-id wrkspc_01...2122# If the named profile you pass with --profile doesn't exist,23# a new named profile will be created with that name.24ant auth login --profile <profile-name>25```2627During the browser flow, you select an organization and then a [workspace](https://platform.claude.com/docs/en/manage-claude/workspaces). The issued token is [scoped to that workspace](https://platform.claude.com/docs/en/manage-claude/workspaces#api-keys-and-resource-scoping), so the CLI can only see resources that belong to it. Pass `--workspace-id` to bind directly and skip the picker. To work in more than one workspace, see [Switch between workspaces](https://platform.claude.com/docs/en/cli-sdks-libraries/cli/authentication#switch-between-workspaces).2829Interactive login is intended for local development and scripting on your own machine. For non-interactive workloads such as CI, servers, and containers, use [Workload Identity Federation](https://platform.claude.com/docs/en/manage-claude/workload-identity-federation) instead.3031Login writes credentials to `credentials/<profile>.json`. The first login for a profile also creates `configs/<profile>.json` and sets it as the active profile. To remove stored credentials, run `ant auth logout`, or `ant auth logout --all` to clear every profile.3233## Admin access3435By default, `ant auth login` requests a workspace-scoped token. To manage the resources documented on the [Admin API](https://platform.claude.com/docs/en/manage-claude/admin-api) page, request the `org:admin` scope under a dedicated profile:3637```bash CLI38ant auth login --profile admin --scope "org:admin"3940# Print a bearer token for Authorization headers:41ant auth print-credentials --profile admin --access-token42```4344The `org:admin` scope is granted only to organization members with the admin, owner, or primary owner role. The issued token has organization-wide access, and any workspace binding on the profile does not constrain it. Keep the admin profile separate from your day-to-day profile so routine commands never run with elevated access.4546## API key4748The CLI also reads your API key from the `ANTHROPIC_API_KEY` environment variable. Get a key from the [Claude Console](https://platform.claude.com/settings/keys).4950<Tabs>51 <Tab title="zsh">52 ```bash53 echo 'export ANTHROPIC_API_KEY=sk-ant-api03-...' >> ~/.zshrc54 source ~/.zshrc55 ```56 </Tab>5758 <Tab title="bash">59 ```bash60 echo 'export ANTHROPIC_API_KEY=sk-ant-api03-...' >> ~/.bashrc61 source ~/.bashrc62 ```63 </Tab>6465 <Tab title="Windows">66 ```powershell67 setx ANTHROPIC_API_KEY "sk-ant-api03-..."68 ```6970 Open a new terminal for the change to take effect.71 </Tab>72</Tabs>7374To override the key for a single invocation, pass `--api-key`. To point at a different API host, set `ANTHROPIC_BASE_URL` or pass `--base-url`.7576If you are using an API key scoped to multiple workspaces, such as a [personal or service account key](https://platform.claude.com/docs/en/manage-claude/authentication#key-types), you must [specify the workspace](https://platform.claude.com/docs/en/manage-claude/authentication#select-a-workspace) to run your command in. Do this by setting an `ANTHROPIC_WORKSPACE_ID` environment variable, which the CLI reads automatically, or by using the [`--workspace-id` flag](https://platform.claude.com/docs/en/cli-sdks-libraries/cli/using#global-flags). The value must be a `wrkspc_...` ID; the literal `default` that the SDKs accept in `ANTHROPIC_WORKSPACE_ID` for [federated token exchange](https://platform.claude.com/docs/en/manage-claude/wif-reference#environment-variables) isn't valid here.7778```bash CLI79ant messages create \80 --workspace-id wrkspc_01... \81 --model claude-opus-5 \82 --max-tokens 1024 \83 --message '{role: user, content: "Hello, Claude"}'84```8586## Check authentication status8788`ant auth status` prints the credential source the CLI selected (API key environment variable, OAuth login, federation, or profile), the active profile, the workspace the active token is bound to, and the configuration directory paths. Use it to diagnose why a workload picked the wrong credential or workspace.8990```bash CLI91ant auth status92```9394```text95Active profile: default96Config dir: ~/.config/anthropic97Profile config: ~/.config/anthropic/configs/default.json98Credentials: ~/.config/anthropic/credentials/default.json99100Credentials101 (active) * Profile (user_oauth) [via active_config] sk-ant-oat01-EXA...102...103104Workspace105 (active) * Workspace wrkspc_01... (Engineering)106```107108Read the `(active)` rows to see which credential source and workspace won. The command reports status rather than performing a health check, so don't script against the exit status. For the full ordering of credential sources, see [Credential precedence](https://platform.claude.com/docs/en/manage-claude/wif-reference#credential-precedence).109110## Switch between workspaces111112An interactive-login token is bound to a single workspace. To use the CLI against more than one workspace, log in to each under its own named profile, then switch between them:113114```bash CLI115# 1. Create the profile (interactive; pick the other workspace in the116# browser, or pass --workspace-id to skip the picker):117# ant auth login --profile other-ws118119# 2. Make it the default for subsequent commands:120ant profile activate other-ws121122# 3. Or select it for a single command without changing the default:123ant --profile other-ws models list124ANTHROPIC_PROFILE=other-ws ant models list125```126127Run [`ant auth status`](https://platform.claude.com/docs/en/cli-sdks-libraries/cli/authentication#check-authentication-status) to confirm which profile and workspace are active.128129<Note>130 Profiles are only consulted when no API key is set. If `ANTHROPIC_API_KEY` is present in your environment, it overrides every profile and these commands all use that key's workspace (or, for a multi-workspace key, the workspace set with `ANTHROPIC_WORKSPACE_ID` or `--workspace-id`). Unset it before switching profiles.131</Note>132133## Manage profiles134135The `ant profile` subcommands inspect and edit profile state directly:136137```bash CLI138ant profile list139ant profile get --profile other-ws140ant profile set workspace_id wrkspc_01... --profile other-ws141```142143The writable keys for `ant profile set` are `workspace_id`, `base_url`, `organization_id`, `scope`, `client_id`, and `console_url`. Setting `workspace_id` records the target workspace in the profile config but does not rebind credentials that were already issued; run `ant auth login` again under that profile to mint a token for the new workspace.144145For the profile file schema and the federation block, see [Profile configuration file](https://platform.claude.com/docs/en/manage-claude/wif-reference#profile-configuration-file). For Workload Identity Federation, see the [Authentication overview](https://platform.claude.com/docs/en/manage-claude/authentication) and the [WIF reference](https://platform.claude.com/docs/en/manage-claude/wif-reference).146147## Next steps148149<CardGroup cols={3}>150 <Card title="Using the CLI" icon="terminal" href="https://platform.claude.com/docs/en/cli-sdks-libraries/cli/using">151 Command structure, output formats, GJSON transforms, and request bodies152 </Card>153154 <Card title="CLI scripting and automation" icon="code" href="https://platform.claude.com/docs/en/cli-sdks-libraries/cli/scripting">155 Version-control API resources, scripting patterns, and use from Claude Code156 </Card>157158 <Card title="Workload Identity Federation" icon="cloud" href="https://platform.claude.com/docs/en/manage-claude/workload-identity-federation">159 Non-interactive authentication for CI, servers, and containers160 </Card>161</CardGroup>162