Agent skill
skills/bitbucket-cli/SKILL.md
is an agent skill that teaches AI coding agents to use bb safely. It adds no commands; it
documents how an agent should use the ones in this book.
Install for Claude Code
From a clone of the repository:
ln -s "$PWD/skills/bitbucket-cli" ~/.claude/skills/bitbucket-cli
The skill triggers when the git remote is bitbucket.org, or the user mentions Bitbucket, a
Bitbucket PR, or Pipelines. It is not for GitHub (gh) or Bitbucket Server/Data Center.
What it teaches
- Read with
--json, parse withjq. Human tables can change; the JSON is the API’s. - Reads are free; writes need the user’s go-ahead. Create, merge, close, approve, review,
comment, pipeline run/cancel, repo create/delete and non-GET
bb apicalls only when the user asked for that action on that object. - Name the PR by id for every write. A branch (or no argument) resolves to the open PR for that branch, else the most recently updated PR of any state, possibly an old merged one.
- Match branches exactly, and confirm a list result with
bb pr view ID --jsonbefore acting on it:pr listcan lag for a while after a write. - Never prompt or open a browser: no
bb auth login,-w/--weborbb browsefrom an agent; pass bodies with-bor-F. - Use
-L 0when completeness matters. - Keep secrets out of output: never
bb auth tokenorbb auth status -t. - Check exit codes 1, 2, 4 and 8 (see exit codes).
Recipes
The skill’s workflows are shell functions, each in a bash block starting with # recipe: NAME:
| Recipe | What it does |
|---|---|
bb_pr_is_open ID BRANCH [BASE] | Exit 0 if pr view says the PR is open, from BRANCH (into BASE) |
bb_pr_for_branch BRANCH [BASE] | Print the id of the one open PR from BRANCH; fail rather than guess |
bb_checks_state ID [--watch] | Print passing, failing, pending or none |
bb_pr_summary ID | Read-only summary: state, branches, approvals, change requests, checks |
bb_failed_logs BRANCH | Failed steps’ logs of the branch’s latest pipeline |
bb_ensure_pr HEAD BASE TITLE [BODY] | Reuse an open PR or create one (after a dry run); print its URL |
bb_upsert_comment ID MARKER BODY | Post or update the agent’s own marked status comment |
bb_safe_merge ID STRATEGY [--allow-no-checks] | Merge only if open, not a draft, no change requests, checks passed |
How it is tested
tests/skill/run.sh(run bycargo test; needsjq) extracts the recipe blocks from SKILL.md, runs them against a mockbb(tests/skill/mock-bb) with a fixture, asserts they pick the right PR and make only the expected writes, then replays each command line against the realbbto catch flags that no longer exist.scripts/skill-e2e.shruns the same recipes against a throwaway repository on Bitbucket.scripts/skill-eval.shtests the agent: it givesclaude -prealistic requests in a scratch checkout wherebbis the mock, and scores whether the right PR was used and only the expected writes were made. It costs API usage and is run by hand.
The skill is part of bb’s interface: a change to a command, flag, default, --json shape, exit
code or PR resolution rule that the skill mentions updates SKILL.md (and the mock) in the same
change.