This document provides guidance for LLMs (Claude, GPT-4, etc.) and autonomous agents (Devin, OpenHands, Claude Code) to effectively use the bb CLI for Bitbucket Cloud operations.
bb is an unofficial command-line interface for Bitbucket Cloud, similar to GitHub's gh CLI. It allows you to interact with Bitbucket repositories, pull requests, issues, pipelines, and more from the terminal.
Bitbucket resources follow this hierarchy:
Workspace (e.g., "hudle")
├── Project (e.g., "PROJ")
│ └── Repository (e.g., "backend-api")
│ ├── Pull Requests
│ ├── Issues
│ ├── Pipelines
│ └── Branches
└── Snippets (workspace-level code snippets)
Understanding this hierarchy is essential:
- Workspace: Top-level container (like a GitHub organization)
- Project: Optional grouping of repositories within a workspace
- Repository: A git repository, always belongs to a workspace
Repositories are identified in two ways:
-
Explicit:
workspace/repo-nameformatbb pr list --repo hudle/backend-api
-
Implicit: Detected from current git directory's remote
cd ~/projects/backend-api bb pr list # auto-detects from git remote
-
Default workspace: If a default workspace is configured, you can use just the repo name
bb workspace set-default hudle bb pr list --repo backend-api # resolves to hudle/backend-api
Most commands support two output formats:
- Human-readable (default): Formatted tables for terminal display
- JSON (
--jsonflag): Structured output for programmatic parsing
For programmatic use, always prefer --json output:
bb pr list --json
bb repo list --workspace myworkspace --jsonBefore performing any operations, verify authentication:
bb auth statusExpected output when authenticated:
bitbucket.org
✓ Logged in to bitbucket.org account username (keyring)
- Active account: true
- Git operations protocol: ssh
- Token: ATAT****...****
If not authenticated, the output will indicate no active account.
Atlassian API tokens are the simplest method, especially for automation:
bb auth login
# Select "API Token" when prompted
# Enter your Atlassian account email
# Paste your API token from https://id.atlassian.com/manage-profile/security/api-tokensOAuth is browser-based and supports automatic token refresh:
bb auth login
# Select "OAuth" when prompted
# Complete browser-based authorizationFor automated environments, set credentials via environment variables:
| Variable | Description |
|---|---|
BB_TOKEN |
API token or OAuth access token |
BB_USERNAME |
Atlassian account email (for API token auth) |
Example CI/CD setup:
export BB_USERNAME="ci-bot@company.com"
export BB_TOKEN="ATATT3xFfGF0..."
bb pr list --repo myworkspace/myrepoThe CLI checks for credentials in this order:
- Environment variables (
BB_TOKEN,BB_USERNAME) - System keyring (stored by
bb auth login) - Config file credentials
If authentication expires or becomes invalid:
bb auth logout
bb auth login# List workspaces you have access to
bb workspace list
# View workspace details
bb workspace view <workspace>
# List workspace members
bb workspace members <workspace>
# Set default workspace (eliminates need for --workspace flag)
bb workspace set-default <workspace>
# Show current default workspace
bb workspace set-default# List repositories in a workspace
bb repo list --workspace <workspace>
bb repo list # uses default workspace
# View repository details
bb repo view <workspace/repo>
bb repo view # uses current git directory
# Clone a repository
bb repo clone <workspace/repo> [directory]
# Create a new repository
bb repo create --name <name> --workspace <workspace>
bb repo create --name <name> # uses default workspace
# Delete a repository (requires confirmation)
bb repo delete <workspace/repo>
# Fork a repository
bb repo fork <workspace/repo> --workspace <destination-workspace>
# Sync fork with upstream
bb repo sync# List pull requests
bb pr list --repo <workspace/repo>
bb pr list --state open|merged|declined|superseded
bb pr list # uses current git directory
# View pull request details
bb pr view <number> --repo <workspace/repo>
bb pr view <number> # uses current git directory
# Create a pull request
bb pr create --title "Title" --source <branch> --destination <branch>
bb pr create # interactive mode
# Edit a pull request
bb pr edit <number> --title "New Title"
# Merge a pull request
bb pr merge <number>
bb pr merge <number> --strategy squash|merge-commit|fast-forward
# Close/decline a pull request
bb pr close <number>
# Reopen a declined pull request
bb pr reopen <number>
# Checkout PR branch locally
bb pr checkout <number>
# View PR diff
bb pr diff <number>
# Check PR pipeline status
bb pr checks <number>
# Add comment to PR
bb pr comment <number> --body "Comment text"
# Review a PR (approve/request-changes/unapprove)
bb pr review <number> --approve
bb pr review <number> --request-changes --body "Please fix..."# List pipelines
bb pipeline list --repo <workspace/repo>
# View pipeline details
bb pipeline view <pipeline-id>
# Run a pipeline
bb pipeline run --branch <branch>
bb pipeline run --branch <branch> --custom <pipeline-name>
# Stop a running pipeline
bb pipeline stop <pipeline-id>
# View pipeline step details
bb pipeline steps <pipeline-id>
# View pipeline logs
bb pipeline logs <pipeline-id>
bb pipeline logs <pipeline-id> --step <step-uuid># List issues
bb issue list --repo <workspace/repo>
bb issue list --state open|closed|new|on-hold
# View issue details
bb issue view <issue-id>
# Create an issue
bb issue create --title "Title" --kind bug|enhancement|proposal|task
bb issue create --title "Title" --priority trivial|minor|major|critical|blocker
# Edit an issue
bb issue edit <issue-id> --title "New Title"
bb issue edit <issue-id> --assignee <username>
# Close an issue
bb issue close <issue-id>
# Reopen an issue
bb issue reopen <issue-id>
# Delete an issue
bb issue delete <issue-id>
# Comment on an issue
bb issue comment <issue-id> --body "Comment text"# List branches
bb branch list --repo <workspace/repo>
# Create a branch
bb branch create <branch-name> --target <base-branch>
# Delete a branch
bb branch delete <branch-name># List projects in a workspace
bb project list --workspace <workspace>
# View project details
bb project view <project-key> --workspace <workspace>
# Create a project
bb project create --key <KEY> --name "Project Name" --workspace <workspace># List snippets
bb snippet list --workspace <workspace>
# View a snippet
bb snippet view <snippet-id> --workspace <workspace>
# Create a snippet
bb snippet create --title "Title" --file <path> --workspace <workspace>
# Edit a snippet
bb snippet edit <snippet-id> --title "New Title" --workspace <workspace>
# Delete a snippet
bb snippet delete <snippet-id> --workspace <workspace># Open repository in browser
bb browse
bb browse --repo <workspace/repo>
# Raw API requests
bb api <endpoint>
bb api /repositories/workspace/repo
bb api /user
# Configuration
bb config list
bb config get <key>
bb config set <key> <value>Error: not logged in to any Bitbucket account
Cause: No authentication credentials found. Recovery:
bb auth loginAPI error 401: Token is invalid, expired, or not supported for this endpoint.
Cause: Authentication token has expired or is invalid. Recovery:
bb auth logout
bb auth loginError: authentication failed
Cause: Invalid credentials or token. Recovery:
- Verify your API token is correct
- Check if token has been revoked at https://id.atlassian.com/manage-profile/security/api-tokens
- Re-authenticate with
bb auth login
API error 403: You do not have access to view this workspace.
Cause: Insufficient permissions for the requested operation. This often occurs when trying to create/delete resources in a workspace where you only have read access. Recovery:
- Check your role in the workspace:
bb workspace list
- If you're a "member", you may need "contributor" or "admin" role for write operations
- Contact a workspace admin to request elevated permissions
API error 404: Repository not found
Cause: You don't have access to this private repository, or the workspace/repo name is incorrect. Recovery:
- Verify the repository name and workspace:
bb repo list --workspace <workspace>
- Check if you have access to the repository
- Verify spelling of workspace and repository names
Error: invalid repository format: myrepo (expected workspace/repo)
Cause: Repository specified without workspace, and no default workspace is configured. Recovery:
# Option 1: Use full format
bb pr list --repo workspace/myrepo
# Option 2: Set a default workspace
bb workspace set-default <workspace>
bb pr list --repo myrepoError: could not detect repository: not a git repository
Cause: Command run outside a git repository and no --repo flag provided.
Recovery:
# Option 1: Specify repository explicitly
bb pr list --repo workspace/repo
# Option 2: Navigate to a git repository
cd /path/to/repo
bb pr listAPI error 429: Rate limit exceeded
Cause: Too many API requests in a short period. Recovery:
- Wait a few minutes before retrying
- Reduce frequency of API calls
- Use
--jsonoutput and cache results when possible
API error 404: Pipeline not found
Cause: The pipeline ID doesn't exist or has been deleted. Recovery:
# List available pipelines
bb pipeline list --repo workspace/repoError: cannot run pipeline: no bitbucket-pipelines.yml found
Cause: Repository doesn't have pipelines configured. Recovery:
- Ensure
bitbucket-pipelines.ymlexists in the repository root - Verify pipelines are enabled in repository settings
Before performing any operations, check authentication status:
bb auth statusIf not authenticated, handle gracefully by informing the user or attempting to authenticate if credentials are available.
While auto-detection from git remotes is convenient, explicit references are more reliable:
# Prefer explicit
bb pr list --repo workspace/repo
# Over implicit (may fail if not in git directory)
bb pr listWhen performing multiple operations on the same workspace:
bb workspace set-default myworkspace
# Subsequent commands don't need --workspace
bb repo list
bb project listAlways use --json flag when you need to process command output:
bb pr list --json
bb repo view workspace/repo --jsonBefore delete or merge operations, verify the resource exists:
# Check PR exists and is open before merging
bb pr view 123 --json
# Then merge
bb pr merge 123Parse error messages to determine the appropriate recovery action:
- 401 errors: Re-authenticate
- 403 errors: Permission issue - inform user
- 404 errors: Resource not found - verify names
- 429 errors: Rate limited - wait and retry
For automated scripts and CI/CD, use flags that avoid interactive prompts:
# Force flag for destructive operations
bb repo delete workspace/repo --force
bb snippet delete abc123 --workspace ws --force
# Specify all required information via flags
bb pr create --title "Title" --source feature --destination main --body "Description"Bitbucket has API rate limits. When making multiple requests:
- Add small delays between requests if making many calls
- Cache responses when appropriate
- Use list commands with
--limitto reduce data transfer
Before running commands, validate that required information is available:
- Workspace name is valid
- Repository exists
- PR/Issue numbers are numeric
- Branch names are valid
When using bb as part of a larger workflow, capture and relay command output to provide clear feedback about what operations were performed and their results.
~/.config/bb/config.yml
| Setting | Description | Default |
|---|---|---|
git_protocol |
Protocol for git operations (ssh or https) |
ssh |
editor |
Editor for interactive input | $EDITOR or vim |
prompt |
Enable/disable prompts | enabled |
pager |
Pager for long output | $PAGER or less |
browser |
Browser for web commands | system default |
http_timeout |
API request timeout (seconds) | 30 |
default_workspace |
Default workspace for commands | none |
bb config set git_protocol https
bb config set default_workspace myworkspace
bb config get default_workspace
bb config list# Show version
bb --version
# Show help
bb --help
bb <command> --help
bb <command> <subcommand> --help