cicd-integration
Patterns for integrating Claude Code into CI/CD pipelines — GitHub Actions, GitLab CI, pre-commit hooks, automated PR reviews, headless mode, and cost control
What this skill does
# CI/CD Integration Patterns
Integrate Claude Code into CI/CD pipelines for automated PR reviews, code generation, test validation, security scanning, and documentation updates. This skill covers GitHub Actions, GitLab CI, pre-commit hooks, and headless execution modes.
## GitHub Actions Integration
Use the official `anthropics/claude-code-action@v1` action for turnkey GitHub integration.
### Supported Features
- Trigger on pull requests, push, schedule, or workflow dispatch
- Environment variable support: `ANTHROPIC_API_KEY`, `CLAUDE_MODEL`
- Pipe mode (`claude -p`) with JSON output
- Tool access filtering via `--allowedTools`
- Multiple model routing (Opus for reviews, Haiku for checks)
- Cost tracking and budget enforcement
### Setup
```yaml
# .github/workflows/claude-pr-review.yml
name: Claude PR Review
on:
pull_request:
types: [opened, synchronize]
workflow_dispatch:
jobs:
review:
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: read
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: anthropics/claude-code-action@v1
with:
task: |
Review the changes in this PR and provide:
1. Security issues found (if any)
2. Code style or complexity concerns
3. Test coverage gaps
4. Performance suggestions
Format as JSON for PR comment automation.
model: claude-opus-4-1-20250805
allowed-tools: Read,Grep,Glob
output-format: json
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
```
### Usage in PR Comments
```yaml
# .github/workflows/claude-pr-analysis.yml
name: Claude PR Analysis with Comments
on:
pull_request:
types: [opened, synchronize]
jobs:
analyze:
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: read
steps:
- uses: actions/checkout@v4
- uses: anthropics/claude-code-action@v1
id: claude
with:
task: |
{
"goal": "Review files in this PR",
"files": "${{ github.event.pull_request.title }}",
"output": "json"
}
output-format: json
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
- name: Comment Review on PR
if: always()
uses: actions/github-script@v7
with:
script: |
const result = JSON.parse('${{ steps.claude.outputs.result }}');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `## Claude Code Review\n\n${result.summary}`
});
```
### Code Generation Workflow
```yaml
# .github/workflows/claude-codegen.yml
name: Generate Code on Dispatch
on:
workflow_dispatch:
inputs:
feature:
description: Feature to generate
required: true
model:
description: Model to use
default: claude-opus-4-1-20250805
required: false
jobs:
generate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: anthropics/claude-code-action@v1
with:
task: Generate ${{ github.event.inputs.feature }}
model: ${{ github.event.inputs.model }}
output-format: json
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
- name: Create PR with Generated Code
uses: peter-evans/create-pull-request@v5
with:
commit-message: "feat: ${{ github.event.inputs.feature }}"
title: "Generate: ${{ github.event.inputs.feature }}"
body: "Auto-generated code from Claude Code Expert"
```
## GitLab CI Integration
Configure Claude Code in GitLab CI pipelines using Docker containers and the CLI.
### Setup
```yaml
# .gitlab-ci.yml
stages:
- review
- test
- generate
variables:
CLAUDE_MODEL: claude-haiku-4-5-20251001
CLAUDE_MAX_TURNS: "5"
claude_review:
stage: review
image: node:20-alpine
before_script:
- npm install -g @anthropic-ai/claude-code
script:
- |
claude \
-p "Review the MR changes and identify issues" \
--allowedTools Read,Grep,Glob \
--output-format json > review_output.json
artifacts:
paths:
- review_output.json
expire_in: 1 day
only:
- merge_requests
claude_test_gap:
stage: test
image: node:20-alpine
before_script:
- npm install -g @anthropic-ai/claude-code
script:
- |
claude \
-p "Find test coverage gaps in changed files" \
--allowedTools Read,Grep,Glob \
--max-turns 3
allow_failure: true
```
### With Caching
```yaml
claude_cached_analysis:
stage: review
image: node:20-alpine
cache:
key: claude-analysis-${CI_COMMIT_SHA}
paths:
- .claude/cache/
- .claude/memory/
before_script:
- npm install -g @anthropic-ai/claude-code
script:
- claude -p "Cached analysis of repo structure"
```
## Pre-Commit Hook Integration
Validate code locally before pushing using Claude Code as a pre-commit hook.
### Husky Setup
```bash
# Install dependencies
npm install husky lint-staged -D
# Initialize husky
npx husky install
# Create Claude hook
cat > .husky/pre-commit << 'EOF'
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
# Run lint-staged (including Claude)
npx lint-staged
EOF
chmod +x .husky/pre-commit
```
### Lint-Staged Configuration
```json
{
"lint-staged": {
"*.{ts,tsx,js,jsx}": [
"eslint --fix",
"claude -p 'Quick style check' --allowedTools Read,Grep"
],
"*.{md,mdx}": [
"markdown-lint",
"claude -p 'Check documentation clarity' --allowedTools Read"
]
}
}
```
### Direct Pre-Commit Hook
```bash
#!/bin/bash
# .git/hooks/pre-commit
# Check staged files with Claude Code
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(ts|tsx|js|jsx)$')
if [ -z "$STAGED_FILES" ]; then
exit 0
fi
echo "Running Claude Code check on staged files..."
if ! claude -p "Security check: $STAGED_FILES" \
--allowedTools Read,Grep,Glob \
--max-turns 2; then
echo "Claude Code check failed. Use 'git commit --no-verify' to bypass."
exit 1
fi
```
## Automated PR Reviews with Structured Output
Use JSON formatting to post structured reviews to PRs.
### Review Configuration
```bash
#!/bin/bash
# scripts/claude-pr-review.sh
set -euo pipefail
REPO=$1
PR_NUMBER=$2
GITHUB_TOKEN=$3
# Clone PR branch
git clone "https://github.com/$REPO.git" /tmp/pr-check
cd /tmp/pr-check
git fetch origin pull/$PR_NUMBER/head
git checkout FETCH_HEAD
# Run Claude review
REVIEW_JSON=$(claude -p \
"Analyze this PR for: security issues, code quality, test coverage, performance" \
--allowedTools Read,Grep,Glob \
--max-turns 3 \
--output-format json)
# Parse results and post
SECURITY=$(echo "$REVIEW_JSON" | jq -r '.security // "None found"')
QUALITY=$(echo "$REVIEW_JSON" | jq -r '.quality // "Pass"')
TESTS=$(echo "$REVIEW_JSON" | jq -r '.test_coverage // "Adequate"')
curl -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$REPO/issues/$PR_NUMBER/comments" \
-d @- << EOF
{
"body": "## Claude Code Review\n\n**Security:** $SECURITY\n\n**Quality:** $QUALITY\n\n**Tests:** $TESTS"
}
EOF
rm -rf /tmp/pr-check
```
## Headless Mode Patterns
Execute Claude Code in fully automated environments without interaction.
### Read-Only Checks
```bash
# Security scan (no write access)
claude -p "Security audit" \
--allowedTools Read,Grep,Glob \
--output-format json \
--max-turns 2
```
### Constrained Sessions
```bash
# Limit turn count to prevent runaway costs
claude -p "Generate test stubs" \
--allowedTools Read,Glob,Bash \
--max-turns 5 \
--output-format json
```
### Model Selection for CI
Related in Cloud & DevOps
appbuilder-action-scaffolder
IncludedCreate, implement, deploy, and debug Adobe Runtime actions with consistent layout, validation, and error handling. Use this skill whenever the user needs to add actions to an App Builder project, understand action structure (params, response format, web/raw actions), configure actions in the manifest, use App Builder SDKs (State, Files, Events, database), deploy and invoke actions via CLI, debug action issues, or implement patterns such as webhook receivers, custom event providers, journaling consumers, large payload redirects, action sequence pipelines, and Asset Compute workers. Also trigger when users mention serverless functions in Adobe context, action logging, IMS authentication for actions, or cron-style scheduled actions.
orchestrating-datacloud
IncludedSalesforce Data Cloud product orchestrator for connect→prepare→harmonize→segment→act workflows. Use this skill when the user needs a multi-step Data Cloud pipeline, cross-phase troubleshooting, or data space and data kit management. TRIGGER when: user needs a multi-step Data Cloud pipeline, asks to set up or troubleshoot Data Cloud across phases, manages data spaces or data kits, or wants a cross-phase sf data360 workflow. DO NOT TRIGGER when: work is isolated to a single phase (use the matching phase-specific skill), the task is STDM/session tracing/parquet telemetry (use observing-agentforce), standard CRM SOQL (use querying-soql), or Apex implementation (use generating-apex).
github-project-automation
IncludedAutomate GitHub repository setup with CI/CD workflows, issue templates, Dependabot, and CodeQL security scanning. Includes 12 production-tested workflows and prevents 18 errors: YAML syntax, action pinning, and configuration. Use when: setting up GitHub Actions CI/CD, creating issue/PR templates, enabling Dependabot or CodeQL scanning, deploying to Cloudflare Workers, implementing matrix testing, or troubleshooting YAML indentation, action version pinning, secrets syntax, runner versions, or CodeQL configuration. Keywords: github actions, github workflow, ci/cd, issue templates, pull request templates, dependabot, codeql, security scanning, yaml syntax, github automation, repository setup, workflow templates, github actions matrix, secrets management, branch protection, codeowners, github projects, continuous integration, continuous deployment, workflow syntax error, action version pinning, runner version, github context, yaml indentation error
sf-datacloud
IncludedSalesforce Data Cloud product orchestrator for connect→prepare→harmonize→segment→act workflows. TRIGGER when: user needs a multi-step Data Cloud pipeline, asks to set up or troubleshoot Data Cloud across phases, manages data spaces or data kits, or wants a cross-phase `sf data360` workflow. DO NOT TRIGGER when: work is isolated to a single phase (use the matching sf-datacloud-* skill), the task is STDM/session tracing/parquet telemetry (use sf-ai-agentforce-observability), standard CRM SOQL (use sf-soql), or Apex implementation (use sf-apex).
fabric-cli
IncludedUse this skill for Fabric.so CLI workflows with the `fabric` terminal command: diagnose/install/login, search or browse a Fabric library, save notes/links/files, create folders, ask the Fabric AI assistant, manage tasks/workspaces, generate shell completion, check subscription usage, produce JSON output, and use Fabric as persistent agent memory. Do not use for Microsoft Fabric/Azure/Power BI `fab`, Daniel Miessler's Fabric framework, Python Fabric SSH, Fabric.js, or textile/fashion fabric.
lark
IncludedLark/Feishu CLI skills: lark-cli operations for docs, markdown, sheets, base, calendar, im, mail, task, okr, drive, wiki, slides, whiteboard, apps, approval, attendance, contact, vc, minutes, event. Use when the user needs to operate Lark/Feishu resources via lark-cli, send messages, manage documents, spreadsheets, calendars, tasks, OKRs, deploy web pages, or any Feishu/Lark workspace operations.