Authentication
The Bitbucket CLI supports two authentication methods: OAuth (recommended) and API Tokens.
OAuth (Recommended)
Section titled “OAuth (Recommended)”The simplest way to authenticate. Just run:
bb auth loginThis opens your browser where you authorize the CLI with your Bitbucket account. No tokens to copy, no scopes to select manually.
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 repositorieswrite:repository:bitbucket— create repositoriesadmin:repository:bitbucket— delete repositories (optional)read:pullrequest:bitbucket— list and view pull requestswrite:pullrequest:bitbucket— create, edit, merge, approve, decline pull requests
- Click Create
- Copy the generated token - you won’t be able to see it again!
-
Authenticate
Terminal window bb auth login -u your-username -p your-api-tokenOr 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 statusThis shows your current authentication method, account information, and token expiry (for OAuth).
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