làm tíai?GitHub ↗
CHƯƠNG 14 / 16

CI/CD và IDE integration

Đưa Claude Code vào GitHub Actions, GitLab CI/CD, VS Code và JetBrains.

12 phút đọc

Claude Code chạy được ở hai nơi ngoài terminal cá nhân: trong pipeline CI/CD (GitHub Actions, GitLab CI/CD) để tự động hoá PR/MR, và ngay trong IDE (VS Code, JetBrains) với giao diện native. Chương này tóm tắt cấu hình gọn và use case chính cho từng môi trường.

Claude Code trong GitHub Actions

@claude mention trong bất kỳ PR hoặc issue nào để Claude phân tích code, tạo PR, implement feature, fix bug — tất cả theo chuẩn của project (CLAUDE.md). Được xây trên nền Claude Agent SDK.

Quick setup

Chạy trong terminal Claude Code:

/install-github-app
  • Cài GitHub App vào repo, rồi hướng dẫn thêm workflow files + API key secret.
  • Yêu cầu: bạn phải là repo admin. App xin quyền read & write cho Contents, Issues, Pull requests.
  • v2.1.187+: có thể chọn Skip for now để chỉ cài App, quay lại sau bằng cách chạy lại /install-github-app.
  • Quick setup chỉ dành cho direct Claude API user. Bedrock/Vertex: xem phần cloud provider bên dưới.

Manual setup

  1. Cài Claude GitHub App: https://github.com/apps/claude (quyền: Contents, Issues, Pull requests — Read & write).
  2. Thêm ANTHROPIC_API_KEY vào repository secrets.
  3. Copy workflow file từ examples/claude.yml vào .github/workflows/.

Test: tag @claude trong một issue hoặc PR comment.

Basic workflow

Action tự động detect: chế độ interactive (phản hồi @claude mention) hay automation (chạy ngay với prompt).

name: Claude Code
on:
  issue_comment:
    types: [created]
  pull_request_review_comment:
    types: [created]
jobs:
  claude:
    runs-on: ubuntu-latest
    steps:
      - uses: anthropics/claude-code-action@v1
        with:
          anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
          # Responds to @claude mentions in comments

Automation với prompt (scheduled / event)

Khi có prompt, action chạy ngay không cần mention. Ví dụ báo cáo hằng ngày:

name: Daily Report
on:
  schedule:
    - cron: "0 9 * * *"
jobs:
  report:
    runs-on: ubuntu-latest
    steps:
      - uses: anthropics/claude-code-action@v1
        with:
          anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
          prompt: "Generate a summary of yesterday's commits and open issues"
          claude_args: "--model opus"

Gọi skill / plugin trong workflow

prompt chấp nhận cả skill invocation lẫn plain text:

  • Skill trong repo (.claude/skills/): chạy actions/checkout trước, rồi truyền /skill-name.
  • Skill trong plugin: cài qua plugin_marketplaces + plugins, truyền namespaced /plugin-name:skill-name.
name: Code Review
on:
  pull_request:
    types: [opened, synchronize]
jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: anthropics/claude-code-action@v1
        with:
          anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
          plugin_marketplaces: "https://github.com/anthropics/claude-code.git"
          plugins: "code-review@claude-code-plugins"
          prompt: "/code-review:code-review ${{ github.repository }}/pull/${{ github.event.pull_request.number }}"

Use case phổ biến (trong comment)

@claude implement this feature based on the issue description
@claude how should I implement user authentication for this endpoint?
@claude fix the TypeError in the user dashboard component

Action parameters (v1)

ParameterMô tảBắt buộc
promptInstructions cho Claude (plain text hoặc tên skill)Không*
claude_argsCLI arguments truyền cho Claude CodeKhông
plugin_marketplacesDanh sách Git URL marketplace (mỗi dòng một cái)Không
pluginsDanh sách plugin cần cài trước khi chạyKhông
anthropic_api_keyClaude API keyCó**
github_tokenGitHub token cho API accessKhông
trigger_phraseTrigger phrase tùy biến (mặc định @claude)Không
use_bedrockDùng Amazon Bedrock thay Claude APIKhông
use_vertexDùng Google Cloud's Agent PlatformKhông

*Bỏ trống prompt với issue/PR comment thì Claude phản hồi theo trigger phrase. **Chỉ bắt buộc với direct Claude API, không cần cho Bedrock/Vertex.

claude_args nhận mọi CLI argument, ví dụ:

claude_args: "--max-turns 5 --model claude-sonnet-5 --mcp-config /path/to/config.json"

Thường dùng: --max-turns (mặc định 10), --model, --mcp-config, --allowedTools, --debug.

Upgrade từ Beta lên v1

Breaking changes cần sửa trong workflow:

  • @beta@v1.
  • Xóa mode: "tag" / mode: "agent" (giờ auto-detect).
  • direct_promptprompt.
  • Chuyển max_turns, model, custom_instructions... sang claude_args (ví dụ --max-turns, --model, --append-system-prompt).
  • allowed_toolsclaude_args: --allowedTools; claude_env → định dạng settings JSON.

Dùng với Amazon Bedrock / Google Cloud

Cho môi trường enterprise: kiểm soát data residency và billing bằng cloud infra riêng.

  • Xác thực qua OIDC (Bedrock) hoặc Workload Identity Federation (Vertex) — không lưu static key.
  • Khuyến nghị tạo GitHub App riêng, dùng actions/create-github-app-token sinh token trong workflow.
  • Secrets cần: Bedrock AWS_ROLE_TO_ASSUME; Vertex GCP_WORKLOAD_IDENTITY_PROVIDER + GCP_SERVICE_ACCOUNT; kèm APP_ID + APP_PRIVATE_KEY nếu dùng App riêng.

Ví dụ bước quan trọng cho Bedrock (rút gọn):

- uses: anthropics/claude-code-action@v1
  with:
    github_token: ${{ steps.app-token.outputs.token }}
    use_bedrock: "true"
    claude_args: '--model us.anthropic.claude-sonnet-4-6 --max-turns 10'

Model ID cho Bedrock có region prefix (ví dụ us.anthropic.claude-sonnet-4-6).

Chi phí và bảo mật

  • Job chạy trên GitHub-hosted runners → tiêu tốn GitHub Actions minutes; mỗi interaction tiêu tốn API token.
  • Tối ưu: @claude command cụ thể, đặt --max-turns, workflow-level timeout, dùng concurrency controls.
  • KHÔNG commit API key. Luôn dùng GitHub Secrets: anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}.

Claude Code trong GitLab CI/CD

Integration này đang ở beta, do GitLab maintain. Cơ chế: GitLab lắng nghe trigger (ví dụ comment @claude), job thu thập context, chạy Claude Code trong container isolated, mọi thay đổi đi qua MR.

Quick setup

  1. Thêm masked CI/CD variable: Settings → CI/CD → VariablesANTHROPIC_API_KEY.
  2. Thêm job vào .gitlab-ci.yml:
stages:
  - ai

claude:
  stage: ai
  image: node:24-alpine3.21
  rules:
    - if: '$CI_PIPELINE_SOURCE == "web"'
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
  variables:
    GIT_STRATEGY: fetch
  before_script:
    - apk update
    - apk add --no-cache git curl bash
    - curl -fsSL https://claude.ai/install.sh | bash
  script:
    - /bin/gitlab-mcp-server || true
    - >
      claude
      -p "${AI_FLOW_INPUT:-'Review this MR and implement the requested changes'}"
      --permission-mode acceptEdits
      --allowedTools "Bash Read Edit Write mcp__gitlab"
      --debug

Test: chạy job thủ công từ CI/CD → Pipelines, hoặc trigger từ MR.

Điểm khác so với GitHub Actions

  • Không có official action — bạn tự cài CLI trong before_script (curl -fsSL https://claude.ai/install.sh | bash) rồi gọi claude -p ... trực tiếp (headless).
  • Dùng biến AI_FLOW_INPUT / AI_FLOW_CONTEXT / AI_FLOW_EVENT khi trigger qua web/API với context payload.
  • mcp__gitlab (GitLab MCP server) cho phép Claude viết comment và mở MR — phải nằm trong --allowedTools.
  • Credential GitLab API: mặc định dùng CI_JOB_TOKEN, hoặc Project Access Token với scope api lưu vào GITLAB_ACCESS_TOKEN.

Mention-driven trigger (tùy chọn)

Thêm project webhook cho "Comments (notes)" trỏ tới một event listener; listener gọi pipeline trigger API với AI_FLOW_INPUT, AI_FLOW_CONTEXT khi comment chứa @claude.

Use case

@claude implement this feature based on the issue description
@claude suggest a concrete approach to cache the results of this API call
@claude fix the TypeError in the user dashboard component

Bedrock / Vertex

  • Bedrock: cấu hình GitLab làm OIDC identity provider trong AWS, đổi CI_JOB_JWT_V2 lấy AWS credentials qua aws sts assume-role-with-web-identity. Variables: AWS_ROLE_TO_ASSUME, AWS_REGION.
  • Vertex: Workload Identity Federation (không tải key), auth bằng gcloud auth login --cred-file. Variables: GCP_WORKLOAD_IDENTITY_PROVIDER, GCP_SERVICE_ACCOUNT, CLOUD_ML_REGION (ví dụ us-east5).

Common parameters (headless)

  • prompt / prompt_file: instructions inline (-p) hoặc qua file.
  • max_turns: giới hạn số vòng lặp.
  • timeout_minutes: giới hạn thời gian chạy.
  • Flags có thể đổi theo version — chạy claude --help trong job để xem.

Governance

  • Mỗi job chạy trong container isolated, network hạn chế; Claude Code dùng workspace-scoped permissions.
  • Mọi thay đổi đi qua MR → branch protection và approval rules vẫn áp dụng cho code do AI sinh.

Tích hợp VS Code

Extension cung cấp giao diện native cho Claude Code, tích hợp thẳng trong IDE (đây là cách khuyến nghị để dùng Claude Code trong VS Code). Cho phép review/sửa plan trước khi accept, auto-accept edit, @-mention file kèm line range, xem history, mở nhiều conversation trong tab/window riêng.

Cài đặt

  • Yêu cầu VS Code 1.98.0+ và một tài khoản Anthropic (Pro/Max/Team/Enterprise hoặc Claude Console — không cần API key, đăng nhập lần đầu khi mở extension).
  • Cài: mở Extensions (Cmd/Ctrl+Shift+X), tìm "Claude Code", Install. Hoạt động cả trên Cursor và các VS Code fork khác (Open VSX registry).
  • Extension bundle sẵn CLI riêng cho chat panel. Muốn chạy claude trong integrated terminal thì cần cài standalone CLI — extension KHÔNG thêm claude vào PATH.

Mở panel

  • Spark icon ở Editor Toolbar (góc trên-phải, chỉ hiện khi có file đang mở).
  • Activity Bar: Spark icon ở sidebar trái (luôn hiện).
  • Command Palette (Cmd/Ctrl+Shift+P) → "Claude Code".
  • Status Bar: ✱ Claude Code góc dưới-phải (chạy cả khi không mở file).

Prompt box — tính năng chính

  • Permission modes: click mode indicator để đổi, hoặc set claudeCode.initialPermissionMode. Có Manual, Plan (Claude mô tả trước, mở plan dưới dạng Markdown document để comment inline), Edit automatically.
  • Command menu (/): attach file, đổi model, extended thinking, /usage, /remote-control, và mục Customize (MCP, hooks, memory, permissions, plugins).
  • @-mention: @file (fuzzy match), @src/components/ (folder — thêm dấu /). Option+K / Alt+K chèn reference kèm line number (ví dụ @app.ts#5-10). Text đang select được Claude thấy tự động.
  • Extended thinking, context indicator (/compact), multi-line (Shift+Enter).

Review changes & checkpoints

  • Khi Claude muốn sửa file: hiện diff side-by-side + xin phép (accept / reject / chỉ dẫn khác). Sửa trực tiếp trong diff trước khi accept thì Claude được báo là bạn đã chỉnh.
  • Checkpoints: hover message → nút rewind, chọn: Fork conversation from here / Rewind code to here / Fork conversation and rewind code.

Chạy song song & vị trí panel

  • Kéo panel về Secondary sidebar (phải), Primary sidebar (trái), hoặc Editor area (tab).
  • Open in New Tab / Open in New Window để chạy nhiều conversation, mỗi cái có history + context riêng.
  • Đổi sang terminal mode: bật setting claudeCode.useTerminal.

VS Code vs CLI

Một số feature chỉ có ở CLI — chạy claude trong integrated terminal (Ctrl+` / Cmd+` ) khi cần.

FeatureCLIExtension
Commands & skillsTất cảSubset (gõ / để xem)
MCP server configMột phần (thêm qua CLI; quản lý bằng /mcp)
Checkpoints
! bash shortcutKhông
Tab completionKhông
  • Extension và CLI dùng chung conversation history: claude --resume trong terminal để tiếp tục.
  • Reference terminal output: @terminal:name.
  • MCP: claude mcp add ... trong terminal, quản lý bằng /mcp trong chat panel.
  • Git worktree song song: claude --worktree feature-auth (-w).

Settings

  • Extension settings (VS Code): Cmd/Ctrl+, → Extensions → Claude Code. Gồm useTerminal, initialPermissionMode, preferredLocation, autosave, respectGitIgnore, disableLoginPrompt...
  • Claude Code settings (~/.claude/settings.json): chia sẻ giữa extension và CLI — allowed commands, env vars, hooks, MCP servers.

Third-party providers

Dùng Bedrock/Vertex/Foundry: bật setting claudeCode.disableLoginPrompt, rồi cấu hình provider trong ~/.claude/settings.json (dùng chung cho cả extension và CLI).

IDE MCP server (built-in)

Khi extension active, nó chạy local MCP server tên ide (ẩn khỏi /mcp) để CLI mở diff, đọc selection cho @-mention, chạy Jupyter cell. Chỉ 2 tool lộ cho model: mcp__ide__getDiagnostics (read-only) và mcp__ide__executeCode (chạy Python trong Jupyter — luôn hỏi trước qua Quick Pick). Nếu tổ chức dùng PreToolUse hook allowlist thì cần biết server này tồn tại.

Tích hợp JetBrains

Plugin cho IntelliJ IDEA, PyCharm, Android Studio, WebStorm, PhpStorm, GoLand. Cung cấp diff viewing trong IDE, selection context sharing, diagnostic sharing.

Cài đặt

Plugin chạy lệnh claude trong integrated terminal của IDE và connect tới nó — KHÔNG bundle CLI riêng, nên cài cả hai:

  1. Cài Claude Code CLI (plugin báo "Cannot launch Claude Code" nếu claude không có trên PATH).
  2. Cài Claude Code plugin từ JetBrains Marketplace, rồi restart IDE hoàn toàn.

Không cần API key (đăng nhập lần đầu khi chạy claude). Nếu claude ở path lạ, set trong plugin Claude command setting.

Sử dụng

  • Từ IDE: chạy claude trong integrated terminal → mọi feature active.
  • Từ terminal ngoài: chạy /ide trong Claude Code để connect tới IDE. Start Claude từ project root để cùng file access với IDE.

Feature & shortcut

  • Quick launch: Cmd+Esc / Ctrl+Esc.
  • File reference: Cmd+Option+K (Mac) / Alt+Ctrl+K (Win/Linux) chèn @src/auth.ts#L1-99.
  • Diff viewing: /config → set Diff tool = auto (diff trong IDE) hoặc terminal. Entry này chỉ hiện khi đã connect IDE.
  • Selection & diagnostic sharing: tự động; Read deny rule chặn sharing cho file khớp.

Plugin settings

Settings → Tools → Claude Code [Beta]:

  • Claude command: ví dụ claude, /usr/local/bin/claude, npx @anthropic-ai/claude-code.
  • WSL: đặt wsl -d Ubuntu -- bash -lic "claude".
  • ESC key: nếu ESC không interrupt được, vào Settings → Tools → Terminal bỏ chọn "Move focus to the editor with Escape" (hoặc xóa shortcut "Switch focus to Editor").

Special config

  • Remote Development: phải cài plugin ở remote host (Settings → Plugin (Host)), không phải máy local.
  • WSL2 "No available IDEs detected": do NAT networking / Windows Firewall chặn. Fix: thêm firewall rule cho subnet WSL2, hoặc chuyển networkingMode=mirrored trong .wslconfig (Windows 11 22H2+) rồi wsl --shutdown.

Bảo mật

Trong acceptEdits mode, Claude có thể sửa file cấu hình IDE mà IDE tự thực thi → cân nhắc dùng manual approval mode, chỉ dùng với prompt tin cậy. Plugin có IDE MCP server tên ide tương tự VS Code, nhưng chỉ lộ mcp__ide__getDiagnostics (không có code-execution tool). Setting Accept connections from all network interfaces (Networking Advanced) mặc định tắt (chỉ loopback 127.0.0.1) — chỉ bật khi loopback không hoạt động, vì transport là ws:// không mã hóa.

Xem thêm

  • content/en/docs/claude-code/github-actions.md — Claude Code GitHub Actions đầy đủ
  • content/en/docs/claude-code/gitlab-ci-cd.md — GitLab CI/CD (beta)
  • content/en/docs/claude-code/vs-code.md — VS Code extension
  • content/en/docs/claude-code/jetbrains.md — JetBrains plugin
  • claude-code-action repository
  • content/en/docs/claude-code/headless.md — Headless mode (nền tảng cho CI/CD)
  • content/en/docs/claude-code/mcp.md — Model Context Protocol
  • content/en/docs/claude-code/settings.md — Cấu hình chia sẻ giữa extension và CLI
Nguồn của chương

Tài liệu chính thức duy nhất từ Anthropic.

Claude Code docs
Trở về mục lục