Connect Bitbucket Cloud to let an Agent inspect repositories, branches, commits, source files, pull requests, review comments, and pipeline results.
Agent Barn stores the credential as an encrypted Agent Secret, and exposes Bitbucket operations to the Agent through the built-in Bitbucket Skill and aai-cli.
What you will configure
- Bitbucket account
- Scoped API token
- Encrypted Agent Secret
- Bitbucket Skill
- aai-cli profile
Bitbucket account
│
├── Scoped API token
├── Workspace ID
└── Repository slugs
│
▼
Encrypted Agent Secret
│
▼
Built-in Bitbucket Skill
│
▼
aai-cli profile and commandsAt the end of this guide, the Agent will have:
- An encrypted
bitbucketcredential - The built-in Bitbucket Skill
- A generated
bitbucket-workprofile - Explicit access to the repositories allowed by the Bitbucket account and API token
- Commands for inspecting source, pull requests, branches, commits, and pipelines
Before you begin
You need:
- An Agent Barn Organization
- An existing Agent, or permission to hire one
- Permission to update the Agent and manage its Secrets
- A Bitbucket Cloud account with access to the intended repositories
- The workspace ID and repository slugs you want the Agent to use
- Permission to create an Atlassian API token
For a dedicated production Agent, use a dedicated Bitbucket account instead of a maintainer’s personal account. Grant that account access only to the repositories required by the Agent’s role.
Choose the authentication method
Use the credential pattern supported by the token you provision. Email plus an API token uses Basic authentication; workspace- and repository-scoped access tokens can use bearer authentication when the supplied token supports it.
A Basic-auth profile includes:
auth_type = "basic_api_token"
email = "agent@example.com"
api_token_secret = "bitbucket.api_token"This matches Bitbucket Cloud’s supported API-token authentication using an Atlassian account email and API token.
If an Agent Barn screen still refers to “App password scopes,” treat that wording as legacy UI copy. Supply a scoped Bitbucket API token.
The validator checks authentication and, where possible, configured repository and pull-request access. Relevant access includes account or user read access when required by the token type, repository read access, pull-request read access, and pull-request write access when the Agent must post review comments. A token can authenticate successfully while still producing missing-scope warnings; an identity lookup alone does not prove access to every configured repository.
Official references:
Plan token permissions
Choose permissions based on what the Agent is expected to do.
| Bitbucket permission | Scope | Use in Agent Barn | Recommendation |
|---|---|---|---|
| User: Read | read:user:bitbucket | Displays and validates the token owner’s identity | Recommended |
| Repositories: Read | read:repository:bitbucket | Lists repositories and reads branches, commits, and source files | Required |
| Pull requests: Read | read:pullrequest:bitbucket | Lists and reads pull requests, diffs, activity, and comments | Required for review workflows |
| Pull requests: Write | write:pullrequest:bitbucket | Creates or changes pull requests and performs write operations | Grant only when the workflow requires it |
| Pipelines: Read | read:pipeline:bitbucket | Reads pipelines, steps, and logs | Required only for CI inspection |
| Repositories: Write | write:repository:bitbucket | Modifies repository content | Not required by the current read-oriented source workflow |
A common code-review configuration is:
read:user:bitbucket
read:repository:bitbucket
read:pullrequest:bitbucket
read:pipeline:bitbucketAdd write:pullrequest:bitbucket only when the Agent must perform pull-request write operations beyond the actions covered by read access.
Create a Bitbucket API token
- Sign in to the Atlassian account that the Agent will use.
- Open the account’s Security settings.
- Select Create and manage API tokens.
- Select Create API token with scopes.
- Enter a descriptive name, such as
agent-barn-code-reviewer. - Set an expiration date that matches your credential-rotation policy.
- Select Bitbucket as the application.
- Select the permissions planned in the previous section.
- Restrict the token to the intended workspace if Atlassian offers that option in your account.
- Review the configuration and create the token.
- Copy the token immediately.
Bitbucket displays the token only once.
Collect repository details
Collect the following values before opening Agent Barn.
| Value | Example | Where to find it |
|---|---|---|
| Workspace ID | acme-engineering | The workspace segment in a Bitbucket repository URL |
| Repository slug | agent-barn | The final repository segment in the URL |
| Account email | agent@example.com | The Atlassian account that created the API token |
| API token | REDACTED | The token copied during creation |
For this repository URL:
https://bitbucket.org/acme-engineering/agent-barnUse workspace acme-engineering and repository agent-barn.
Enter a bare repository slug in Agent Barn. Do not enter the full URL or workspace/repository.
Correct
agent-barnIncorrect
https://bitbucket.org/acme-engineering/agent-barn
acme-engineering/agent-barnThe workspace ID can differ from the workspace’s display name. Use the value from the repository URL.
Connect Bitbucket
- In Agent Barn, open Agents.
- Select the Agent that needs Bitbucket access.
- Open the Agent’s Configuration.
- Select Keys & integrations.
- Select Edit.
- Under Integration credentials, add Bitbucket.
- Select Manual credential.
- Complete the Bitbucket fields.
- Apply the configuration.
| Agent Barn field | Required | Value |
|---|---|---|
Workspace (workspace) | Yes | Bitbucket workspace identifier |
Repositories (repos) | No | Optional list of bare repository slugs |
Email (email) | Yes | Account email used when Basic authentication is required |
API token (apiToken) | Yes | Secret token or supported access token |
Example:
Workspace
acme-engineering
Repositories
agent-barn
internal-platform
Email
agent@example.com
API token
••••••••••••••••repos is a list, not a single repo field. Legacy credentials with one repository may be normalized into this list; new entries should always use repos. The API token is encrypted and write-only, so examples never display a real token.
If the Agent is running, use the website’s restart-aware apply flow. The updated credential and generated profile become available when the Agent starts again.
Assign the Bitbucket Skill
The aai-bitbucket Skill supplies instructions and command references; the Bitbucket Integration credential supplies authentication and generated profile configuration. Bitbucket is a tool Integration, not a Communication Connection.
- Open the Agent’s Skills configuration.
- Select Edit.
- Add the built-in Bitbucket Skill.
- Apply the change.
- Restart the Agent if prompted.
The mounted Skill’s canonical entry point is:
./skills/aai-bitbucket/SKILL.mdaai-bitbucket/
├── SKILL.md
└── references/
└── command-reference.mdThe Agent should read ./skills/aai-bitbucket/SKILL.md before using Bitbucket. The supporting command reference belongs to that same bundle; the Skill is not one file inside a shared aai-cli directory. It documents the aai-cli bitbucket command group.
Assigning the Skill does not create, reveal, or grant a credential; adding a credential does not mutate the Skill. The bundled Skill declares Bitbucket as a required provider, which Agent configuration validates against available Integration credentials. Bitbucket is also eligible for the manual-entry Shared Credentials workflow.
Validate the connection
After saving the credential:
- Return to Keys & integrations.
- Find the configured Bitbucket credential.
- Select Validate.
- Review the validation status, identity, and missing scopes.
| Status | Meaning |
|---|---|
| Valid | Authentication succeeded and no checked scope is missing |
| Warning | Authentication succeeded, but the validator detected a missing permission |
| Invalid | The token was rejected, expired, unreachable, or could not access a required resource |
A successful response resembles:
{
"validation_status": "valid",
"validation_identity": "Agent Account (@agent-account)",
"validation_error": null,
"missing_scopes": []
}A usable token with incomplete permissions can return:
{
"validation_status": "warning",
"validation_identity": "Agent Account (@agent-account)",
"validation_error": null,
"missing_scopes": [
"Repositories (read) scope missing"
]
}Verify Agent access
Ask the Agent to identify its configured Bitbucket integration and inspect a known repository. For direct runtime verification, use commands like these inside the Agent environment.
List repositories:
aai-cli bitbucket repos list \
--limit 3 \
--profile bitbucket-workRead repository metadata:
aai-cli bitbucket repos get acme-engineering/agent-barn \
--profile bitbucket-workRead the default branch:
aai-cli bitbucket branches get main \
--owner acme-engineering \
--repo agent-barn \
--profile bitbucket-workRead a source file:
aai-cli bitbucket source get main README.md \
--owner acme-engineering \
--repo agent-barn \
--profile bitbucket-workList pull requests:
aai-cli bitbucket prs list \
--owner acme-engineering \
--repo agent-barn \
--state OPEN \
--limit 5 \
--profile bitbucket-workInspect recent pipelines:
aai-cli bitbucket pipelines list \
--owner acme-engineering \
--repo agent-barn \
--limit 5 \
--profile bitbucket-workSuccessful command output is JSON. Errors are written to standard error as a JSON object, and return a non-zero exit code.
Use the supported command groups
aai-cli bitbucket repos
aai-cli bitbucket prs
aai-cli bitbucket branches
aai-cli bitbucket commits
aai-cli bitbucket source
aai-cli bitbucket pipelinesThese commands list and inspect repositories, pull requests, branches, commits, source files and history, pipelines, steps, and logs. Pull-request commands also read diffs, diff statistics, commits, and activity, and can list, create, update, or delete comments. The Skill documents these commands; aai-cli performs the provider operation.
Review a pull request through aai-cli
- Run
prs getto inspect pull-request metadata. - Run
prs diffstatto identify changed files. - Use
prs diff --outputfor a large diff. - Use
source get <commit> <path>for exact file contents. - Use
prs comments createonly when the Agent’s policy permits review comments.
aai-cli bitbucket prs get 42 --repo my-workspace/my-repo --profile bitbucket-work
aai-cli bitbucket prs diffstat 42 --repo my-workspace/my-repo --profile bitbucket-work
aai-cli bitbucket prs diff 42 --repo my-workspace/my-repo --output local/logs/pr-42.diff --profile bitbucket-work
aai-cli bitbucket source get <commit> <path> --repo my-workspace/my-repo --profile bitbucket-workFor an inline comment, use --inline-path and --inline-to for a line added in the new file, or --inline-from for a line removed from the old file. Do not use direct Bitbucket REST calls as the Agent interface.
Repository profiles
Agent Barn converts the repository list into one or more aai-cli profiles.
One repository
Workspace acme-engineering with repository agent-barn creates a single profile:
bitbucket-work → acme-engineering/agent-barn
Multiple repositories
Each additional repository adds a numbered profile: bitbucket-work-2, bitbucket-work-3, and so on.
No configured repository
bitbucket-work is still created, but without a default repo. Repository commands must pass --repo.
With three repositories configured, Agent Barn creates:
bitbucket-work → acme-engineering/agent-barn
bitbucket-work-2 → acme-engineering/internal-platform
bitbucket-work-3 → acme-engineering/documentationThe Agent’s generated tool context contains the authoritative mapping. Do not infer that a numbered profile refers to a particular repository without checking that mapping.
Because command-line values override profile defaults, the Agent can normally continue using bitbucket-work and pass the intended --owner and --repo explicitly:
--owner acme-engineering --repo agent-barnRuntime behavior
When the Agent starts, Agent Barn:
- Decrypts the Bitbucket credential for the runtime.
- Writes the token to the encrypted
aai-clisecret store. - Generates the Bitbucket profile.
- Mounts the built-in Bitbucket Skill.
- Adds the profile mapping to the Agent’s tool context.
A generated profile resembles:
[profiles.bitbucket-work]
auth_type = "basic_api_token"
workspace = "acme-engineering"
repo = "agent-barn"
email = "agent@example.com"
api_token_secret = "bitbucket.api_token"The token itself is not written into the profile. The profile references the encrypted secret name bitbucket.api_token.
The complete runtime path is:
Encrypted Bitbucket credential
│
▼
Agent start
│
├── aai-cli encrypted secret store
├── bitbucket-work profile
└── Bitbucket Skill files
│
▼
aai-cli bitbucket
│
▼
Bitbucket Cloud APICredential changes take effect after the Agent restarts.
Use a Shared Credential
An Organization administrator can create an Organization-owned Shared Credential for Bitbucket, and attach it to multiple Agents.
Use a Shared Credential when:
- Multiple Agents should use the same dedicated Bitbucket service account
- One administrator should rotate the token centrally
- Individual Agent operators should not handle the token
- The same workspace and repository defaults apply to several Agents
To attach one:
- Create or locate the Bitbucket Shared Credential in the Organization.
- Open the Agent’s Keys & integrations configuration.
- Add Bitbucket.
- Switch from Manual credential to Shared Credential.
- Select the intended credential.
- Apply the change, and restart the Agent if prompted.
- Validate the connection from the Agent.
An Agent can use either a manual Bitbucket credential or a Shared Bitbucket Credential, not both simultaneously.
Continue to Use shared credentials for the complete ownership and rotation model.
Rotate or remove the credential
Rotate a manual credential
- Create a replacement API token in Atlassian.
- Keep the old token active temporarily.
- Open the Agent’s Keys & integrations configuration.
- Replace the Bitbucket credential with the new token.
- Apply the change.
- Restart the Agent.
- Validate the new credential.
- Run a real repository command.
- Revoke the old token in Atlassian.
Because secret values are write-only, rotation replaces the complete credential content. Re-enter the workspace, repositories, email, and token.
Rotate a Shared Credential
Update the Organization-owned Shared Credential, validate it, and restart attached Agents so their runtime artifacts are regenerated.
Remove the credential
Before removing Bitbucket:
- Remove or replace any assigned Skill that requires Bitbucket.
- Stop the Agent, or use the website’s restart-aware apply flow.
- Open Keys & integrations.
- Mark the Bitbucket credential for removal.
- Apply the change.
- Restart and verify the Agent.
Agent Barn blocks removal when a remaining assigned Skill requires the bitbucket provider.
API reference
Add or replace a manual credential
The Agent must be stopped when using the raw update endpoint.
PATCH /api/v1/organizations/{organization_id}/agents/{agent_id}
Content-Type: application/json{
"secrets": [
{
"provider": "bitbucket",
"content": {
"workspace": "acme-engineering",
"repos": [
"agent-barn",
"internal-platform"
],
"email": "agent@example.com",
"apiToken": "REDACTED"
}
}
]
}Attach a Shared Credential
{
"shared_credentials": [
{
"shared_credential_id": "00000000-0000-0000-0000-000000000000"
}
]
}Validate the Agent credential
POST /api/v1/organizations/{organization_id}/agents/{agent_id}/integrations/bitbucket/validateThe response includes:
{
"validation_status": "valid",
"validation_identity": "Agent Account (@agent-account)",
"validation_error": null,
"missing_scopes": []
}Remove the credential
{
"removed_secret_providers": [
"bitbucket"
]
}Credential operations require access to the Agent and the appropriate update and secret-management permissions, including agent.secret.manage.
Troubleshooting
The Agent cannot find the Bitbucket command guidance
Skill, credential, or profile
Confirm the Bitbucket Integration exists for the Agent, the required Skill is assigned and published, and the Agent has started with the generated artifacts. Read ./skills/aai-bitbucket/SKILL.md and pass --profile bitbucket-work explicitly. If no repository is configured, include --repo; for several repositories, select the corresponding generated profile or pass an explicit repository identity.
Validation reports “Invalid API token or credentials”
Check the token type and email
Check that:
- You created an API token with scopes for the Bitbucket application
- Email is the Atlassian account email that owns the token
- The token was copied completely
- The token has not expired or been revoked
- You did not enter an Atlassian account password
- You did not enter a retired Bitbucket app password
Create a replacement token if the original token can no longer be retrieved.
Validation succeeds but repository commands return 403
A permission or membership gap
The token authenticated, but it lacks a required permission, or the account cannot access the repository. Check:
read:repository:bitbucketis selected- The account is a member of the target workspace, or has repository access
- The token is allowed to access the target workspace
- The workspace ID and repository slug are correct
- Pull-request and pipeline permissions are present for those operations
Pull requests work but source files fail
Separate scopes
Pull-request access and repository access use separate scopes. Add read:repository:bitbucket.
The pull-request scope does not automatically grant access to repository source endpoints.
Source files work but pull requests fail
Repository Read is not enough
Add read:pullrequest:bitbucket. Repository Read does not include pull-request access.
Pipeline commands return 403
Pipelines has its own scope
Add read:pipeline:bitbucket. Repository Read does not include Bitbucket Pipelines.
The repository cannot be found
Check IDs and slugs
Confirm that:
- Workspace contains the workspace ID, not its display name
- Repositories contains a bare slug
--ownercontains only the workspace ID--repocontains only the repository slug- The token-owning account can open the repository in Bitbucket
aai-cli reports that the repository is missing
No default repository
No default repository was configured, or the command did not include --repo. Run the command with explicit values:
aai-cli bitbucket prs list \
--owner acme-engineering \
--repo agent-barn \
--profile bitbucket-work The wrong repository is used
Pass the target explicitly
Pass both the workspace and repository explicitly:
--owner acme-engineering --repo agent-barnIf using a numbered profile, consult the Agent’s generated integration mapping before selecting it.
Validation succeeds but runtime commands fail authentication
Bearer tokens do not match the profile
Confirm that you supplied a user-based Bitbucket API token and its Atlassian account email.
Workspace and repository access tokens use bearer authentication, while the current Agent Barn runtime profile uses basic_api_token. Replace the credential with an account API token for the supported end-to-end flow.
The credential cannot be removed
A Skill still requires it
A remaining assigned Skill requires Bitbucket.
Remove the Bitbucket Skill, or replace the dependent Skill, before removing the credential.
Changes are not visible to the Agent
Artifacts are produced at startup
Restart the Agent. Profiles, encrypted runtime Secrets, mounted Skills, and generated tool context are produced during Agent startup.
Security practices
- Use a dedicated Bitbucket account for production Agents
- Grant the account access only to required repositories
- Create a separate API token for Agent Barn
- Set an expiration date
- Start with read scopes
- Avoid repository write, admin, and delete scopes unless a documented workflow requires them
- Use different credentials for different authorization boundaries
- Treat the repository list as defaults, not access control
- Prefer Shared Credentials when administrators should own rotation
- Validate after every rotation
- Test a real repository operation after validation
- Revoke replaced or compromised tokens immediately
- Never place a real token in documentation, source control, logs, prompts, or chat messages