> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coderabbit.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Bitbucket Cloud

> Set up CodeRabbit for Bitbucket Cloud with a service account and a scoped Atlassian API token, install it on repositories, and fix common problems.

Bitbucket (This feature is available on Bitbucket.)

CodeRabbit reviews Bitbucket Cloud pull requests through a service account: an Atlassian account whose API token you save in CodeRabbit. A webhook on each installed repository tells CodeRabbit when a pull request is opened, updated, or commented on. For self-hosted Bitbucket, see [Bitbucket Data Center](https://docs.coderabbit.ai/platforms/bitbucket-data-center.md).

## Before you begin

Setup has four parts:

1. [Create the service account](#create-the-service-account).
2. [Create its API token](#create-the-api-token).
3. [Sign in and connect your workspace](#connect-your-workspace).
4. [Install on repositories and test](#install-coderabbit-on-repositories).

| Who | Needs | Role in setup |
| - | - | - |
| Workspace admin | Administrator of the Bitbucket workspace | Saves the service account's email and API token in CodeRabbit. Only workspace admins can. |
| Installer | **Admin** permission on each repository to install | Clicks **Install**. CodeRabbit creates the repository webhooks with this person's Bitbucket login. |
| Service account | Membership in the workspace, and **Write** access to the repositories CodeRabbit reviews | Owns the API token. CodeRabbit acts in Bitbucket as this account. |

One person can fill both admin roles. Bitbucket workspace admins become CodeRabbit [admins](https://docs.coderabbit.ai/management/roles.md), and other workspace members become CodeRabbit members.

**Cost:** the service account is a member of your workspace, so Bitbucket counts it as a billable user. On the Bitbucket Free plan, it counts toward the 5-user limit. It doesn't need a CodeRabbit seat.

If your organization uses CodeRabbit's EU instance, use `app.eu.coderabbit.ai` wherever this page says `app.coderabbit.ai`.

When you finish, you have:

* A service account whose Atlassian email, account UUID, and API token CodeRabbit stores, with the token encrypted. CodeRabbit uses them to read pull requests and post reviews.
* A CodeRabbit [webhook](#webhooks) on each installed repository.
* CodeRabbit reviews on new and updated pull requests in those repositories.

## Create the service account

CodeRabbit accepts an API token from any Atlassian account, but a dedicated account avoids two problems:

* CodeRabbit posts reviews, comments, and approvals as the token's owner. With a personal token, they appear under that person's name.
* CodeRabbit doesn't review pull requests opened by the account whose token is saved, and says "This PR was authored by the user configured for CodeRabbit reviews." With a personal token, that person's pull requests are never reviewed.

**1. Create an Atlassian account**

Sign up for a new Atlassian account with an email address your team controls, such as a shared mailbox. Pick a display name your team will recognize on review comments.

**2. Add the account to your workspace**

Invite the account to your Bitbucket workspace ([Atlassian's guide](https://support.atlassian.com/bitbucket-cloud/docs/grant-access-to-a-workspace/)) and give it **Write** access to the repositories CodeRabbit should review. Read access is enough for review comments and approvals, but features that push commits or branches need Write, such as [Fix comments](https://docs.coderabbit.ai/finishing-touches/autofix.md), committing changes CodeRabbit prepares in chat, and security fixes.

If your workspace enforces two-step verification, a Bitbucket Premium feature, API calls made with the token don't prompt for it.

## Create the API token

**1. Sign in as the service account**

Sign in to Atlassian as the service account, not as yourself. A private browser window keeps the two sessions apart.

**2. Start a scoped token**

Open [API tokens](https://id.atlassian.com/manage-profile/security/api-tokens) and select **Create API token with scopes**. Tokens created without scopes don't work with Bitbucket.

**3. Name the token and set an expiry date**

Enter a name, such as `CodeRabbit`, and an expiry date between 1 and 365 days away. CodeRabbit can't use an expired token and doesn't warn you in advance, so note the date and [replace the token](#replace-the-token-or-service-account) before then.

**4. Select Bitbucket**

Select **Bitbucket** as the app.

**5. Select the scopes**

Select all scopes marked **Yes** in [Scopes](#scopes), plus `write:repository:bitbucket` unless you don't want CodeRabbit to push commits. Select each one explicitly: a write scope doesn't include the matching read scope.

**6. Create and copy the token**

Create the token and copy it right away. Atlassian shows it only once.

### Scopes

CodeRabbit refuses to save a token that lacks any required scope.

| Scope | Required | What it allows |
| - | - | - |
| `read:repository:bitbucket` | Yes | Read code, diffs, and commits, and clone the repository |
| `write:repository:bitbucket` | Recommended | Push commits and branches |
| `read:pullrequest:bitbucket` | Yes | Read pull requests and their comments |
| `write:pullrequest:bitbucket` | Yes | Post reviews, approve or request changes, and open pull requests |
| `read:workspace:bitbucket` | Yes | Read workspace members and permissions, for example to check a comment author's access |
| `read:user:bitbucket` | Yes | Read the service account's own profile, so CodeRabbit can identify it |
| `read:pipeline:bitbucket` | Yes | Read Bitbucket Pipelines runs, steps, and logs, used as context for CI failures |
| `read:runner:bitbucket` | Yes | Read Bitbucket Pipelines runner information |
| `read:issue:bitbucket` | Yes | Read Bitbucket issues, such as issues linked to a pull request |
| `write:issue:bitbucket` | Yes | Create and update Bitbucket issues |

CodeRabbit saves a token without `write:repository:bitbucket`, but then features that push commits or branches fail, such as [Fix comments](https://docs.coderabbit.ai/finishing-touches/autofix.md), committing changes CodeRabbit prepares in chat, and security fixes.

Don't add scopes that aren't in this table. CodeRabbit doesn't need them.

## Connect your workspace

**1. Sign in with Bitbucket Cloud**

Go to the [CodeRabbit login page](https://app.coderabbit.ai/login) and select **Bitbucket Cloud**. Sign in as yourself, the workspace admin, not as the service account. Bitbucket asks you to authorize CodeRabbit (OAuth 2.0) and then returns you to CodeRabbit.

**2. Select your workspace**

Pick the Bitbucket workspace to connect. Workspaces already connected to CodeRabbit appear disabled.

**3. Save the service account credentials**

In **Username / Email**, enter the service account's Atlassian account email. In **API Token**, paste the token. CodeRabbit verifies the pair and the token's scopes before saving. If saving fails, see [Troubleshooting](#troubleshooting).

CodeRabbit skips this step when the workspace already has saved credentials.

## Install CodeRabbit on repositories

The onboarding wizard continues with this step. To add repositories later, use the [Repositories](https://app.coderabbit.ai/settings/repositories) page.

**1. Select repositories**

Select the repositories CodeRabbit should review.

**2. Install**

Click **Install**. CodeRabbit adds a [webhook](#webhooks) to each selected repository. If no credentials are saved yet, first click **Installation Guide** on the **Repositories** page, enter the service account's **Atlassian Email** and **API Token** in the **Bitbucket Cloud** dialog, and click **Submit**.

**3. Open a test pull request**

Open a pull request in an installed repository. CodeRabbit posts a review on it as the service account.

To remove CodeRabbit from repositories, select them on the **Repositories** page and click **Uninstall**. CodeRabbit deletes each repository's webhook and its stored webhook secret, using your Bitbucket login.

## Talk to CodeRabbit in pull requests

To talk to CodeRabbit in a pull request comment, mention `@coderabbitai`, `@coderabbit`, or the service account. Bitbucket's mention autocomplete works too. See [Manage code reviews](https://docs.coderabbit.ai/guides/commands.md) for the commands.

## Replace the token or service account

The saved credentials are on the [Bitbucket user](https://app.coderabbit.ai/settings/bitbucket-user) page (**Account → Bitbucket user**) in CodeRabbit. The page shows **Organization user (User ID: …)**, where the ID is the account's Bitbucket UUID (the `uuid` field returned by `GET https://api.bitbucket.org/2.0/user`), not its username.

To replace an expiring token, or to switch CodeRabbit to a different account:

**1. Create a new token**

Create a token for the account CodeRabbit should use, with the same scopes. See [Create the API token](#create-the-api-token).

**2. Save it in CodeRabbit**

On the **Bitbucket user** page, enter the account's **Atlassian Email** and the new **API Token**, and save.

**3. Revoke the old token**

Signed in to Atlassian as the old token's owner, revoke it on the [API tokens](https://id.atlassian.com/manage-profile/security/api-tokens) page.

Webhooks don't need any change: they were created with the installer's Bitbucket login and are authenticated by their secret, not by the service account. After a switch, CodeRabbit posts new reviews as the new account.

## Webhooks

**Install** adds one webhook per repository with the URL `https://app.coderabbit.ai/handleBitbucket` and a random secret for that repository. Installing again after **Uninstall** replaces any webhook with that URL instead of adding a second one.

Bitbucket signs each delivery with the webhook's secret, using HMAC-SHA256 in the `X-Hub-Signature` header. CodeRabbit verifies the signature with a constant-time comparison. It uses the repository's own secret if one is stored, and otherwise the organization secret saved on the [Webhook secret](https://app.coderabbit.ai/settings/webhook-secrets) page (**Account → Webhook secret**).

![Bitbucket repository webhook settings listing a webhook with the URL https://app.coderabbit.ai/handleBitbucket](https://mintcdn.com/coderabbit/69LGK0BhaHIxrC15/images/platforms/img/integrations/bitbucket-webhook.png?fit=max\&auto=format\&n=69LGK0BhaHIxrC15\&q=85\&s=d67b856fee17794a4cfe2bcd43c9e5d4)

A CodeRabbit webhook in a Bitbucket repository's webhook settings

**Install** subscribes each webhook to the events CodeRabbit needs, so most setups never need a webhook added by hand.

> [accordion] Add a webhook manually
>
> Add a webhook by hand only if you need to, for example when no repository admin can click **Install**. A repository installed with **Install** has its own random secret, which CodeRabbit checks instead of the organization secret. To use a known secret there, [rotate it](#rotate-the-webhook-secret) first: **Change secret** sets the new secret on every installed repository.
>
> **1. Copy the webhook URL**
>
> On the [Webhook secret](https://app.coderabbit.ai/settings/webhook-secrets) page, copy the **Webhook URL**. Only admins see this page.
>
> **2. Save the organization secret**
>
> Enter a secret and save it. If a secret already exists and you don't have it, set a new one with **Change secret**; see [Rotate the webhook secret](#rotate-the-webhook-secret).
>
> **3. Add the webhook in Bitbucket**
>
> In the repository, go to **Repository settings → Webhooks → Add webhook**. Only repository admins can add webhooks. Paste the URL, enter the same secret, and select the triggers in the table below.
>
> Reviews run on **Created** and **Updated**, and chat commands on **Comment created**, so those three are the minimum. Approvals, declines, merges, pushes, and build statuses feed [Triage](https://docs.coderabbit.ai/triage.md) and related features. Select all twelve to match **Install**.
>
> | Bitbucket trigger | Event key | Required |
> | - | - | - |
> | Pull Request **Created** | `pullrequest:created` | Yes |
> | Pull Request **Updated** | `pullrequest:updated` | Yes |
> | Pull Request **Comment created** | `pullrequest:comment_created` | Yes |
> | Pull Request **Comment updated** | `pullrequest:comment_updated` | Recommended |
> | Pull Request **Comment resolved** | `pullrequest:comment_resolved` | Recommended |
> | Pull Request **Approved** | `pullrequest:approved` | Recommended |
> | Pull Request **Approval removed** | `pullrequest:unapproved` | Recommended |
> | Pull Request **Declined** | `pullrequest:rejected` | Recommended |
> | Pull Request **Merged** | `pullrequest:fulfilled` | Recommended |
> | Repository **Push** | `repo:push` | Recommended |
> | Repository **Build status created** | `repo:commit_status_created` | Recommended |
> | Repository **Build status updated** | `repo:commit_status_updated` | Recommended |

### Rotate the webhook secret

On **Account → Webhook secret**, click **Change secret** and save the new secret. CodeRabbit then updates every webhook with the CodeRabbit URL on installed repositories, together with their stored secrets. It makes the changes with your Bitbucket login and reports how many repositories it updated and how many failed. For each failed repository, and for webhooks on repositories CodeRabbit hasn't installed, update the secret in Bitbucket under **Repository settings → Webhooks**.

## IP allowlist

If your workspace restricts access by IP address (**Workspace settings → Access Management → Access controls → Restrict access to certain IP addresses**, a Bitbucket Premium feature), add CodeRabbit's IP addresses there:

```text IPs to allow list theme={null}
35.222.179.152/32, 34.170.211.100/32, 136.113.208.247/32
```

## Troubleshooting

Most fixes below need a Bitbucket workspace admin, who is also a CodeRabbit admin. If onboarding shows **Admin Access Required**, ask one. Installing needs **Admin** permission on the repository. If one pull request wasn't reviewed for a reason unrelated to Bitbucket setup, such as its draft status, its target branch, or review seats, see [Automatic review controls](https://docs.coderabbit.ai/configuration/auto-review.md) and [Seat assignment](https://docs.coderabbit.ai/management/seat-assignment.md).

> [accordion] Credentials can't be saved
>
> | Message | Cause and fix |
> | - | - |
> | `Failed to verify Bitbucket credentials` | The email and token don't match, or the token expired or was revoked. Use the Atlassian account email of the account that owns the token, and a token created with **Create API token with scopes**. Bitbucket app passwords are no longer supported; an API token is required. |
> | `Token is missing necessary scope: <scope>` | Create a new token with every required scope in [Scopes](#scopes), and save it. |
> | `Failed to verify token scopes, try again` or `Failed to get user profile` | A temporary failure, not a credentials problem. Retry, and contact [support](https://docs.coderabbit.ai/support) if it persists. |
> | `Failed to save Bitbucket user details` | The **Bitbucket user** page shows only this generic message. Test the credentials as shown below. |
>
> To test an email and token outside CodeRabbit, run the request CodeRabbit makes, and enter the API token when curl asks for a password:
>
> ```bash theme={null}
> curl -u "coderabbit@example.com" https://api.bitbucket.org/2.0/user
> ```
>
> A JSON profile with a `uuid` field means the email and token work.

> [accordion] Install fails
>
> An error that includes `Give it admin access to the repository` or `Give that account admin access to the repository, and make sure its credential includes the webhook scope` means the account creating the webhook lacks **Admin** permission on that repository. CodeRabbit creates webhooks with the Bitbucket login of whoever clicks **Install**, so ask a repository admin to install it, or get **Admin** permission first.

> [accordion] Reviews stopped
>
> * **On every repository:** the service account's API token has most likely expired or been revoked. When Bitbucket rejects the token, the CodeRabbit app shows "Bitbucket needs its credentials updated." with a **Fix connection** link, and if it keeps failing, CodeRabbit emails a billing admin. Nothing is posted on pull requests. Create a new token and save it, as described in [Replace the token or service account](#replace-the-token-or-service-account).
> * **On one repository, or a new one:** check that the service account still has access to it. Then, in Bitbucket, check **Repository settings → Webhooks** for a webhook with the CodeRabbit URL. If it's missing, select the repository on the **Repositories** page and click **Uninstall**, then **Install**.
> * **After turning on IP allowlisting:** add CodeRabbit's addresses, as described in [IP allowlist](#ip-allowlist).

> [accordion] One person's pull requests are never reviewed
>
> CodeRabbit doesn't review pull requests opened by the account whose token is saved, and says "This PR was authored by the user configured for CodeRabbit reviews." If CodeRabbit's reviews appear under that person's name, the saved token is theirs. [Switch to a dedicated service account](#replace-the-token-or-service-account).

> [accordion] Webhook deliveries are rejected
>
> The secret on the Bitbucket webhook doesn't match the one CodeRabbit uses: the repository's own secret if one is stored, otherwise the organization secret on the **Webhook secret** page. For an installed repository, [rotate the webhook secret](#rotate-the-webhook-secret), which also updates webhooks you added by hand with the CodeRabbit URL, or click **Uninstall**, then **Install**. For a repository without its own secret, set the organization secret on the webhook in Bitbucket.

For anything else, contact [CodeRabbit support](https://docs.coderabbit.ai/support).

## What's next

> [card] [Configure CodeRabbit](https://docs.coderabbit.ai/getting-started/yaml-configuration.md)
>
> Tune how CodeRabbit reviews each repository with a `.coderabbit.yaml` file.

> [card] [Automatic review controls](https://docs.coderabbit.ai/configuration/auto-review.md)
>
> Choose which pull requests CodeRabbit reviews automatically, by target branch, draft status, label, or title.

> [card] [Manage code reviews](https://docs.coderabbit.ai/guides/commands.md)
>
> Pause, resume, or request reviews from pull request comments with `@coderabbitai` commands.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.