Claude Platform Docs

CLI authentication options

Authenticate the ant CLI with interactive sign-in, API keys, named profiles, and Workload Identity Federation.

The ant CLI supports several credential sources. The CLI quickstart covers the one-command sign-in (ant auth login). This page covers every option in full.

Interactive sign-in

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 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.

CLI
ant auth login

# On a remote host without a browser:
ant auth login --no-browser

# Select a specific workspace and skip the browser picker:
ant auth login --workspace-id wrkspc_01...

# If the profile that you name with --profile doesn't exist,
# the sign-in creates it.
ant auth login --profile work

The CLI stores each sign-in under a profile. The first time you sign in under a profile, you select a workspace in the browser. If you belong to more than one Claude Console organization, you select the organization first. The issued token is scoped to that workspace, so the CLI can only see resources that belong to it. Pass --workspace-id to select a workspace directly and skip the workspace picker.

The profile keeps that organization and workspace for its later sign-ins. To work in another organization or workspace, sign in under a new profile (see Switch between workspaces). You can also change the profile’s organization or workspace and sign in again (see Manage profiles).

Interactive sign-in 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 instead.

Signing in writes credentials to credentials/<profile>.json. The first sign-in for a profile also creates configs/<profile>.json.

A sign-in that names a profile, with --profile or ANTHROPIC_PROFILE, makes that profile the active profile. Any command that doesn’t name a profile, a sign-in included, uses the active profile. Until you make another profile active, that’s default.

To remove the active profile’s stored credentials, run ant auth logout. The profile keeps its organization and workspace. To clear every profile, those settings included, run ant auth logout --all.

Admin access

To manage your organization, such as with the organization commands for the Admin API, you need the latest version of ant. To install ant, see Installation in the CLI quickstart. To sign in with the org:admin scope, you need the admin role (see the Admin API page’s Organization roles and permissions section).

Unlike a usual sign-in, which works in one workspace, an admin sign-in can make changes across your organization.

The following commands change environment variables, so run them in a shell that you keep for administration. They list your profiles, unset ANTHROPIC_API_KEY, sign in under a separate profile with the org:admin scope, and export the token. The --admin flag in the ant auth login command adds the org:admin scope to the scopes that a sign-in already requests.

The sign-in also makes the admin profile the CLI’s active profile. Your other shells use it too. Until you switch back, clients in those shells that use the active profile, such as the ant CLI, can run as an admin.

CLI
# List your profiles. An asterisk marks the active one.
# Note it, so that you can switch back later:
ant profile list

# Unset the API key variable.
# While that variable is set, the SDK and the CLI use the key and not the token:
unset ANTHROPIC_API_KEY

ant auth login --profile admin --admin
export ANTHROPIC_AUTH_TOKEN=$(ant auth print-credentials \
  --profile admin --access-token)

In this shell, the SDK and the ant CLI send the exported token on every call, whichever profile is active.

For organization webhooks, sign in another way, as the Sign in for organization webhooks section describes.

In this shell, run organization commands. For example, ant organization:users list lists your organization’s members.

The token in ANTHROPIC_AUTH_TOKEN is short-lived, and nothing renews it there. When requests start to return 401, follow these steps:

  1. Rerun the export command, which gets a new token if the old one has expired.
  2. If requests still return 401, sign in again with the same ant auth login command that you used, and rerun the export command.

When you finish your admin work, undo what the sign-in commands changed. What to run for the active profile depends on whether you have a profile other than the one you signed in under:

  • You have another profile: Switch back to the profile that was active before you signed in. If it was default, run ant profile activate default.
  • You have no other profile: ant auth logout --all revokes the tokens on the server and removes every profile and credential. Run it so that the profile you signed in under doesn’t stay the active one.

If you switched back, the profile you signed in under keeps its credential on disk. If you won’t need that credential for your next admin session, run ant auth logout --profile with the profile’s name, such as admin. That revokes its tokens on the server and deletes the credential.

The unset and export commands changed environment variables only in the shell where you ran them. To undo them, do one of these:

  • Close that shell.
  • To keep using the shell, unset ANTHROPIC_AUTH_TOKEN, and set ANTHROPIC_API_KEY again if you use it.

API key

The CLI also reads your API key from the ANTHROPIC_API_KEY environment variable. Get a key from the Claude Console.

echo 'export ANTHROPIC_API_KEY=sk-ant-api03-...' >> ~/.zshrc
source ~/.zshrc

To override the key for a single run, pass --api-key-stdin and pipe the key to the command. To point at a different API host, set ANTHROPIC_BASE_URL or pass --base-url.

If you use a personal or service account key scoped to the organization, specify the workspace to run your command in. Set the ANTHROPIC_WORKSPACE_ID environment variable, which the CLI reads automatically, or use the --workspace-id flag. The value must be a wrkspc_... ID.

CLI
ant messages create \
  --workspace-id wrkspc_01... \
  --model claude-opus-5-5 \
  --max-tokens 1024 \
  --message '{role: user, content: "Hello, Claude"}'

Claude Models on Google Cloud (Anthropic managed)

To call Claude Models on Google Cloud (Anthropic managed), the CLI uses Google Application Default Credentials instead of ant auth login or an API key. To set up the CLI, follow these steps:

  1. Set up the credentials: See Authentication on Claude Models on Google Cloud (Anthropic managed).
  2. Set your project ID and workspace ID: Pass --google-cloud-project and --google-cloud-workspace-id, or set ANTHROPIC_GOOGLE_CLOUD_PROJECT and ANTHROPIC_GOOGLE_CLOUD_WORKSPACE_ID. For the other settings and their defaults, see Project, location, and workspace resolution.
  3. Leave competing settings unset: An API key, an authentication token, a configuration profile, or Anthropic’s federation variables can take precedence over these settings. Before you run a command, check which settings to leave unset.
  4. Confirm that the CLI uses these settings: Run ant auth status and check that the Google Cloud row is marked (active). If you set them with flags, pass the same flags to ant auth status.

Check authentication status

ant auth status prints the credential source the CLI selected (API key environment variable, OAuth sign-in, federation, Google Cloud, or profile), the active profile, the workspace the active token is scoped to, and the configuration directory paths. Use it to diagnose why a workload picked the wrong credential or workspace.

CLI
ant auth status
Active profile:  default
Config dir:      ~/.config/anthropic
Profile config:  ~/.config/anthropic/configs/default.json
Credentials:     ~/.config/anthropic/credentials/default.json

Credentials
  (active) * Profile (user_oauth) [via active_config]       sk-ant-oat01-EXA...
...

Workspace
  (active) * Workspace                                      wrkspc_01... (Engineering)

Read 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.

Switch between workspaces

A token from an interactive sign-in is scoped to one workspace at most. To use the CLI against more than one workspace, sign in to each under its own named profile, then switch between them:

CLI
# 1. Create the profile (interactive; pick the other workspace in the
#    browser, or pass --workspace-id to skip the picker):
# ant auth login --profile other-ws

# 2. The sign-in made other-ws active. Switch back to your day-to-day
#    profile, such as default:
ant profile activate default

# 3. Use other-ws for one command; later commands still use default:
ant --profile other-ws models list
ANTHROPIC_PROFILE=other-ws ant models list

Run ant auth status to confirm which profile and workspace are active.

Manage profiles

The ant profile subcommands inspect and edit profile state directly:

CLI
ant profile list
ant profile get --profile other-ws
ant profile set workspace_id wrkspc_01... --profile other-ws

The 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.

For the profile file schema and the federation block, see Profile configuration file. For Workload Identity Federation, see Authentication and the WIF reference.

Next steps

Command structure, output formats, GJSON transforms, and request bodies

Version control for API resources, scripting patterns, and use from Claude Code

Non-interactive authentication for CI, servers, and containers

Was this page helpful?