본문 바로가기
C.W.K.
Stream
Lesson 13 of 13 · published

자동화, CI/CD, 비대화형 활용법

~22 min · automation, ci-cd, headless, github-actions, scripting

Level 0🌱 입문자
0 XP0/70 lessons0/11 achievements
0/120 XP to next level120 XP to go0% complete

대화형 도구를 파이프라인의 한 단계로 확장해

-p, --allowedTools, --output-format json을 함께 쓰면 Claude Code는 사람이 지켜보는 터미널 도구를 넘어 자동화 파이프라인의 한 단계가 돼. CI에서 PR을 검토하고, 밤마다 release notes를 만들고, 오류를 먼저 분류할 수 있어.

실전에서는 실패하는 테스트를 먼저 만들고 구현과 리팩터링을 잇는 TDD 흐름, git diff main...HEAD | claude -p로 하는 변경 검토, JSON 결과를 jq로 읽어 다음 단계를 결정하는 방식이 자주 쓰여. 자동화에서는 Claude가 쓸 수 있는 도구를 필요한 만큼만 미리 허용해야 해.

일반적인 PR 자동화는 anthropics/claude-code-action@v1으로 시작할 수 있어. 정형화된 경우를 벗어나면 같은 기본 단위를 셸과 CI에서 직접 조합해. 핵심은 자유 텍스트를 억지로 파싱하지 않고 구조화 결과와 최소 권한으로 연결하는 거야.

직접 확인할 항목: @claude.

Code

셸에서 비대화형 검토 실행하기·bash
#!/bin/bash
# scripts/ai-review.sh
set -euo pipefail

DIFF=$(git diff origin/main...HEAD)
[ -z "$DIFF" ] && { echo "no changes"; exit 0; }

REVIEW=$(echo "$DIFF" | claude -p \
  "Review this diff. Format: [SEVERITY: HIGH|MEDIUM|LOW] desc (file:line)" \
  --output-format text \
  --allowedTools "Read,Bash(git log *)")

echo "$REVIEW" > "review-$(date +%Y%m%d-%H%M%S).md"
echo "$REVIEW"

# Gate the pipeline
if echo "$REVIEW" | grep -q "SEVERITY: HIGH"; then
  echo "high-severity findings, blocking"
  exit 1
fi
GitHub Action으로 PR 검토하기·yaml
# .github/workflows/claude-review.yml
name: Claude PR Review
on:
  pull_request:
    types: [opened, synchronize]

permissions:
  contents: read
  pull-requests: write

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with: { fetch-depth: 0 }

      - uses: actions/setup-node@v4
        with: { node-version: '22' }

      - run: npm install -g @anthropic-ai/claude-code

      - name: Run Claude review
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
        run: |
          git diff origin/main...HEAD | claude -p \
            "Review for bugs, security, missing tests. Markdown output." \
            --output-format text \
            --allowedTools "Read,Bash(git log *),Bash(git show *)" \
            > review.md

      - uses: actions/github-script@v7
        with:
          script: |
            const fs = require('fs');
            const review = fs.readFileSync('review.md', 'utf8');
            github.rest.issues.createComment({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: context.issue.number,
              body: '## Claude Code Review\n\n' + review
            });

External links

Exercise

실제 저장소에 Claude 검토 단계를 연결해. 푸시 전에 돌리는 로컬 스크립트나 PR에서 실행되는 GitHub Action 가운데 하나를 고르면 돼. --allowedTools로 최소 권한만 주고 실제 PR에서 시험한 뒤, 게시된 댓글을 캡처해.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.