Authentication
The Bitbucket CLI supports two authentication methods: OAuth (recommended) and API tokens.
OAuth (recommended)
Section titled “OAuth (recommended)”bb auth loginThis opens your browser where you authorize the CLI with your Bitbucket account. No tokens to copy, no scopes to select manually. Tokens expire after 2 hours and are refreshed automatically.
If BB_API_TOKEN is exported in your shell, bb auth login uses API-token auth instead of opening a browser. It is the variable being set that switches the flow, not its value — even export BB_API_TOKEN= does it. Run unset BB_API_TOKEN first if you want OAuth.
Using a custom OAuth consumer
Section titled “Using a custom OAuth consumer”Organizations can use their own OAuth consumer instead of the built-in default:
bb auth login --client-id YOUR_CLIENT_ID --client-secret YOUR_CLIENT_SECRETTo set up a custom OAuth consumer:
- Go to Workspace settings > Apps and features > OAuth consumers
- Click Add consumer
- Set Callback URL to
http://localhost:19872/callback - Grant permissions: Account (Read), Repositories (Read, Write, Admin), Pull requests (Read, Write)
- Save and use the generated Key as
--client-idand Secret as--client-secret
Custom credentials are stored in your config file for subsequent logins.
API token (for CI/CD and headless environments)
Section titled “API token (for CI/CD and headless environments)”Use API tokens when a browser is not available (SSH sessions, Docker containers, CI/CD pipelines).
-
Create an API token
-
Log in to Bitbucket
-
Go to Personal settings (click your avatar in the bottom left)
-
Navigate to API tokens under “Access management”
-
Click Create API token
-
Give it a descriptive name (e.g., “Bitbucket CLI”)
-
Select the required scopes:
read:user:bitbucket— verify your identityread:repository:bitbucket— list and view repositories, commits, build statuseswrite:repository:bitbucket— set commit build statusesadmin:repository:bitbucket— create repositories, manage default reviewersdelete:repository:bitbucket— delete repositories (optional)read:pullrequest:bitbucket— list and view pull requestswrite:pullrequest:bitbucket— create, edit, merge, approve, decline pull requests
See Token Scopes for a per-command breakdown if you want to mint a token with the minimum scope set for your workflow.
-
Click Create
-
Copy the generated token — Bitbucket will not show it again.
-
-
Authenticate
Terminal window bb auth login -u your-username -p your-api-tokenOr pipe the token via stdin so it never lands in your shell history or
psoutput (recommended):Terminal window echo "$BB_API_TOKEN" | bb auth login -u your-username --with-token--with-tokenreads all of stdin and trims it, so a trailing newline is fine. It cannot be combined with-p— that fails with error5002(“Cannot combine –password with –with-token”). If nothing is piped in, the login fails with5001(“No API token found on stdin”).Or using environment variables:
Terminal window export BB_USERNAME=your-usernameexport BB_API_TOKEN=your-api-tokenbb auth login
See Environment Variables Reference for more details on using environment variables in scripts and CI/CD.
Check auth status
Section titled “Check auth status”bb auth status✓ Logged in to Bitbucket Authentication: OAuth Username: jdoe Display name: Jane Doe Account ID: 5f1a2b3c4d5e6f7a8b9c0d1e Token expires: in 1h 42m Default workspace: acmeToken expires only appears for OAuth logins. Default workspace only appears once one is configured. Add --json for a machine-readable version.
Logout
Section titled “Logout”bb auth logoutThis removes stored credentials and revokes your OAuth token (if using OAuth). Non-auth settings are preserved.
Configuration storage
Section titled “Configuration storage”Credentials are stored in:
- Linux/macOS:
~/.config/bb/config.json - Windows:
%APPDATA%\bb\config.json
See Configuration File Reference for details on the config file format.
Next steps
Section titled “Next steps”- Quick Start Guide - Get up and running in 60 seconds
- Repository Context - How the CLI detects your workspace/repo
- Troubleshooting - Common authentication issues and solutions