Bring Claude's AI-powered code assistance directly into your Bitbucket Pipelines workflows. This pipe enables automated code reviews, intelligent PR responses, and AI-driven development tasks within your CI/CD pipeline.
# Basic setup - Claude responds to @claude mentions in PRs
pipelines:
pull-requests:
'**':
- step:
name: Claude Code Assistant
image: atlassian/default-image:4
script:
# Install Bun
- curl -fsSL https://bun.sh/install | bash
- export PATH="$HOME/.bun/bin:$PATH"
# Clone and setup Claude pipe
- git clone https://github.com/tsadrakula/Claude_Code_Bitbucket.git /tmp/claude-pipe
- cd /tmp/claude-pipe && bun install && bun run build
# Return to repository directory and run Claude
- cd $BITBUCKET_CLONE_DIR && bun run /tmp/claude-pipe/dist/index.js
services:
- docker-
Go to Repository settings β Repository variables
-
REQUIRED for PR comments (choose one option):
Option A: Repository Access Token (Recommended)
- Go to Repository settings β Access tokens β Create access token
- Name: "Claude Code"
- Permissions: Pull requests (write), Repositories (read)
- Set
BITBUCKET_ACCESS_TOKEN=x-token-auth:your_token_here
Option B: App Password
BITBUCKET_ACCESS_TOKEN=username:app_password(Create app password)
Option C: Separate Variables
BITBUCKET_USERNAME= Your usernameBITBUCKET_APP_PASSWORD= Your app password
-
Add your Claude API key (choose one):
ANTHROPIC_API_KEY- For Anthropic Claude APIAWS_ACCESS_KEY_ID+AWS_SECRET_ACCESS_KEY- For AWS BedrockGCP_PROJECT_ID+GCP_SERVICE_ACCOUNT_KEY- For Google Vertex AI
Now Claude will respond when you:
- Create a PR with
@claudein the description - Comment
@claudeon any PR - Tag
@claudefor code reviews
The Atlassian default image has git and other tools pre-installed:
pipelines:
pull-requests:
'**':
- step:
name: Claude Code Assistant
image: atlassian/default-image:4
script:
# Install Bun
- curl -fsSL https://bun.sh/install | bash
- export PATH="$HOME/.bun/bin:$PATH"
# Clone and setup Claude pipe
- git clone https://github.com/tsadrakula/Claude_Code_Bitbucket.git /tmp/claude-pipe
- cd /tmp/claude-pipe
- bun install
- bun run build
# Return to repository directory and run Claude
- cd $BITBUCKET_CLONE_DIR
- bun run /tmp/claude-pipe/dist/index.js
services:
- dockerLighter weight option with Node.js:
pipelines:
pull-requests:
'**':
- step:
name: Claude Code Assistant
image: node:20-alpine
script:
# Install required tools
- apk add --no-cache git bash
- npm install -g bun
# Clone and setup Claude pipe
- git clone https://github.com/tsadrakula/Claude_Code_Bitbucket.git /tmp/claude-pipe
- cd /tmp/claude-pipe
- bun install
- bun run build
# Return to repository directory and run Claude
- cd $BITBUCKET_CLONE_DIR
- bun run /tmp/claude-pipe/dist/index.js
services:
- dockerPre-built Docker image:
pipelines:
pull-requests:
'**':
- step:
name: Claude Code Assistant
image: tsadrakula/claude-bitbucket-pipe:latest
script:
- /app/run.sh- Fork this repository
- Customize as needed
- Build and publish to your workspace:
# Clone and customize
git clone https://github.com/tsadrakula/Claude_Code_Bitbucket.git
cd Claude_Code_Bitbucket
# Install and build
bun install
bun run build
# Build Docker image
docker build -t your-workspace/claude-code-pipe:latest .
# Push to your registry
docker push your-workspace/claude-code-pipe:latestThen use in your pipeline:
pipelines:
pull-requests:
'**':
- step:
name: Claude Code Assistant
script:
- pipe: your-workspace/claude-code-pipe:latest
variables:
MODE: "tag"
TRIGGER_PHRASE: "@claude"pipelines:
pull-requests:
'**':
- step:
name: Automatic PR Review
image: atlassian/default-image:4
script:
- curl -fsSL https://bun.sh/install | bash
- export PATH="$HOME/.bun/bin:$PATH"
- git clone https://github.com/tsadrakula/Claude_Code_Bitbucket.git claude-pipe
- cd claude-pipe && bun install && bun run build
- MODE=experimental-review bun startpipelines:
custom:
claude-agent:
- step:
name: Claude Agent
image: atlassian/default-image:4
script:
- curl -fsSL https://bun.sh/install | bash
- export PATH="$HOME/.bun/bin:$PATH"
- git clone https://github.com/tsadrakula/Claude_Code_Bitbucket.git claude-pipe
- cd claude-pipe && bun install && bun run build
- MODE=agent TASK="Refactor authentication module" bun startpipelines:
pull-requests:
'**':
- step:
name: Claude with Custom Trigger
image: atlassian/default-image:4
script:
- curl -fsSL https://bun.sh/install | bash
- export PATH="$HOME/.bun/bin:$PATH"
- git clone https://github.com/tsadrakula/Claude_Code_Bitbucket.git claude-pipe
- cd claude-pipe && bun install && bun run build
- TRIGGER_PHRASE="@ai-assist" bun start| Variable | Description |
|---|---|
BITBUCKET_ACCESS_TOKEN |
REQUIRED for PR comments - Format: username:app_password |
BITBUCKET_USERNAME |
Alternative: Your Bitbucket username (use with BITBUCKET_APP_PASSWORD) |
BITBUCKET_APP_PASSWORD |
Alternative: Your app password (use with BITBUCKET_USERNAME) |
| Variable | Description |
|---|---|
| Anthropic API | |
ANTHROPIC_API_KEY |
Your Anthropic API key |
| AWS Bedrock | |
AWS_ACCESS_KEY_ID |
AWS access key |
AWS_SECRET_ACCESS_KEY |
AWS secret key |
AWS_REGION |
AWS region (default: us-east-1) |
| Google Vertex AI | |
GCP_PROJECT_ID |
Google Cloud project ID |
GCP_SERVICE_ACCOUNT_KEY |
Service account JSON key |
GCP_REGION |
GCP region (default: us-central1) |
| Variable | Description | Default |
|---|---|---|
| Core Settings | ||
MODE |
Operation mode: tag, agent, or experimental-review |
tag |
TRIGGER_PHRASE |
Phrase to trigger Claude in comments | @claude |
MODEL |
Claude model to use | sonnet |
MAX_TURNS |
Maximum conversation turns | 30 |
TIMEOUT_MINUTES |
Execution timeout | 10 |
| Comment Handling | ||
ENABLE_STREAMING_COMMENTS |
Show live updates as Claude responds | false |
AUTO_DETECT_ACTIONABLE |
Automatically detect and execute actionable requests | true |
COMMENT_UPDATE_STRATEGY |
How to post comments: stream, final, or both |
final |
| Repository Settings | ||
BRANCH_PREFIX |
Prefix for created branches | claude/ |
AUTO_COMMIT |
Automatically commit changes | false |
AUTO_PR |
Automatically create PRs | false |
| Development | ||
VERBOSE |
Enable verbose logging | false |
DRY_RUN |
Test without making changes | false |
WORKING_DIRECTORY |
Override Claude's working directory | $BITBUCKET_CLONE_DIR |
Claude automatically detects whether your request is actionable (requires code changes) or informational (needs explanation):
| Request Type | Example | Claude's Response |
|---|---|---|
| Actionable | "Change this color to blue" | Makes the edit directly |
| Actionable | "Fix the bug in login" | Implements the fix |
| Actionable | "Add error handling here" | Adds the code |
| Informational | "What does this function do?" | Explains without editing |
| Informational | "How does authentication work?" | Provides detailed explanation |
| Informational | "Review this for security issues" | Analyzes and reports findings |
Claude now properly responds to inline comments:
- Proper Threading: Claude replies directly to YOUR comment (not a new thread)
- Context Preservation: Maintains the conversation in the same thread
- Smart Fallback: Falls back to top-level if line numbers unavailable
- Branch Awareness: Claude knows which branch it's working on
Control how Claude posts responses with COMMENT_UPDATE_STRATEGY:
| Strategy | Behavior | Use Case |
|---|---|---|
final (default) |
Posts once when complete | Clean PR history |
stream |
Shows live updates only | Real-time feedback |
both |
Updates during + final post | Maximum visibility |
Example configuration for streaming:
script:
- ENABLE_STREAMING_COMMENTS=true COMMENT_UPDATE_STRATEGY=both bun startIn a PR comment:
@claude Can you review this authentication implementation for security issues?
@claude Please add input validation to the user registration function
@claude How would you implement rate limiting for this API endpoint?
@claude The tests are failing. Can you help fix them?
On a specific line in a PR:
@claude could you change this color to a darker shade of blue?
Claude will:
- β Detect this as an actionable request
- β Make the edit directly
- β Reply inline to your comment
Informational request:
@claude What does this authentication function do?
Claude will:
- π Explain the function
- π« Won't make any edits
Actionable request:
@claude Fix the SQL injection vulnerability in this query
Claude will:
- π§ Implement the fix
- β Update the code
- π¬ Explain the changes
pipelines:
pull-requests:
'**':
- step:
name: Claude via AWS Bedrock
image: atlassian/default-image:4
script:
- curl -fsSL https://bun.sh/install | bash
- export PATH="$HOME/.bun/bin:$PATH"
- git clone https://github.com/tsadrakula/Claude_Code_Bitbucket.git claude-pipe
- cd claude-pipe && bun install && bun run build
- |
export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
export AWS_REGION="us-east-1"
export MODEL="sonnet"
bun startpipelines:
pull-requests:
'**':
- step:
name: Claude via Google Vertex
image: atlassian/default-image:4
script:
- curl -fsSL https://bun.sh/install | bash
- export PATH="$HOME/.bun/bin:$PATH"
- git clone https://github.com/tsadrakula/Claude_Code_Bitbucket.git claude-pipe
- cd claude-pipe && bun install && bun run build
- |
export GCP_PROJECT_ID=$GCP_PROJECT_ID
export GCP_SERVICE_ACCOUNT_KEY=$GCP_SERVICE_ACCOUNT_KEY
export GCP_REGION="us-central1"
export MODEL="sonnet"
bun startpipelines:
# Automatic PR reviews
pull-requests:
'**':
- step:
name: Claude PR Assistant
image: atlassian/default-image:4
script:
- curl -fsSL https://bun.sh/install | bash
- export PATH="$HOME/.bun/bin:$PATH"
- git clone https://github.com/tsadrakula/Claude_Code_Bitbucket.git claude-pipe
- cd claude-pipe && bun install && bun run build
- bun start
# Manual agent tasks
custom:
run-claude-agent:
- variables:
- name: TASK
default: "Analyze and improve code quality"
- step:
name: Claude Agent Task
image: atlassian/default-image:4
script:
- curl -fsSL https://bun.sh/install | bash
- export PATH="$HOME/.bun/bin:$PATH"
- git clone https://github.com/tsadrakula/Claude_Code_Bitbucket.git claude-pipe
- cd claude-pipe && bun install && bun run build
- MODE=agent TASK="$TASK" bun start
# Scheduled maintenance
branches:
main:
- step:
name: Weekly Code Review
image: atlassian/default-image:4
trigger: manual
script:
- curl -fsSL https://bun.sh/install | bash
- export PATH="$HOME/.bun/bin:$PATH"
- git clone https://github.com/tsadrakula/Claude_Code_Bitbucket.git claude-pipe
- cd claude-pipe && bun install && bun run build
- MODE=agent TASK="Review code for potential improvements" bun start# Clone the repository
git clone https://github.com/tsadrakula/Claude_Code_Bitbucket.git
cd Claude_Code_Bitbucket
# Install dependencies
bun install
# Run tests
bun test
# Build the project
bun run build
# Test locally with your Bitbucket repo
export BITBUCKET_WORKSPACE="your-workspace"
export BITBUCKET_REPO_SLUG="your-repo"
export ANTHROPIC_API_KEY="your-api-key"
bun run dev# Build image
docker build -t claude-bitbucket-pipe .
# Test locally
docker run --env-file .env claude-bitbucket-pipe
# Push to registry
docker tag claude-bitbucket-pipe your-registry/claude-bitbucket-pipe:latest
docker push your-registry/claude-bitbucket-pipe:latest- API Keys: Always use Bitbucket's secured repository variables
- Permissions: Use repository access tokens with minimal required permissions
- Review: Always review Claude's suggestions before merging
- Branches: Use
BRANCH_PREFIXto isolate Claude's changes - Dry Run: Test with
DRY_RUN=truefirst
- Check the trigger phrase matches (default:
@claude) - Verify API key is set in repository variables
- Check pipeline logs: Repository β Pipelines β View logs
Use atlassian/default-image:4 or install git:
# For alpine images
- apk add --no-cache git
# For debian/ubuntu images
- apt-get update && apt-get install -y git# Test API key locally
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01"# Increase timeout in pipeline
script:
- TIMEOUT_MINUTES=30 bun startRecommended: Repository Access Token
- Go to Repository settings β Security β Access tokens
- Click "Create access token"
- Name: "Claude Code"
- Permissions:
- Pull requests: Write
- Repositories: Read
- Copy the token
- Set
BITBUCKET_ACCESS_TOKEN=x-token-auth:TOKEN_HERE
Alternative: App Password
- Go to Bitbucket App Passwords
- Click "Create app password"
- Label: "Claude Code"
- Permissions:
- Pull requests: Read and Write
- Repositories: Read
- Copy the password
- Set
BITBUCKET_ACCESS_TOKEN=yourusername:password_here
- π Read the technical documentation
- π Report an issue
- π¬ Check existing issues
- π See example configurations
MIT License - see LICENSE for details.
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new features
- Submit a pull request
See CONTRIBUTING.md for details.
Powered by Anthropic's Claude and Bitbucket Pipelines