blog

I built an AI pull-request review bot for Bitbucket with Claude

Anthropic's managed Code Review is GitHub-only. Here's how to build a Bitbucket Pipelines bot that reviews every pull request with the Claude API, what it costs, and the traps to avoid.

6 min read

  • #AI
  • #code review
  • #Bitbucket
  • #Claude

Short answer: an AI review bot for Bitbucket is a single Bitbucket Pipelines step that runs on every pull request, fetches the diff from the Bitbucket API, sends it to Claude, and posts the findings back as inline PR comments. The whole script is about fifty lines, and reviewing a typical PR with Sonnet costs a few cents.

Why build your own? Because Anthropic’s managed Code Review still only works with GitHub, and the official CI guides cover GitHub Actions and GitLab — not Bitbucket. There’s an open feature request on the Claude Code repo for Bitbucket Pipelines support, but if your team lives in the Atlassian stack, you don’t have to wait for it.

What are your options for AI code review on Bitbucket?

There are three realistic paths:

Option How it works Pros Cons
Atlassian Code Reviewer (formerly Rovo Dev code review) built into Bitbucket Cloud zero setup uses Rovo credits, less control over rules
Claude Code in Pipelines (claude -p) the full agent runs in a CI step sees the whole repo, not just the diff slower and pricier per PR
Your own script + Claude API diff → model → comments full control, cheapest you maintain it

Atlassian’s Code Reviewer now ships with paid Jira subscriptions, and Rovo credit billing starts on December 3, 2026. Credits come from a shared org-wide pool and usage scales with PR size and how often reviews run. If that works for your team, use it.

I went with option three because I want to know exactly which rules the model gets and what each review costs.

What does the architecture look like?

Four steps — no server, no webhook receiver:

  1. Trigger. Bitbucket Pipelines has a dedicated pull-requests section that runs when a PR is opened and on every push to its source branch.
  2. Diff. The script pulls the diff from the Bitbucket Cloud REST API (/pullrequests/{id}/diff).
  3. Model. The diff goes to Claude together with a system prompt containing your team’s rules. The model returns a JSON list of findings.
  4. Comments. Each finding becomes an inline comment on the right line via /pullrequests/{id}/comments with an inline object.

Pipelines already exposes BITBUCKET_WORKSPACE, BITBUCKET_REPO_SLUG and BITBUCKET_PR_ID, so the script knows which PR it’s looking at.

How do you set up Bitbucket Pipelines?

Add this to bitbucket-pipelines.yml:

pipelines:
  pull-requests:
    '**':
      - step:
          name: AI review
          image: node:22
          script:
            - npm install @anthropic-ai/sdk
            - node scripts/ai-review.mjs

Then add two secured repository variables: ANTHROPIC_API_KEY and BB_TOKEN.

One thing that breaks a lot of older tutorials: Bitbucket Cloud has retired app passwords. New ones couldn’t be created after September 2025, and since June 9, 2026 only tokens work. For a bot, a repository access token with repository read and pull request write permissions is the cleanest choice — comments show up under the token’s identity instead of yours.

What does the review script look like?

A trimmed-down version that shows the idea:

// scripts/ai-review.mjs
import Anthropic from '@anthropic-ai/sdk';

const { BITBUCKET_WORKSPACE: ws, BITBUCKET_REPO_SLUG: repo, BITBUCKET_PR_ID: pr, BB_TOKEN } = process.env;
const api = `https://api.bitbucket.org/2.0/repositories/${ws}/${repo}/pullrequests/${pr}`;
const headers = { Authorization: `Bearer ${BB_TOKEN}`, 'Content-Type': 'application/json' };

const diff = await (await fetch(`${api}/diff`, { headers })).text();
if (diff.length > 200_000) process.exit(0); // huge PR — skip

const claude = new Anthropic(); // reads ANTHROPIC_API_KEY
const res = await claude.messages.create({
  model: 'claude-sonnet-5-5',
  max_tokens: 4000,
  system: `You are a senior frontend reviewer (React, TypeScript).
Report only real bugs, security issues and logic errors. No style nitpicks.
Return only a JSON array: [{"path": "src/...", "line": 12, "comment": "..."}]. Return [] if nothing is wrong.`,
  messages: [{ role: 'user', content: diff }],
});

const findings = JSON.parse(res.content[0].text);
for (const f of findings.slice(0, 10)) {
  await fetch(`${api}/comments`, {
    method: 'POST',
    headers,
    body: JSON.stringify({
      content: { raw: `**AI review:** ${f.comment}` },
      inline: { path: f.path, to: f.line },
    }),
  });
}

Three deliberate choices:

  • A cap of 10 comments. Nobody reads a bot that leaves forty.
  • “No style” rule. Prettier and ESLint already handle formatting. The model should look for what linters can’t see.
  • Skipping huge PRs. Generated files and lockfiles burn tokens for nothing — better still, strip them from the diff before sending.

For production, swap JSON.parse for structured output via tool use. Models occasionally wrap JSON in a Markdown fence, and the parse fails.

How much does AI code review cost per pull request?

From the official pricing page: Claude Sonnet 5.5 is $2 per million input tokens and $10 per million output tokens; Haiku 5.5 is $0.10 / $0.50 (for prompts up to 100K tokens). For a typical PR with ~20K tokens of diff and ~2K tokens of output:

Model Cost per review (approx.) 500 PRs / month
Haiku 5.5 ~$0.003 ~$1.50
Sonnet 5.5 ~$0.06 ~$30
Opus 5.5 ~$0.12 ~$60

Treat these as orders of magnitude — big PRs and long system prompts push them up. A good setup is Haiku for a quick pass on every push and Sonnet only once the PR is marked ready for review. Since the system prompt repeats on every call, prompt caching cuts the cost further.

What does AI review catch, and what does it miss?

In my work on React and TypeScript projects, AI review earns its keep on the things tired humans skip: a missing await, a useEffect with the wrong dependencies, an unhandled API error, a secret that slipped into a commit. It’s weaker at judging architecture or business logic — it doesn’t know why the team chose a particular approach.

So I treat it as a fast first reviewer, not a replacement for a teammate. Same rule as in my post on how I use Claude Code day to day: the AI proposes, a human decides.

What should you watch out for?

  • Duplicate comments. Pipelines runs on every push, so the bot can repeat itself. Fetch existing comments first and skip findings it has already posted.
  • Client code and data. The diff is sent to the Anthropic API. Check that your client contracts allow it.
  • Rules as a file. Keep the system prompt in the repo (e.g. REVIEW.md) so the team can change review rules through a PR.
  • Off-the-shelf tools. If you don’t need full control, Claude Code’s official code review plugins can run locally before you even push.

FAQ

Does Claude Code officially support Bitbucket? Not like GitHub. Managed Code Review is GitHub-only, and CI guides exist for GitHub Actions and GitLab. On Bitbucket you can run Claude Code in a Pipelines step with claude -p, or call the API directly as shown here.

Does this work with Bitbucket Data Center? The idea is the same, but the REST API differs (different URLs and inline comment format), and you’d typically run it from Jenkins or Bamboo instead of Pipelines.

Which model should I use? Start with Sonnet 5.5 for the best quality-to-cost ratio. Haiku 5.5 is great for cheap, fast checks; Opus is worth it only for critical code paths.

Should the bot approve or block PRs? It can via the API, but I wouldn’t. Let it comment; keep the merge decision human.


The code for my experiments lives on GitHub, and I share what actually works with AI tooling on LinkedIn. If your team needs help setting up something like this — or you need a fast, modern website — get in touch via website development.