Authentication
Bitbucket CLI supports two authentication methods. OAuth 2.0 is recommended — it is more secure and refreshes tokens automatically. API tokens are the fallback for CI and automation.
Option A — OAuth 2.0 (recommended)
Section titled “Option A — OAuth 2.0 (recommended)”bitbucket auth login --oauthYou’ll need an OAuth consumer first:
- Go to your Bitbucket workspace settings.
- Set the callback URL to one of the following — the CLI uses the first available port:
http://127.0.0.1:8080/callbackhttp://127.0.0.1:3000/callbackhttp://127.0.0.1:8888/callbackhttp://127.0.0.1:9000/callback
- Grant these permissions: Account (Read), Repositories (Read), Pull requests (Read/Write), Issues (Read/Write), Pipelines (Read/Write).
- Copy the Key (client ID) and Secret when prompted.
You can also pass the consumer credentials non-interactively with --client-id / --client-secret, or via the BITBUCKET_CLIENT_ID and BITBUCKET_CLIENT_SECRET environment variables.
Option B — API token (CI / automation)
Section titled “Option B — API token (CI / automation)”bitbucket auth login --api-keyCreate the token first:
- Open your Bitbucket personal settings and go to the API tokens section.
- Create a token with the permissions you need.
- Enter your Atlassian account email and the token when prompted, or run non-interactively:
bitbucket auth login --api-key --email you@example.com --token <api-token>The email and token can also be supplied via BITBUCKET_EMAIL and BITBUCKET_API_TOKEN.
Checking and clearing credentials
Section titled “Checking and clearing credentials”bitbucket auth status # show the authenticated accountbitbucket auth logout # remove stored credentialsCredential storage
Section titled “Credential storage”Credentials are stored in your operating system’s keyring when one is available. On systems without a keyring (for example, headless CI), they fall back to a restricted-permission file at ~/.config/bitbucket/credentials.json (mode 0600 on Unix).