AI Agent Integration
AI coding assistants can use the Bitbucket CLI to manage pull requests and repositories through natural conversation. Simply ask “Create a PR for this branch” and the AI handles the rest.
Benefits
Section titled “Benefits”- Natural language - No need to memorize command flags
- Intelligent chaining - AI chains commands automatically
- Team consistency - Encode conventions for everyone
- Faster workflows - “Approve and merge PR 42” in one sentence
Choose your AI agent:
-
Create the skill directory:
Terminal window mkdir -p .claude/skills/bb-cli -
Create the skill file at
.claude/skills/bb-cli/SKILL.md:---name: bb-clidescription: Execute Bitbucket Cloud CLI commands using `bb`. Use when creating, listing, editing, or managing pull requests, repositories, authentication, or configuration.allowed-tools: Bash(bb:*), Read, Grep, Glob---# Bitbucket CLI (`bb`)Command-line interface for Bitbucket Cloud (@pilatos/bitbucket-cli).## Quick Start```bashbb auth status # Check authenticationbb pr list # List open PRsbb pr create -t "..." # Create PR from current branch```## Requirements- Bun runtime 1.0+ installed (https://bun.sh)- `npm install -g @pilatos/bitbucket-cli` (or bun/pnpm)- Authenticated via `bb auth login` (env vars supported during login)- Run from git repo with Bitbucket remote## CommandsSee the full command reference in the skill file or run `bb --help`.**Key commands:**- `bb pr create/list/view/diff/checkout/approve/merge/decline/ready/comments`- `bb repo clone/create/list/view/delete`- `bb auth login/logout/status/token`- `bb config get/set/list`## Workflows**Create PR:**```bashgit add . && git commit -m "feat: description"git push -u origin feature-branchbb pr create -t "feat: description" -b "Details"```**Review and Merge:**```bashbb pr checkout 42bb pr diff 42bb pr approve 42bb pr merge 42 --strategy squash --close-source-branch```**Draft PR:**```bashbb pr create -t "WIP" --draftbb pr ready 42 # Mark as ready later```## Tips- Context auto-detection: run from git repo with Bitbucket remote- JSON output: all commands support `--json`- Error codes: 0=success, 1xxx=auth, 2xxx=API, 3xxx=git, 4xxx=config, 5xxx=validation, 6xxx=context, 7xxx=network -
Restart Claude Code to load the skill
-
Test it: Ask “List open PRs in this repo”
-
Create
AGENTS.mdin your project root if it doesn’t exist -
Add the bb-cli section to
AGENTS.md:## Bitbucket CLI (bb)Use `bb` (@pilatos/bitbucket-cli) for Bitbucket operations.### Installation```bash# Requires Bun runtime (https://bun.sh)npm install -g @pilatos/bitbucket-clibb auth login```### Common Commands**Pull Requests:**- `bb pr list` - List open PRs- `bb pr create -t "title"` - Create PR from current branch- `bb pr view <id>` - View PR details- `bb pr diff <id>` - View diff- `bb pr checkout <id>` - Checkout locally- `bb pr approve <id>` - Approve PR- `bb pr merge <id>` - Merge PR- `bb pr ready <id>` - Mark draft as ready- `bb pr comments add <id> "text"` - Add comment**Repositories:**- `bb repo list -w workspace` - List repos- `bb repo clone workspace/repo` - Clone**Configuration:**- `bb config set defaultWorkspace myworkspace`### Tips1. Requires Bun runtime 1.0+ to execute2. Auto-detection works when in a git repo with Bitbucket remote3. Use `--json` for machine-readable output4. Squash merge: `bb pr merge <id> --strategy squash`5. Delete source branch: `--close-source-branch`### Workflows**Create PR:**```bashgit add . && git commit -m "feat: desc"git push -u origin feature-branchbb pr create -t "feat: desc" -b "Details"```**Review and Merge:**```bashbb pr checkout 42bb pr approve 42bb pr merge 42 --strategy squash --close-source-branch``` -
Run opencode in your project directory
-
Test it: Ask “What’s the status of my PRs?”
-
Create
.cursorrulesin your project root:## Bitbucket CLI (bb)Use `bb` (@pilatos/bitbucket-cli) for Bitbucket operations.**Key Commands:**- `bb pr create/list/view/diff/checkout/approve/merge/decline/ready/comments`- `bb repo list/clone/view`- `bb config get/set/list`- `bb auth login/status`**Context:** Auto-detects workspace/repo from git remotes. Use `-w/-r` to override.**Output:** Use `--json` for machine-readable output.**Auth:** Requires `bb auth login` (which can use `BB_USERNAME` + `BB_API_TOKEN`).**Workflows:**- Create: Push branch → `bb pr create -t "title" -b "body"`- Review: `bb pr checkout <id>` → review → `bb pr approve <id>` → `bb pr merge <id> --strategy squash` -
Open Cursor in the project
-
Use Composer or Chat with bb commands
-
Test it: Ask “Create a PR for my current changes”
Example Conversations
Section titled “Example Conversations”Creating a PR:
You: Create a PR for my current branch titled "Add user validation"AI: [Runs: bb pr create -t "Add user validation"] ✅ Created PR #42 https://bitbucket.org/workspace/repo/pull-requests/42Checking Open PRs:
You: What PRs need my review?AI: [Runs: bb pr list --json] Found 3 open PRs: • #42 - Add user validation (by john, 2 hours ago) • #41 - Fix login bug (by jane, 1 day ago) • #40 - Update dependencies (by bot, 3 days ago)Review Workflow:
You: Review PR 42 and approve it if it looks goodAI: [Runs: bb pr view 42, bb pr diff 42] Changes look good. Approving... [Runs: bb pr approve 42] ✅ Approved PR #42.Draft PRs:
You: Create a draft PR for my WIPAI: [Runs: bb pr create -t "WIP: Feature" --draft] ✅ Created draft PR #43
You: Mark it ready for reviewAI: [Runs: bb pr ready 43] ✅ Marked PR #43 as ready for reviewTeam Conventions
Section titled “Team Conventions”Add team-specific rules to your AI instructions:
### Branch Naming- Features: `feat/<ticket>-<description>`- Bugs: `fix/<ticket>-<description>`- Hotfixes: `hotfix/<description>`
### PR Requirements- All PRs need one approval- Use draft PRs for work-in-progress- Always squash merge features: `--strategy squash`- Always delete source branches: `--close-source-branch`
### Review Process1. bb pr checkout <id>2. Review changes with bb pr diff <id>3. bb pr approve <id>4. bb pr merge <id> --strategy squash --close-source-branchThis ensures everyone follows the same workflow automatically.
Security
Section titled “Security”export BB_USERNAME=your-usernameexport BB_API_TOKEN=your-api-tokenFor Claude Code, limit permissions in the skill:
allowed-tools: Bash(bb:*), Read, Grep, Glob # Good - only bb commandsTroubleshooting
Section titled “Troubleshooting”| Issue | Solution |
|---|---|
| ”Not authenticated” | Set BB_USERNAME and BB_API_TOKEN, then run bb auth login |
| Commands still prompting | Claude Code: check allowed-tools includes Bash(bb:*) |
| ”Could not determine repo” | Run from git repo with Bitbucket remote, or use -w/-r flags |
| AI using wrong syntax | Add more examples to your skill/instructions |
| opencode not finding commands | Ensure bb CLI is installed and in PATH |
Related Guides
Section titled “Related Guides”- Scripting & Automation
- CI/CD Integration
- JSON Output
- Error Codes
- Command Reference - Full PR command documentation